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:
172.20.31.0/23
- A small HTML file with a list of websites hosted by the web server.
172.20.31.1/23
- A web application running Adminer, a lightweight alternative to phpMyAdmin.
172.20.31.2/23
- 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. 172.20.31.3/23
- A custom-built web application for taking notes. Any notes written in HTML gets shown up in the web browser.
172.20.31.4/23
- A development version of the note-taking web application taken from
172.20.31.3
.
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.254
. Both 172.20.30.255
and 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.