[Lxc-users] retrieve guest container's ip address
Alan McDuff
alan.mcduff at yahoo.com
Mon Jan 7 13:03:42 UTC 2013
Thank you, Ben. I have just searched again for similar questions, and found what I think is the most "natural" solution:
Add this line to /etc/dhcp/dhclient.conf on the host:
prepend domain-name-servers 10.0.3.1;
Then run "service networking restart", and I can log into the guest with "ssh ubuntu at guest1" or use "nslookup guest1".
HTH
Alan
________________________________
From: Ben Butler-Cole <ben at bridesmere.com>
To: Alan McDuff <alan.mcduff at yahoo.com>
Cc: Marko Anastasov <marko.anastasov at gmail.com>; "lxc-users at lists.sourceforge.net" <lxc-users at lists.sourceforge.net>
Sent: Monday, January 7, 2013 11:11 AM
Subject: Re: [Lxc-users] retrieve guest container's ip address
On 5 January 2013 12:29, Alan McDuff <alan.mcduff at yahoo.com> wrote:
>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 at guest1.lxc".
>
>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.
>
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.
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.
If you don't like that solution because of the non-locality, you might prefer to write a small script, say `lxc-ssh`:
$1=container
ssh $(host $container 10.0.3.1 | tail -1 | awk '{print $NF}')
-Ben
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.linuxcontainers.org/pipermail/lxc-users/attachments/20130107/a40a4ac4/attachment.html>
More information about the lxc-users
mailing list