Lxd: Container Not Getting IP Address

Created on 11 Nov 2015  路  24Comments  路  Source: lxc/lxd

I have been setting up a fresh new LXD instance on another computer of mine and skipping all parts of the LXC introduction. After several reboots, the usual test-ubuntu container does not have a usable IP address:

>>> lxc info ubuntu
Name: ubuntu
Status: Running
Init: 3615
Ips:
  lo:   IPV4    127.0.0.1
  lo:   IPV6    ::1

What am I missing?

Most helpful comment

Make sure the container's network cloud-init inet setting is set to dhcp, not manual,
especially if container was created before initial bridge setup (sudo lxd init),
hopefully this will save someone a few hours troubleshooting e.g.:

lxc exec ubuntu -- grep eth0 /etc/network/interfaces.d/50-cloud-init.cfg
auto eth0
iface eth0 inet dhcp 

If updating:

sudo systemctl restart lxd-bridge
lxc restart ubuntu

For more information:
man interfaces

Container Not Getting IP Address #1298

All 24 comments

what does "ifconfig lxcbr0" show you?

>>> ifconfig lxcbr0
lxcbr0    Link encap:Ethernet  HWaddr fe:91:e5:d9:55:49  
          inet addr:10.0.3.1  Bcast:0.0.0.0  Mask:255.255.255.0
          inet6 addr: fe80::945e:afff:fe82:5312/64 Scope:Link
          UP BROADCAST MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:9 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:0 (0.0 B)  TX bytes:1371 (1.3 KB)

Host OS: Fedora 23
LXD version: 0.21

