Pro Tip for Proxmox Users: Need to Add Multiple IP Addresses for a Single NIC in LXC?
A Note About Proxmox and LXC (Linux Containers)
For those unfamiliar with LXC and Proxmox, LXC is similar to a virtual machine that runs a guest OS (Windows, Linux, Mac, Android, etc.) but the container part of LXC excludes the core part of the OS and simply provides networking and storage inside a container. Unlike virtual machines, applications inside a container can access resources on a host system directly. Proxmox is a hypervisor for running virtual machines and Linux containers (LXC) in a server hardware.
IP Addresses and Subnetting
Do you need to have multiple IP addresses assigned to a network interface inside an LXC container? In terms of networking, a single NIC can have multiple IP addresses. This is useful if you want to run a single server with multiple websites that have their own IP address. Here’s what I mean:
- A small HTML file with a list of websites hosted by the web server.
- A web application running Adminer, a lightweight alternative to phpMyAdmin.
- A development version of my website that mirrors a production version. Anyone who visits my site sees my production version of my website.
Once I test the changes I made in the development website, I push the changes up to the production website.
- A custom-built web application for taking notes. Any notes written in HTML gets shown up in the web browser.
- A development version of the note-taking web application taken from
A note for those new to networking: pay attention to the subnet. A slash 23 subnet can start with
172.20.30.1 and ends at
172.20.31.0 are both valid IP addresses.
172.20.30.0 is a network address and
172.20.31.255 is a broadcast address. Cisco has an article about IP addressing and subnetting in order to help you understand how subnetting works. With that out of the way, let’s get into configuring a Linux container running in a Proxmox server.
How I Initially Configure the Network Interface Inside a Linux Container?
When you create a new Linux container, you get to the Networking tab and filled in the IP address and default gateway. Once you start the container, the output of
/etc/network/interfaces is as follows:
auto lo iface lo inet loopback auto eth0 iface eth0 inet static address 172.20.31.0/23 gateway 172.20.30.1
Now you want to add additional IP addresses to a single network interface:
auto lo iface lo inet loopback auto eth0 iface eth0 inet static address 172.20.31.0/23 gateway 172.20.30.1 iface eth0 inet static address 172.20.31.1/23 iface eth0 inet static address 172.20.31.2/23 iface eth0 inet static address 172.20.31.3/23 iface eth0 inet static address 172.20.31.4/23
You saved the file and you did a restart of networking service:
systemctl restart networking
What happens if you reboot? The output will be as follows:
auto lo iface lo inet loopback auto eth0 iface eth0 inet static address 172.20.31.0/23 gateway 172.20.30.1 iface eth0 inet static address 172.20.31.0/23 gateway 172.20.30.1 iface eth0 inet static address 172.20.31.0/23 gateway 172.20.30.1 iface eth0 inet static address 172.20.31.0/23 gateway 172.20.30.1 iface eth0 inet static address 172.20.31.0/23 gateway 172.20.30.1
If I did not check out the
/etc/network/interfaces file, I would execute the
ip a command that lists IP addresses for all interfaces and saw something similar to this:
gpadmin-local@webservers:~$ ip a 1: lo:
mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000 link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo valid_lft forever preferred_lft forever inet6 ::1/128 scope host valid_lft forever preferred_lft forever 2: eth0@if111: mtu 1500 qdisc noqueue state UP group default qlen 1000 link/ether 7e:ef:18:b4:a4:b9 brd ff:ff:ff:ff:ff:ff link-netnsid 0 inet 172.20.31.0/23 brd 172.20.31.255 scope global eth0 valid_lft forever preferred_lft forever inet6 fe80::7cef:18ff:feb4:a4b9/64 scope link valid_lft forever preferred_lft forever
When I restarted the networking service, I found out that the network interface (
eth0) already exists. I don’t know why Proxmox would change individual IP addresses to the same IP address and add redundant default gateways with the same IP address, but it seems Proxmox does not handle multiple IP addresses in a network section of the web interface for the Linux container.
Turns out I have to remove the IP address and gateway from the network configuration. With the Linux container selected (in my case:
webservers), I went into Network, double-click the
eth0 row containing an IP address, tab over to IPv4/CIDR edit box and removed both the IP address/subnet mask and gateway. Once I’ve done that, I clicked OK, made configuration changes in
/etc/network/interfaces, and rebooted the container. In order to verify full networking functionality, I rebooted the Linux container, logged back into the container, and once I execute
ip a command, all the IP addresses are preserved.
Oh, and I almost forgot: this network configuration can also apply to Ubuntu, AlmaLinux, Rocky Linux, OpenSUSE, and just about any other Linux distributions.
Notes For Those Who Use a Screen Reader
For anyone using a screen reader such as JAWS (Windows), NVDA (Windows), VoiceOver (Mac), or Orca (Linux), I’m not sure how anyone can access a virtual machine within a Proxmox web interface. And I’m not even sure if screen readers can read the text within the Linux container console; however, I am able to copy text from the console. The only difference is I have to highlight using a mouse, right-click in the console, and select copy. Doing Control+C sends a termination signal or displays
^C in a terminal. Doing Control+V once does nothing, but executing Control=V again shows a
^V in a console, so pasting text in a Proxmox console does nothing for those who do not want or cannot use a mouse.
The bottom line is this: in the networking section of the Proxmox web interface, leave the IP address and default gateway blank. Once you get into the console, edit the
/etc.network/interfaces and add your IP addresses manually.