OpenVZ virtualization uses the host node’s kernel and is therefore limited in its network configuration. However, you can set up NAT or bridging for containers.
Here’s how to configure IP routing for an OpenVZ container:
**1. NAT configuration on Host Node (HN)**———
NAT configuration makes the host node act as a gateway for the VEs.
(a) Enable IP forwarding:
```
echo 1 > /proc/sys/net/ipv4/ip_forward
```
(b) Protect against IP spoofing:
```
iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
```
© Open required ports for your VEs in iptables, if necessary.
2. Basic Network Configuration on the OpenVZ Container:
Enter the VE and assign a network:
```
vzctl enter VEID
```
(a) Now assign an IP address to the ethernet card, for example:
```
ip addr add 192.168.0.101/24 dev eth0
```
(b) Finally, add default route:
```
route add default gw 192.168.0.1 eth0
```
© Write this configuration to a script or use vzctl to set up on boot.
3. Bridge Configuration on Host Node (HN):
Another option is network bridging, which will make your VEs look like they are on the same network as your Host.
To set this up, you will need to create a network bridge on your HN and attach the physical network interface to it. For the bridge configuration, here is a basic example:
1. Install the bridge-utils package:
```
apt-get install bridge-utils
```
1. Define a bridge and add your network interface to it:
```
brctl addbr br0
brctl addif br0 eth0
```
1. When done, bring the bridge up:
```
ip link set br0 up
```
1. Configure IP address of the bridge:
```
ip addr add 192.168.1.100/24 dev br0
```
4. Assigning Static IP Address to the Container:
Assign an IP address to the VE from the Host Node:
```
vzctl set 101 —ipadd 192.168.1.101 —save
```
Please, note some commands might require administrative rights to be run, and some paths might vary depending on the Linux distribution that’s being used.