>>> ifconfig lxcbr0
lxcbr0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 10.0.3.1  netmask 255.255.255.0  broadcast 0.0.0.0
        inet6 fe80::74ba:c2ff:fe22:9423  prefixlen 64  scopeid 0x20<link>
        ether fe:01:38:68:4f:5c  txqueuelen 0  (Ethernet)
        RX packets 463  bytes 40913 (39.9 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 431  bytes 51670 (50.4 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

I'm also facing similar issue while testing for all images (amd64 only) as only for certain distros can obtain the ip address. Most recent distros can't seems to obtain ip while older distros can, see result below.

>>> lxc list
+---------------------+---------+------------+------+-----------+-----------+
|        NAME         |  STATE  |    IPV4    | IPV6 | EPHEMERAL | SNAPSHOTS |
+---------------------+---------+------------+------+-----------+-----------+
| test-busybox        | RUNNING |            |      | NO        |         0 |
| test-centos-6       | RUNNING | 10.0.3.161 |      | NO        |         0 |
| test-centos-7       | RUNNING |            |      | NO        |         0 |
| test-debian-jessie  | RUNNING |            |      | NO        |         0 |
| test-debian-sid     | RUNNING |            |      | NO        |         0 |
| test-debian-squeeze | RUNNING | 10.0.3.129 |      | NO        |         0 |
| test-debian-wheezy  | RUNNING | 10.0.3.70  |      | NO        |         0 |
| test-gentoo-current | RUNNING |            |      | NO        |         0 |
| test-oracle-65      | RUNNING | 10.0.3.237 |      | NO        |         0 |
| test-plamo-5x       | RUNNING | 10.0.3.72  |      | NO        |         0 |
| test-ubuntu-cloud   | RUNNING | 10.0.3.143 |      | NO        |         0 |
| test-ubuntu-precise | RUNNING | 10.0.3.42  |      | NO        |         0 |
| test-ubuntu-trusty  | RUNNING | 10.0.3.111 |      | NO        |         0 |
| test-ubuntu-vivid   | RUNNING |            |      | NO        |         0 |
| test-ubuntu-wily    | RUNNING |            |      | NO        |         0 |
| test-ubuntu-xenial  | RUNNING |            |      | NO        |         0 |
+---------------------+---------+------------+------+-----------+-----------+

Rebuilding the containers yields similar result.

|        NAME         |  STATE  |    IPV4    | IPV6 | EPHEMERAL | SNAPSHOTS |
+---------------------+---------+------------+------+-----------+-----------+
| test-busybox        | RUNNING |            |      | NO        |         0 |
| test-centos-6       | RUNNING | 10.0.3.153 |      | NO        |         0 |
| test-centos-7       | RUNNING |            |      | NO        |         0 |
| test-debian-jessie  | RUNNING |            |      | NO        |         0 |
| test-debian-sid     | RUNNING |            |      | NO        |         0 |
| test-debian-squeeze | RUNNING | 10.0.3.158 |      | NO        |         0 |
| test-debian-wheezy  | RUNNING | 10.0.3.236 |      | NO        |         0 |
| test-gentoo-current | RUNNING |            |      | NO        |         0 |
| test-oracle-65      | RUNNING | 10.0.3.51  |      | NO        |         0 |
| test-plamo-5x       | RUNNING | 10.0.3.5   |      | NO        |         0 |
| test-ubuntu-cloud   | RUNNING | 10.0.3.232 |      | NO        |         0 |
| test-ubuntu-precise | RUNNING | 10.0.3.244 |      | NO        |         0 |
| test-ubuntu-trusty  | RUNNING | 10.0.3.214 |      | NO        |         0 |
| test-ubuntu-vivid   | RUNNING |            |      | NO        |         0 |
| test-ubuntu-wily    | RUNNING |            |      | NO        |         0 |
| test-ubuntu-xenial  | RUNNING |            |      | NO        |         0 |
+---------------------+---------+------------+------+-----------+-----------+

Is dnsmasq running on the lxcbr0 tot provide dhcp to the containers?

@jsimonetti How can I look this up?

You can see if dnsmasq is running with ps ax | grep dnsmasq
This should return the dnsmasq process.

Which distribution are you using?

Ubuntu 14.04

>>> ps ax | grep dnsmasq
 1248 ?        S      0:00 dnsmasq -u lxc-dnsmasq --strict-order --bind-interfaces --pid-file=/run/lxc/dnsmasq.pid --listen-address 10.0.3.1 --dhcp-range 10.0.3.2,10.0.3.254 --dhcp-lease-max=253 --dhcp-no-override --except-interface=lo --interface=lxcbr0 --dhcp-leasefile=/var/lib/misc/dnsmasq.lxcbr0.leases --dhcp-authoritative
 2227 ?        S      0:00 /usr/sbin/dnsmasq --conf-file=/var/lib/libvirt/dnsmasq/default.conf
 2302 ?        S      0:00 /usr/sbin/dnsmasq --no-resolv --keep-in-foreground --no-hosts --bind-interfaces --pid-file=/run/sendsigs.omit.d/network-manager.dnsmasq.pid --listen-address=127.0.1.1 --conf-file=/var/run/NetworkManager/dnsmasq.conf --cache-size=0 --proxy-dnssec --enable-dbus=org.freedesktop.NetworkManager.dnsmasq --conf-dir=/etc/NetworkManager/dnsmasq.d
24295 pts/15   S+     0:00 grep --color=auto dnsmasq

I've managed to obtain the IP address of some of the container by entering the container the requesting an IP address manually. I suspect certain container template was not created correctly (certain services were not started)? But I may be wrong.

Note that I can't get the container to shut down properly (another issue I'm still troubleshooting), so I can't test whether the changes will be permanent on next container reboot.

The container without assigned IP.

>>> lxc info test-ubuntu-wily
Name: test-ubuntu-wily
Status: Running
Init: 18545
Ips:
  lo:   IPV4    127.0.0.1
  lo:   IPV6    ::1

Enter our container through Bash shell.

>>> lxc exec test-ubuntu-wily /bin/bash
root@test-ubuntu-wily:~# 

Get our eth0 interface up.

root@test-ubuntu-wily:~# ifconfig eth0 up
root@test-ubuntu-wily:~# ifconfig
eth0      Link encap:Ethernet  HWaddr 00:16:3e:af:0e:d6  
          inet6 addr: fe80::216:3eff:feaf:ed6/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:6 errors:0 dropped:0 overruns:0 frame:0
          TX packets:6 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:508 (508.0 B)  TX bytes:508 (508.0 B)

lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)

