Routing inside LXC container (Ubuntu 18)

DynFi User

Renowned Member
Apr 18, 2016
152
17
83
49
dynfi.com
We are migrating container from Ubuntu 14 to Ubuntu 18.

We have a configuration with routing inside the container (in /etc/network/interfaces) :

auto lo
iface lo inet loopback

auto eth0
iface eth0 inet static
address 23.51.52.24
netmask 255.255.255.240
gateway 23.51.52.1

auto eth1
iface eth1 inet static
address 192.168.10.25
netmask 255.255.255.0

auto netManagement
iface netManagement inet static
address 192.168.9.25
netmask 255.255.255.0
up /sbin/route add -net 192.168.25.0 netmask 255.255.255.0 gw 192.168.9.1
down /sbin/route del -net 192.168.25.0 netmask 255.255.255.0
up /sbin/route add -net 10.10.10.0 netmask 255.255.255.0 gw 192.168.9.1
down /sbin/route del -net 10.10.10.0 netmask 255.255.255.0
up /sbin/route add -net 10.10.20.0 netmask 255.255.255.0 gw 192.168.9.1
down /sbin/route del -net 10.10.20.0 netmask 255.255.255.0
up /sbin/route add -net 192.168.23.0 netmask 255.255.255.0 gw 192.168.9.1
down /sbin/route del -net 192.168.23.0 netmask 255.255.255.0
up /sbin/route add -net 10.0.99.0 netmask 255.255.255.0 gw 192.168.9.1
down /sbin/route del -net 10.0.99.0 netmask 255.255.255.0



This is working like a charm in older Ubuntu.
We are looking for the best solution to do that in an Ubuntu 18 container using latest PVE ?

We have read some things about ".pve-ignore.interfaces" but documentation is scarce and we would like to avoid long term compatibility issues with LXC or PVE (and we have quite many CT with this kind of config).

Thanks for your reply.
 
While this seems to be interesting : https://wiki.archlinux.org/index.php/Systemd-networkd#Configuration_examples

I still would like to know what is the advised way to handle custom networking configuration in Proxmox Containers ?

This can be done at many different level including configd-networkd / netplan …
So most probably Proxmox has some advise to provide on this topic in order to keep long term compatibility;
 
Nobody has answer to this ?
 
hi

we use systemd-networkd for ubuntu containers with version >= 17.10

you can use the ignore feature and write your own network config if you want.

the proxmox-generated networkd configs are like this:

Code:
$ cat /etc/systemd/network/eth0.network
[Match]
Name = eth0

[Network]
Description = Interface eth0 autoconfigured by PVE
Address = 192.168.22.133/20
Gateway = 192.168.16.1
DHCP = none
IPv6AcceptRA = false
 
Ok so here is how to proceed :

You need to create a file in the container called ".pve-ignore.hosts" file should be located in "/etc/" so "/etc/.pve-ignore.hosts"
This will let the system know NOT to rewrite on boot any modification operated in the "/etc/systemd/network/"

Then you need to setup your interfaces in "/etc/systemd/network/" using standard semantic such as :

Code:
[Match]
Name = netABC

[Network]
Description = Interface netABC autoconfigured by PVE
Address = 192.168.12.16/24
DHCP = none
IPv6AcceptRA = false

[Route]
Gateway=192.168.14.1
Destination=10.10.10.0/24
[Route]
Gateway=192.168.14.1
Destination=192.168.15.0/24


I would strongly suggest that Proxmox team
1. provide user with documented infos on this process.
2. adds an extended parameter to the CT network configuration which will take care of this so that route can easily be added.

It might be tricky since there might be quite many options in the Network settings, but It should be much more straightforward.
 
thanks for the instructions and the feedback.

a suggestion from me would be to make a template from your container with the custom network config and .pve-ignore.hosts file, since you mentioned you have a lot of containers similar to this. it would make it easier to create new ones like this, since you just need to clone from template and edit the ip probably
 
Nice suggestion too !

Do you have any pointer for template creation ?
 
you can simply right click on an existing container on the gui and convert it to template
 
Ok so here is how to proceed :

You need to create a file in the container called ".pve-ignore.hosts" file should be located in "/etc/" so "/etc/.pve-ignore.hosts"
This will let the system know NOT to rewrite on boot any modification operated in the "/etc/systemd/network/"

Then you need to setup your interfaces in "/etc/systemd/network/" using standard semantic such as :

Why not creating a script in /etc/networkd-dispatcher/routable.d that contains the routes. By this you're still able to update the ip adress from the gui and still have you static routes defined... I just did in Ubuntu 18.04 and it works great.

Andreas
 
In my case I put the ".pve-ignore.eth0.network" in /etc/systemd/network/ to prevent overwrite of the eth0.network in Ubuntu 18.04 LXC.

Code:
root@Domoticz:/etc/systemd/network# ls -la
total 12
drwxr-xr-x 2 root root 4096 Aug 21 08:19 .
drwxr-xr-x 5 root root 4096 Aug 18 13:30 ..
-rw-r--r-- 1 root root    0 Aug 21 08:18 .pve-ignore.eth0.network
-rw-r--r-- 1 root root  169 Aug 21 08:19 eth0.network

root@Domoticz:/etc/systemd/network# cat eth0.network
[Match]
Name = eth0

[Network]
Description = Interface eth0 autoconfigured by PVE
DHCP = v4
IPv6AcceptRA = false

[Route]
Gateway=192.168.3.29
Destination=10.0.101.0/24
 

About

The Proxmox community has been around for many years and offers help and support for Proxmox VE, Proxmox Backup Server, and Proxmox Mail Gateway.
We think our community is one of the best thanks to people like you!

Get your subscription!

The Proxmox team works very hard to make sure you are running the best software and getting stable updates and security enhancements, as well as quick enterprise support. Tens of thousands of happy customers have a Proxmox subscription. Get yours easily in our online shop.

Buy now!