How to assign static IP for container?

micah

New Member
Jul 29, 2016
10
1
1
34
I am newish to networking and a couple days new to virtualization and I'm having a bit of a hard time wrapping my head around networking, specifically assigning static IPs to my containers.

proxmoxserver has an IP of 192.168.0.170 and I would like to assign ....171 to my first container and 172 to my second. I have read the wiki but am still having a hard time, it seems no matter what I set my options to in the GUI or how I edit config files (following the wiki) it's either ignored (for example, container 100 is on 192.168.0.23) or I lose internet connection and ip address on the container (127.0.0.1).

Here is my current /etc/network/interfaces on my host:

Code:
auto lo
iface lo inet loopback

iface eth0 inet static
  address  192.168.0.171
  netmask  255.255.255.0

iface eth1 inet manual

auto vmbr0
iface vmbr0 inet static
  address  192.168.0.170
  netmask  255.255.255.0
  gateway  192.168.0.1
  bridge_ports eth0
  bridge_stp off
  bridge_fd 0

At the moment my container is set to DHCP which at least allows for connection, but the wrong IP. In the GUI if I set it to static and save then it reverts to 192.0.0.1. If I set to static and try to input an IP and Gateway it won't allow me to save. Network name is eth0 and bridge is vmbr0.

What am I doing wrong here?
 
Undo your eth0 changes, that's not what you want. You should only have .170 in your /etc/network/interfaces

Having a static IP is very simple, just do this:

View attachment 4063

For your network, you'll have to put 192.168.0.171/24 in the IPv4/CIDR field and you VM should work.
Urg. Perfect, fixed it thanks. So much trial and error and I was missing the /CIDR there.

In case anybody else searches and finds this, just putting in the IPv4/CIDR field did apply a static IP but I couldn't connect to the internet from the container. Putting in the gateway fixed this.
 
  • Like
Reactions: Edvin
Undo your eth0 changes, that's not what you want. You should only have .170 in your /etc/network/interfaces

Having a static IP is very simple, just do this:

View attachment 4063

For your network, you'll have to put 192.168.0.171/24 in the IPv4/CIDR field and you VM should work.

What proxmox version is this?
in 4.4 there's no such option
Screen Shot 2017-01-27 at 14.29.08.png
 
What proxmox version is this?
in 4.4 there's no such option
View attachment 4690

LnxBil's screenshot is for container setup (where you can configure the network setup including addresses, gateways, DNS) - your screenshot is for VM setup (where you can only configure the hypervisor side of the network setup).
 
  • Like
Reactions: onetiger
Hello, I have a similar issue.
prox mox 6.1.3
CT centos 7 upgrade to latest as of 3/5/2020.

In proxmox, on the network tab of the CT i set it to DHCP. start CT and it has internet.
If I change to static, set IP to 192.168.1.15/24 and gateway to 192.168.1.1 and than reboot the CT there is no internet traffic on the CT and ifconfig in the container does not show a IPV4 address like it does when set to DHCP

address of the prox mox is 192.168.1.147/24
 
I tried to go around it, In the router I set a static map for the MAC that is generated on the network tab and set it to the IP I want but same error as setting static ip.
 
I solved it. When testing something grabbed the IP while it was in DHCP range and kept it after I switched the range. All is good
 
I always leave it at DHCP and do IP reservations in my router (pfSense). That way if I want to change it, I can change all the IPs at once in the pfSense interface. Seems more convenient to me. YMMV
 
Undo your eth0 changes, that's not what you want. You should only have .170 in your /etc/network/interfaces

Having a static IP is very simple, just do this:

View attachment 4063

For your network, you'll have to put 192.168.0.171/24 in the IPv4/CIDR field and you VM should work.
I know it's an old thread, but first, thank you so much for this, second, I tried setting it up to /32 not /24 and didn't work, why it only worked through /24 and not /32?
 
I tried setting it up to /32 not /24 and didn't work, why it only worked through /24 and not /32?
Why would you want to set a /32 IP? Normally you have an IP in a subnet that is larger than yourself because you want to talk to other machines, so you would set e.g. /24. Maybe you missunderstood what a CIDR is or I missunderstood what you exactly want to do with it. Please elaborate.
 
Why would you want to set a /32 IP? Normally you have an IP in a subnet that is larger than yourself because you want to talk to other machines, so you would set e.g. /24. Maybe you missunderstood what a CIDR is or I missunderstood what you exactly want to do with it. Please elaborate.
As I understand, this settings set a static IP for the specified network interface, so why setting it to /24 and not /32 to just include only one ip address?
 
For a VM to communicate outside of itself i.e. over a network, it needs an address to send the data to (the default route / gateway). This gateway/router MUST be in the same subnet as the VM otherwise the VM cannot communicate with it.
If you set the VM subnet mask / CIDR to /32 you are saying this is the ONLY device and it cannot communicate with anything else.
192.168.0.1/24 can communicate with any device on the 192.168.0 subnet.
10.11.12.13/24 can communicate with any device on the 10.11.12 subnet.
Subnet masking is not really complex (if you use a subnet calculator) and hopefully things start making sense.
 
For a VM to communicate outside of itself i.e. over a network, it needs an address to send the data to (the default route / gateway). This gateway/router MUST be in the same subnet as the VM otherwise the VM cannot communicate with it.
If you set the VM subnet mask / CIDR to /32 you are saying this is the ONLY device and it cannot communicate with anything else.
192.168.0.1/24 can communicate with any device on the 192.168.0 subnet.
10.11.12.13/24 can communicate with any device on the 10.11.12 subnet.
Subnet masking is not really complex (if you use a subnet calculator) and hopefully things start making sense.
Thank you for explaining, that's what I understand yes, I just didn't know that the same rules apply when setting a static ip too.
 

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!