Update your name server details.

root@test-ubuntu-wily:~# resolvconf -u        
resolvconf: Error: /run/resolvconf/interface either does not exist or is not a directory

Create the missing folder and try again.

root@test-ubuntu-wily:~# mkdir -p /run/resolvconf/interface
root@test-ubuntu-wily:~# resolvconf -u

Release and renew the IP address.

root@test-ubuntu-wily:~# dhclient -r
Killed old client process
root@test-ubuntu-wily:~# dhclient
root@test-ubuntu-wily:~#

Check your eth0 interface again.

root@test-ubuntu-wily:~# ifconfig eth0
eth0      Link encap:Ethernet  HWaddr 00:16:3e:af:0e:d6  
          inet addr:10.0.3.217  Bcast:10.0.3.255  Mask:255.255.255.0
          inet6 addr: fe80::216:3eff:feaf:ed6/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:30 errors:0 dropped:0 overruns:0 frame:0
          TX packets:25 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:4652 (4.6 KB)  TX bytes:5262 (5.2 KB)

However, you still can't connect to the Internet from within the container. You'll need to create the /etc/resolv.conf file. You will need to reconfigure resolvconf to symbolic link from /etc/resolv.conf to /run/resolvconf/resolv.conf.

root@test-ubuntu-wily:~# 
root@test-ubuntu-wily:~# dpkg-reconfigure resolvconf
root@test-ubuntu-wily:~# ll /etc/resolv.conf 
lrwxrwxrwx. 1 root root 29 Nov 13 16:59 /etc/resolv.conf -> ../run/resolvconf/resolv.conf

Test your Internet connection.

root@test-ubuntu-wily:~# ping linuxcontainers.org
PING linuxcontainers.org (192.99.34.219) 56(84) bytes of data.
64 bytes from vorash.stgraber.org (192.99.34.219): icmp_seq=1 ttl=55 time=274 ms
64 bytes from vorash.stgraber.org (192.99.34.219): icmp_seq=2 ttl=55 time=282 ms
......

Exit and check the container info again.

root@test-ubuntu-wily:~# exit
exit
>>> lxc info test-ubuntu-wily
Name: test-ubuntu-wily
Status: Running
Init: 18545
Ips:
  eth0: IPV4    10.0.3.217
  lo:   IPV4    127.0.0.1
  lo:   IPV6    ::1

@kianmeng Interesting.

Is there something which might have caused this behavior?

@srkunze Most likely the network interface (eth0) within the container failed to boot properly. Without eth0, surely the container cannot get an IP through DHCP. Why? No idea.

[root@test-centos-7 ~]# systemctl status network
Failed to get D-Bus connection: Failed to connect to socket /run/systemd/private: 
Connection refused

Somewhat strange happened: I put the host into a proxy-free network. (cf. https://github.com/lxc/lxd/issues/1309#issuecomment-156171447)

That situation not only gave apt the ability to verify the lxd/lxc-stable repository but also gave LXD the ability to assign an IP address to the container.

@kianmeng @stgraber Does this make any sense?

@srkunze

I'm not sure about your environment and setup, but try troubleshoot your issue using Wireshark.

  1. Install and start Wireshark.
  2. Listen to the bridge interface lxcbr0 and start any container.
  3. Check the DHCP network traffic in Wireshark between the container and lxcbr0.
  4. Repeat this for for proxy and proxy-free network.
  5. Compare the results.

Maybe this may give you some hints.

Couldn't reproduce for now. Closing.

@kianmeng What would be the procedure for centos 6/7 container, if it doesn't getting ip address. Some commands are not found in centos such as dhclient... ?

@redhat57

Unfortunately I can't reproduce your issue. Best if you open a new ticket and provides us with more details on how to reproduce your errors.

Host details.

$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 16.10
Release:        16.10
Codename:       yakkety

$ lxc version
2.9.1

For me, CentOS 6 images seems to find IP address and dhclient.

$ lxc launch images:centos/6/amd64 my-centos
$ lxc exec my-centos bash
[root@my-centos ~]# ip addr show eth0 | grep -w inet
    inet 10.20.35.204/24 brd 10.20.35.255 scope global eth0

[root@my-centos ~]# dhclient --version
isc-dhclient-4.1.1-P1

i have the exact same issue on

  driver: lxc
  driver_version: 2.0.7
  kernel: Linux
  kernel_architecture: x86_64
  kernel_version: 4.8.5-gentoo
  server: lxd
  server_pid: 5173
  server_version: "2.11"
  storage: dir
  storage_version: "1"

problem occured after recompiling lxc without cgmanager support. it worked with cgmanager.
older clients work, newer debian or ubuntu dont get an ip. seems like it never triggered dhclient. can get it working by manually entering dhclient eth0. still cant shutdown machine. only occurs on newer images, older images like debian wheezy work well.

EDIT:
Reason: Host is not compatible with systemd, but client depends on it.

Solution:
Compile Kernel >4.5 with systemd compatibility

General setup  --->
    [*] open by fhandle syscalls
    [*] Control Group support --->
    [ ] Enable deprecated sysfs features to support old userspace tools
    [*] Configure standard kernel features (expert users)  --->
        [*] Enable eventpoll support
        [*] Enable signalfd() system call
        [*] Enable timerfd() system call
[*] Networking support --->
Device Drivers  --->
    Generic Driver Options  --->
        [*] Maintain a devtmpfs filesystem to mount at /dev
File systems  --->
    [*] Inotify support for userspace
    Pseudo filesystems  --->
        [*] /proc file system support
        [*] sysfs file system support

then add the following entry into /etc/fstab:
cgroup /sys/fs/cgroup/systemd cgroup none,name=systemd 0 0

I had to add it there manually for it to work in Ubuntu 16.04 LTS. This is how my config looks like

# Common configuration
lxc.include = /usr/share/lxc/config/ubuntu.common.conf

# Container specific configuration
lxc.rootfs = /var/lib/lxc/c1/rootfs
lxc.mount = /var/lib/lxc/c1/fstab
lxc.utsname = c1
lxc.arch = amd64

# Network configuration
lxc.network.type = veth
lxc.network.flags = up
lxc.network.link = lxcbr0
lxc.network.hwaddr = 00:16:3e:3a:36:2f
#my configs
lxc.network.ipv4 = 10.0.3.100/24 10.0.3.255
lxc.network.ipv4.gateway = auto
lxc.start.auto = 1
lxc.start.delay = 15
lxc.start.order = 10

Make sure the container's network cloud-init inet setting is set to dhcp, not manual,
especially if container was created before initial bridge setup (sudo lxd init),
hopefully this will save someone a few hours troubleshooting e.g.:

lxc exec ubuntu -- grep eth0 /etc/network/interfaces.d/50-cloud-init.cfg
auto eth0
iface eth0 inet dhcp 

If updating:

sudo systemctl restart lxd-bridge
lxc restart ubuntu

For more information:
man interfaces

Container Not Getting IP Address #1298

Had the same issue, @raymov you made my day!

solution based on @raymov 's comment:
run
lxc profile edit default
and change user.network_mode from link-local to dhcp. maybe you have to run systemctl restart lxd-bridge afterwards, can't remember.

thx @raymov !!!

Throwing my 2 cents in here, before getting any of this, I highly recommend moving to the feature branch of lxd/lxc (version 3.0+)

This gives you access to: lxc network commands.

Reason for this, I installed it, and accidentally placed the dhcp pool outside of my subset that I assigned to the brdige (idiot me, check). Now lxc never complained about any of this, but it took me half an hour to figure out this dumb mistake.

Nowadays with version 2.3+ you can simply run: lxc network show lxdbr0
And verify you have configured it right.

I did lxc network show lxdbr0 and got:

config: {}
description: Default LXD profile
devices:
  root:
    path: /
    pool: default
    type: disk
name: default
used_by:
- /1.0/containers/ubuntu

Then I updated the config to:

config: {}
description: Default LXD profile
devices:
  eth0:
    name: eth0
    nictype: bridged
    parent: lxdbr0
    type: nic
  root:
    path: /
    pool: default
    type: disk
name: default
used_by:
- /1.0/containers/ubuntu

Now my container has ipv4 ip

Coming from macOS, especially if you have just connected Apple Ethernet dongle on Ubuntu 16.04 (LXC 2.x for the sake of practice). Even fixing and restart the network couldn't get the IPv4 appeared in the lxc list, what I did to restart my MacBook and login to Ubuntu, re-run lxc list and finally shows 192.168.x.x successfully.

Other info, you can use ens# (Apple Ethernet dongle shown) instead of eth0, which is exactly the same network.

I've managed to obtain the IP address of some of the container by entering the container the requesting an IP address manually. I suspect certain container template was not created correctly (certain services were not started)? But I may be wrong.

Note that I can't get the container to shut down properly (another issue I'm still troubleshooting), so I can't test whether the changes will be permanent on next container reboot.

