×


Create Private Network Bridge on Proxmox VE 6 with NAT

Proxmox is a great platform to create virtual machines and containers.

We can use it to easily migrate instances to other connected nodes.

Here at Ibmi Media, as part of our Server Management Services, we regularly help our Customers to perform related Promox queries.

In this context, we shall look into Private Network Bridge on Proxmox VE 6 with NAT.


How to Create Private Network Bridge on Proxmox ?

In Proxmox virtualization infrastructure, we can do the network configuration in two ways:

Via the CLI (manually editing network configuration files).

From an intuitive graphical user interface.


We can choose either method. However, the choice depends on our Linux administration expertise.


1. How to Create Virtual Network Bridge on Proxmox With NAT ?

For the CLI method, we edit /etc/network/interfaces configuration files directly:

$ sudo vim /etc/network/interfaces

We create a virtual network bridge based on the below network parameters:

  • Network: 192.168.48.0 
  • Network mask: 255.255.255.0 
  • Proxmox host IP: 192.168.48.1 


Then we print current active network interfaces on the server:

$ sudo ip -f inet a s
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
2: enp4s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
inet 192.168.58.236/26 brd 195.201.58.255 scope global enp4s0
valid_lft forever preferred_lft forever


On the other hand, we create a virtual bridge named vmbr1:

auto vmbr1
iface vmbr1 inet static
address 192.168.48.1
netmask 255.255.255.0
bridge_ports none
bridge_stp off
bridge_fd 0

Here, we can see that there is no physical interface that links to the bridge.


How to Configure NAT (Masquerading) ?

Masquerading allows VMs in a private network to access the external networks. It is possible by using the host IP address for outgoing traffic.

iptables rewrite each outgoing packet to appear as originating from the host. In addition, it rewrites the responses accordingly to route to the original sender.

Moving ahead, we will modify the above network configurations to add routing for internet connectivity.

Since primary interface enp4s0 connects to the physical switch and has internet connectivity, we route traffic coming from vmbr1 through it:

auto vmbr1
iface vmbr1 inet static
address 192.168.48.1
netmask 255.255.255.0
bridge_ports none
bridge_stp off
bridge_fd 0
post-up echo 1 > /proc/sys/net/ipv4/ip_forward
post-up iptables -t nat -A POSTROUTING -s ‘192.168.48.0/24’ -o enp4s0 -j MASQUERADE
post-down iptables -t nat -D POSTROUTING -s ‘192.168.48.0/24’ -o enp4s0 -j MASQUERADE

Here, enp4s0 can replace with a VLAN interface or another Linux bridge.


How to Bring up the bridge interface ?

We can validate those network configurations by manually bringing up the bridge interface:

$ sudo ifup vmbr1

Waiting for vmbr1 to get ready (MAXWAIT is 2 seconds).


Then we check the bridge IP information:

$ ip address show dev vmbr1
3: vmbr1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UNKNOWN group default qlen 1000
link/ether 16:cf:7e:23:de:1e brd ff:ff:ff:ff:ff:ff
inet 192.168.48.1/24 brd 192.168.50.255 scope global vmbr1
valid_lft forever preferred_lft forever
inet6 fe80::14cf:7eff:fe23:de1e/64 scope link
valid_lft forever preferred_lft forever


From the output, we can see that the IP address on the vmbr1 is correct.

Then we should be able to restart the networking service without any failures:

$ sudo systemctl restart networking

Eventually, we confirm the status is active:

$ systemctl status networking.service
● networking.service – Raise network interfaces
Loaded: loaded (/lib/systemd/system/networking.service; enabled; vendor preset: enabled)
Active: active (exited) since Fri 2021-05-07 19:27:34 CEST; 29s ago
Docs: man:interfaces(5)
Process: 27355 ExecStart=/sbin/ifup -a –read-environment (code=exited, status=0/SUCCESS)
Main PID: 27355 (code=exited, status=0/SUCCESS)
May 07 19:27:29 proxmox systemd[1]: Starting Raise network interfaces…
May 07 19:27:34 proxmox ifup[27355]: Waiting for DAD… Done
May 07 19:27:34 proxmox ifup[27355]: Waiting for vmbr1 to get ready (MAXWAIT is 2 seconds).
May 07 19:27:34 proxmox systemd[1]: Started Raise network interfaces.

Once we create a Virtual machine on the bridge, it will behave as if it directly connects to the physical network.

The network, in turn, sees each virtual machine as having its own MAC, even though there is only one network cable connecting all of these VMs to the network.


[Need help with creating Private Network Bridge on Proxmox? We are here for you. ]


Conclusion

This article covers how to create a Private Network Bridge on Proxmox. 

To do this:

1. Enable paket forwarding in /etc/sysctl.conf on the Proxmox host

2. Edit /etc/network/interfaces on the ProxMox host, to get 10.10.10.0/24 for your containers, that route through eth0 of the ProxMox host

Code:
# network interface settings; autogenerated# Please do NOT modify this file directly, unless you know what
# you're doing.
#
# If you want to manage parts of the network configuration manually,
# please utilize the 'source' or 'source-directory' directives to do
# so.
# PVE will preserve these directives, but will NOT read its network
# configuration from sourced files, so do not attempt to move any of
# the PVE managed interfaces into external files!
auto lo
iface lo inet loopback
auto eth0
iface eth0 inet static
address YOUR-PUBLIC-STATIC-IP/YOUR-PUBLIC-MASK
gateway YOUR-STATIC-GATEWAY
auto vmbr1
iface vmbr1 inet static
address 10.10.10.1
netmask 255.255.255.0
bridge_ports none
bridge_stp off
bridge_fd 0
post-up iptables -t nat -A POSTROUTING -s '10.10.10.0/24' -o eth0 -j MASQUERADE
post-down iptables -t nat -D POSTROUTING -s '10.10.10.0/24' -o eth0 -j MASQUERADE


3. Configure a container inside 10.10.10.0/24 - as an example using 10.10.10.2 .