You can set per host/container parameters for the DHCP server. An LXD machine (VM) can be always given the same hostname, IP address and leas time. For example, you can tell dnsmasq to always given the VM msyqldb1 the IP address 192.168.1.100.
How to always allocate the LXD VM/machine named db the IP address 10.147.164.3?
Your dnsmasq DHCP server can read the file contains information about one host per line. The default file name is /var/lib/lxd/networks/lxdbr0/dnsmasq.hosts. The format of a line is as follows:
{ipaddr},{hostname}
OR
{macadd},{ipaddr},{hostname}
The advantage of storing DHCP host information in this file is that it can be changed without re-starting dnsmasq server when the file will be re-read when dnsmasq receives SIGHUP. Edit the /var/lib/lxd/networks/lxdbr0/dnsmasq.hosts file, enter:
$ sudo vi /var/lib/lxd/networks/lxdbr0/dnsmasq.hosts
Sample config:
# always set IP to 10.147.164.2 for apache1 vm 10.147.164.2,apache1 # always set IP to 10.147.164.3 for db1 vm having mac addr 00:16:ee:62:ff:90 00:16:ee:62:ff:90,10.147.164.3,db1
Save and close the file. Send SIGHUP to dnsmasq using killall command as follows:
$ sudo killall -SIGHUP dnsmasq
Now you can start lxd vm or restart already running lxd vm:
$ lxc restart db1
$ lxc start db1
Verify new IP address:
$ lxc list
$ lxc info db1
Sample outputs:
Fig.01: Set DHCP IPs of lxd/lxc (Linux containers) on Linux
🐧 1 comment so far... add one ↓
Category | List of Unix and Linux commands |
---|---|
File Management | cat |
Firewall | Alpine Awall • CentOS 8 • OpenSUSE • RHEL 8 • Ubuntu 16.04 • Ubuntu 18.04 • Ubuntu 20.04 |
Network Utilities | dig • host • ip • nmap |
OpenVPN | CentOS 7 • CentOS 8 • Debian 10 • Debian 8/9 • Ubuntu 18.04 • Ubuntu 20.04 |
Package Manager | apk • apt |
Processes Management | bg • chroot • cron • disown • fg • jobs • killall • kill • pidof • pstree • pwdx • time |
Searching | grep • whereis • which |
User Information | groups • id • lastcomm • last • lid/libuser-lid • logname • members • users • whoami • who • w |
WireGuard VPN | Alpine • CentOS 8 • Debian 10 • Firewall • Ubuntu 20.04 |
Please make faq for how to assign private communication between containers and having internet access from them.