The container without assigned IP.

>>> lxc info test-ubuntu-wily
Name: test-ubuntu-wily
Status: Running
Init: 18545
Ips:
  lo:   IPV4    127.0.0.1
  lo:   IPV6    ::1

Enter our container through Bash shell.

>>> lxc exec test-ubuntu-wily /bin/bash
root@test-ubuntu-wily:~# 

Get our eth0 interface up.

root@test-ubuntu-wily:~# ifconfig eth0 up
root@test-ubuntu-wily:~# ifconfig
eth0      Link encap:Ethernet  HWaddr 00:16:3e:af:0e:d6  
          inet6 addr: fe80::216:3eff:feaf:ed6/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:6 errors:0 dropped:0 overruns:0 frame:0
          TX packets:6 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:508 (508.0 B)  TX bytes:508 (508.0 B)

lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)

Update your name server details.

root@test-ubuntu-wily:~# resolvconf -u        
resolvconf: Error: /run/resolvconf/interface either does not exist or is not a directory

Create the missing folder and try again.

root@test-ubuntu-wily:~# mkdir -p /run/resolvconf/interface
root@test-ubuntu-wily:~# resolvconf -u

Release and renew the IP address.

root@test-ubuntu-wily:~# dhclient -r
Killed old client process
root@test-ubuntu-wily:~# dhclient
root@test-ubuntu-wily:~#

Check your eth0 interface again.

root@test-ubuntu-wily:~# ifconfig eth0
eth0      Link encap:Ethernet  HWaddr 00:16:3e:af:0e:d6  
          inet addr:10.0.3.217  Bcast:10.0.3.255  Mask:255.255.255.0
          inet6 addr: fe80::216:3eff:feaf:ed6/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:30 errors:0 dropped:0 overruns:0 frame:0
          TX packets:25 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:4652 (4.6 KB)  TX bytes:5262 (5.2 KB)

However, you still can't connect to the Internet from within the container. You'll need to create the /etc/resolv.conf file. You will need to reconfigure resolvconf to symbolic link from /etc/resolv.conf to /run/resolvconf/resolv.conf.

root@test-ubuntu-wily:~# 
root@test-ubuntu-wily:~# dpkg-reconfigure resolvconf
root@test-ubuntu-wily:~# ll /etc/resolv.conf 
lrwxrwxrwx. 1 root root 29 Nov 13 16:59 /etc/resolv.conf -> ../run/resolvconf/resolv.conf

Test your Internet connection.

root@test-ubuntu-wily:~# ping linuxcontainers.org
PING linuxcontainers.org (192.99.34.219) 56(84) bytes of data.
64 bytes from vorash.stgraber.org (192.99.34.219): icmp_seq=1 ttl=55 time=274 ms
64 bytes from vorash.stgraber.org (192.99.34.219): icmp_seq=2 ttl=55 time=282 ms
......

Exit and check the container info again.

root@test-ubuntu-wily:~# exit
exit
>>> lxc info test-ubuntu-wily
Name: test-ubuntu-wily
Status: Running
Init: 18545
Ips:
  eth0: IPV4    10.0.3.217
  lo:   IPV4    127.0.0.1
  lo:   IPV6    ::1

every i turn of lxc container, restat container i have type command to have internet.

Was this page helpful?
0 / 5 - 0 ratings