To map a static IP address to a container using dnsmasq under LXD (Linux containers), you will need to do the following:
apt
, yum
, pacman
).For example, on a Debian-based system, you can use the following command to install dnsmasq:
$ sudo apt-get install dnsmasq
/etc/dnsmasq.conf
) to specify the static IP mapping for the container.To specify the static IP mapping, you will need to add a line to the configuration file with the following format:
dhcp-host=<MAC address>,<IP address>
Replace <MAC address>
with the MAC address of the container's network interface and <IP address>
with the static IP address that you want to assign to the container.
For example, to map the static IP address 10.0.0.100
to the container with the MAC address 00:11:22:33:44:55
, you would add the following line to the dnsmasq configuration file:
dhcp-host=00:11:22:33:44:55,10.0.0.100
service
or systemctl
command to restart the dnsmasq service, depending on your Linux distribution.For example, on a Debian-based system, you can use the following command to restart the dnsmasq service:
$ sudo service dnsmasq restart
On a Red Hat-based system, you can use the following command to restart the dnsmasq service:
$ sudo systemctl restart dnsmasq
/etc/network/interfaces
file and adding a static
block for the network interface.For example, to configure the eth0
interface with the static IP address 10.0.0.100
, you would add the following lines to the /etc/network/interfaces
file:
auto eth0 iface eth0 inet static address 10.0.0.100 netmask 255.255.255.0 gateway 10.0.0.1
/etc/network/interfaces
file, you will need to restart the container's network to apply the changes. You can do this by running the ifdown
and ifup
commands for the network interface.For example, to restart the eth0
interface, you can use the following commands:
$ ifdown eth0 $ if