Static IP for CentOS LXC container
LXC containers get dynamic IP from DHCP. When you stop and start a container, its IP gets changed. If you hosting some web application on this container, you need to point the application to new IP. To avoid this, you can configure static IP on the container.
LXC containers get IP in the range 10.0.3.2-255. To make CentOS container IP static, edit file
1 |
vi /etc/sysconfig/network-scripts/ifcfg-eth0 |
Find
1 |
BOOTPROTO=dhcp |
Replace with
1 |
BOOTPROTO=STATIC |
Add below
1 2 3 4 |
IPADDR=10.0.3.2 GATEWAY=10.0.3.1 DNS1=1.1.1.1 DNS1=8.8.8.8 |
10.0.3.2 = replace with any unused IP in the range your LXC container assign using DHCP.
Create a static route file
1 |
vi /etc/sysconfig/network-scripts/route-eth0 |
Add
1 2 |
10.0.3.1 dev eth0 default via 10.0.3.1 dev eth0 |
After restarting the LXC container, you will have a fixed IP.
1 |
reboot |