[Lxc-users] retrieve guest container's ip address

Ben Butler-Cole ben at bridesmere.com
Mon Jan 7 10:11:01 UTC 2013


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/ad04ba6a/attachment.html>


More information about the lxc-users mailing list