Two IP addresses assigned to network

networking

(Michael Eager) #1

I created a Fedora 30 container on a CentOS 7 host. I’ve assigned it a static IP address in the config file:

Network configuration

lxc.network.type = veth
lxc.network.flags = up
lxc.network.link = br0
lxc.network.ipv4 = 192.168.20.7/24
lxc.network.ipv4.gateway = 192.168.20.1
lxc.network.hwaddr = 00:16:3e:aa:61:34

When I run the container, eth0 has the correct IP address, but also has another IP address which appears to be assigned by DHCP:

lxc-info -n wiki

Name: wiki
State: RUNNING
PID: 22853
IP: 192.168.20.187
IP: 192.168.20.7

I can ping both IP addresses from other systems on the network.

How can I prevent the container from getting an IP address from DHCP?


(Thomas Parrott) #2

Hi @eager

Because you are connecting your container to a bridge (br0), I am assuming that the network that br0 connects to has a DHCP service running on it. As such when the container starts up, any OS inside the container that is configure to configure the network interface via DHCP will get a dynamically assigned IP.

In addition to that, LXC will add any statically configure IPs to your interface, which is what you are seeing occur.

You have several options to stop the dynamically IPs being added to your container:

  1. Stop DHCP service on the br0 network (probably not a good idea if you have other hosts that rely on it).
  2. Modify the OS inside the container to not try to get an IP via DHCP
  3. Use a network mode like ipvlan that doesn’t support DHCP

Hope that helps :slight_smile: