Adding a second IP to a LXC Container

Philipp Page

Member
Apr 26, 2016
30
0
6
26
Hello,

I am new with Proxmox and wanted to add a second static IP address to my LXC Container.
It is currently configured with the IP 178.33.157.22 and works great (bridged mode).
Now I was trying to add 178.33.157.21 and entered instead of net0 net1 and instead of eth0 eth1. But it does not work, the IP does not even show up in Proxmox:
11ebe77aad3462c97cb89105f2de79b6.png

c8c41a724afc3424bfe6220b9a6fb5e6.png


I hope that someone can help.
Edit: No error or message shows up while adding.
 
works fine here..

could you post the output of "pveversion -v" and the content of "/etc/pve/lxc/ID.conf" (where ID is your container's ID)
 
Here the output of "pveversion -v":
Code:
proxmox-ve: 4.1-41 (running kernel: 4.2.8-1-pve)
pve-manager: 4.2-2 (running version: 4.2-2/725d76f0)
pve-kernel-4.2.8-1-pve: 4.2.8-41
lvm2: 2.02.116-pve2
corosync-pve: 2.3.5-2
libqb0: 1.0-1
pve-cluster: 4.0-39
qemu-server: 4.0-72
pve-firmware: 1.1-8
libpve-common-perl: 4.0-59
libpve-access-control: 4.0-16
libpve-storage-perl: 4.0-50
pve-libspice-server1: 0.12.5-2
vncterm: 1.2-1
pve-qemu-kvm: 2.5-14
pve-container: 1.0-62
pve-firewall: 2.0-25
pve-ha-manager: 1.0-28
ksm-control-daemon: 1.2-1
glusterfs-client: 3.5.2-2+deb8u1
lxc-pve: 1.1.5-7
lxcfs: 2.0.0-pve2
cgmanager: 0.39-pve1
criu: 1.6.0-1
zfsutils: 0.6.5-pve9~jessie

And here the config file output with the wrong configured IP on net1:
Code:
arch: amd64
cpulimit: 2
cpuunits: 2048
hostname: gameserver.cod4-server.info
memory: 6144
net0: bridge=vmbr0,gw=149.202.210.254,hwaddr=02:00:00:51:cd:b1,ip=178.33.157.22/32,name=eth0,type=veth
net1: bridge=vmbr0,hwaddr=02:00:00:e7:89:c2,name=eth1,type=veth
ostype: debian
rootfs: local:1001/vm-1001-disk-1.raw,size=250G
swap: 6144

After some tests I also noticed that the ip assignment works if the container is stopped but not if it is running.
 
this looks like the "hotplugging" of new network configuration fails in the container, in which case the old configuration is restored.
you should be able to see any error messages when updating the configuration with "pct set", for example with
"pct set ID -net1 bridge=vmbr0,hwaddr=02:00:00:e7:89:c2,name=eth1,type=veth,ip=XX.XXX.XX.XX,gw=XX.XX.XX.XX"
 
I actually dont know what it was, but after doing apt-get dist-upgrade it works, thanks anyways for your support.
 
After having a more detailed look at the problem, I recognised that it is not fixed.

Here the error message:
Code:
root@srv02:~# pct set 1001 -net1 bridge=vmbr0,hwaddr=02:00:00:51:cd:b1,name=eth1,type=veth,ip=178.33.157.22/32,gw=149.202.210.254
RTNETLINK answers: File exists
command 'lxc-attach -n 1001 -s NETWORK -- /sbin/ip -4 route add 149.202.210.254 dev eth1' failed: exit code 2

When I do not add the gateway to the command, the IP can be added but does not work since the gateway is not set.
 
Last edited:
Could you post the contents of "/etc/network/interfaces" and the output of "ip route" (both in the container)? You cannot add the same gateway/route twice, which is why the command fails.
 
Here the Output of /etc/network/interfaces when i do not enter the gateway:
Code:
root@gameserver:~# cat /etc/network/interfaces
auto lo
iface lo inet loopback

auto eth0
iface eth0 inet static
        address 178.33.157.21
        netmask 255.255.255.255
        post-up ip route add 149.202.210.254 dev eth0
        post-up ip route add default via 149.202.210.254 dev eth0
        pre-down ip route del default via 149.202.210.254 dev eth0
        pre-down ip route del 149.202.210.254 dev eth0

auto eth1
iface eth1 inet static
        address 178.33.157.22
        netmask 255.255.255.255

And here ip route
Code:
root@gameserver:~# ip route
default via 149.202.210.254 dev eth0
149.202.210.254 dev eth0  scope link

You are right, when I have the gateway added on one network adapter it works. So now it is configured that it works :eek:
 
yes, this is a limitation of the kernel - one gateway can only be used once per routing table.
 
Yes, there is a simple solution. Do it like Fabian said: Only add the gateway once for net0 and let the field empty for the following network adapters and only fill out the ip address field. It should look like that:
e4626441ec174c6caeca0deb4f1df531.jpg
 
yes:

ii lxc-pve 1.1.5-7 amd64 Linux containers usersapce tools
ii lxcfs 2.0.0-pve2 amd64 LXC userspace filesystem
ii novnc-pve 0.5-6 amd64 HTML5 VNC client
ii pve-cluster 4.0-39 amd64 Cluster Infrastructure for Proxmox Virtual Environment
ii pve-container 1.0-64 all Proxmox VE Container management tool
ii pve-firewall 2.0-27 amd64 Proxmox VE Firewall
ii pve-firmware 1.1-8 all Binary firmware code for the pve-kernel
ii pve-ha-manager 1.0-31 amd64 Proxmox VE HA Manager
rc pve-kernel-4.2.6-1-pve 4.2.6-36 amd64 The Proxmox PVE Kernel Image
ii pve-kernel-4.2.8-1-pve 4.2.8-41 amd64 The Proxmox PVE Kernel Image
ii pve-kernel-4.4.8-1-pve 4.4.8-51 amd64 The Proxmox PVE Kernel Image
ii pve-libspice-server1 0.12.5-2 amd64 SPICE remote display system server library
ii pve-manager 4.2-5 amd64 The Proxmox Virtual Environment
ii pve-qemu-kvm 2.5-17 amd64 Full virtualization on x86 hardware

I'm using the Image from OVH, which is working perfect besides the more than one ip problem. What version do u have?
 
I am using the same version. Can you share your hosts network configuration. Then i can compare it with my configuration, probably we can find an error there.
 

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!