LXC container and Wireguard - issue with NIC names?

reckless

Well-Known Member
Feb 5, 2019
79
4
48
So in order to get a working instance of Wireguard, you need to specify the eth interface at some point. I have one NIC in my unprivileged LXC, named eth0, but when I run ip a in the LXC I see this output:

Code:
root@wireguard:~# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> 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
151: eth0@if152: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000
    link/ether 3a:8a:3e:44:ff:ea brd ff:ff:ff:ff:ff:ff link-netnsid 0
    inet 192.168.0.12/24 brd 192.168.1.255 scope global eth0
       valid_lft forever preferred_lft forever
    inet6 fe80::388a:3eff:fe44:ffea/64 scope link
       valid_lft forever preferred_lft forever

What is the @if152 part for? That number seems to be random. I cannot get Wireguard to work in an LXC and I believe it's due to this changing number. The same exact config works great on a VM with a port called ens18. This is how it looks:

Code:
PostUp = iptables -A FORWARD -i %i -j ACCEPT; iptables -A FORWARD -o %i -j ACCEPT; iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
PostDown = iptables -D FORWARD -i %i -j ACCEPT; iptables -D FORWARD -o %i -j ACCEPT; iptables -t nat -D POSTROUTING -o eth0 -j MASQUERADE

Again, the above code works fine on a VM that keeps the NIC names the same after each reboot.

Is it possible to keep that static in LXC, in order to get Wireguard to work?