<html><body><div style="color:#000; background-color:#fff; font-family:times new roman, new york, times, serif;font-size:12pt"><div><span>Thank you, Ben. I have just searched again for similar questions, and found what I think is the most "natural" solution:</span></div><div style="color: rgb(0, 0, 0); font-size: 16px; font-family: times new roman,new york,times,serif; background-color: transparent; font-style: normal;"><span>Add this line to /etc/dhcp/dhclient.conf on the host:</span></div><div style="color: rgb(0, 0, 0); font-size: 16px; font-family: times new roman,new york,times,serif; background-color: transparent; font-style: normal;"><span>prepend domain-name-servers 10.0.3.1;</span></div><div style="color: rgb(0, 0, 0); font-size: 16px; font-family: times new roman,new york,times,serif; background-color: transparent; font-style: normal;"><span>Then run "service networking restart", and I can log into the guest with "ssh ubuntu@guest1" or use
 "nslookup guest1".</span></div><div style="color: rgb(0, 0, 0); font-size: 16px; font-family: times new roman,new york,times,serif; background-color: transparent; font-style: normal;"><span>HTH<br></span></div><div style="color: rgb(0, 0, 0); font-size: 16px; font-family: times new roman,new york,times,serif; background-color: transparent; font-style: normal;"><span>Alan<br></span></div><div><br></div>  <div style="font-family: times new roman, new york, times, serif; font-size: 12pt;"> <div style="font-family: times new roman, new york, times, serif; font-size: 12pt;"> <div dir="ltr"> <font face="Arial" size="2"> <hr size="1">  <b><span style="font-weight:bold;">From:</span></b> Ben Butler-Cole <ben@bridesmere.com><br> <b><span style="font-weight: bold;">To:</span></b> Alan McDuff <alan.mcduff@yahoo.com> <br><b><span style="font-weight: bold;">Cc:</span></b> Marko Anastasov <marko.anastasov@gmail.com>;
 "lxc-users@lists.sourceforge.net" <lxc-users@lists.sourceforge.net> <br> <b><span style="font-weight: bold;">Sent:</span></b> Monday, January 7, 2013 11:11 AM<br> <b><span style="font-weight: bold;">Subject:</span></b> Re: [Lxc-users] retrieve guest container's ip address<br> </font> </div> <br>
<meta http-equiv="x-dns-prefetch-control" content="off"><div id="yiv897771666"><div dir="ltr"><div class="yiv897771666gmail_extra"><div class="yiv897771666gmail_quote">On 5 January 2013 12:29, Alan McDuff <span dir="ltr"><<a rel="nofollow" ymailto="mailto:alan.mcduff@yahoo.com" target="_blank" href="mailto:alan.mcduff@yahoo.com">alan.mcduff@yahoo.com</a>></span> wrote:<br>

<blockquote class="yiv897771666gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex;"><div><div style="font-size:12pt;font-family:times new roman, new york, times, serif;"><div class="yiv897771666im">>If you paste the .lxc part from http://www.stgraber.org/2012/07/17/easily-ssh-to-your-containers-and-vms-on-ubuntu-12-04-lts/ into your ~/.ssh/config >and start the container, then you should be able to ssh with "ssh ubuntu@guest1.lxc".</div>

<div style="font-family:times new roman, new york, times, serif;font-size:12pt;"><div style="font-family:times new roman, new york, times, serif;font-size:12pt;"><br>Thanks, but this doesn't look like a clean setup to me. If there is no better solution, I will write a post-lxc-create script that appends "$(host $guestname 10.0.3.1) $guestname" to /etc/hosts.<br>

</div></div></div></div></blockquote><div><br></div><div>I think that writing the address into /etc/hosts may cause you problems eventually because it will get out of date when you remove containers and potentially recycle addresses.<br>

<br></div><div>Stephane's solution has the advantage that it looks up the address dynamically when you need it. I really like the idea of putting the look-up into ~/.ssh/config, especially because it allows you to other useful things like turning off some security checking and setting the username.<br>

<br>If you don't like that solution because of the non-locality, you might prefer to write a small script, say `lxc-ssh`:<br><br></div><div>    $1=container<br></div><div>    ssh $(host $container 10.0.3.1 | tail -1 | awk '{print $NF}')</div>

</div><br></div><div class="yiv897771666gmail_extra">-Ben<br><br></div></div>
</div><meta http-equiv="x-dns-prefetch-control" content="on"><br><br> </div> </div>  </div></body></html>