Difference between revisions of "Networking vserver guests RHEL"

From Linux-VServer

Jump to: navigation, search
Line 69: Line 69:
iptables-save > /etc/sysconfig/iptables
iptables-save > /etc/sysconfig/iptables

Revision as of 20:40, 21 October 2011


Public IP Space

Chose a private IP range

Private IP Range:
Host Private IP:
Guest Private IP:


In a RHEL based system many configurations are stored in /etc/sysconfig. The network settings are /etc/sysconfig/network-scripts.

cp /etc/sysconfig/network-scripts/ifcfg-eth0 /etc/sysconfig/network-scripts/ifcfg-eth0:1
vi  /etc/sysconfig/network-scripts/ifcfg-eth0:1

This IP address will now start at boot up.

ifup eth0:1

Assuming your vserver is test01

echo "eth0:1" > /etc/vservers/test01/interfaces/0/dev
echo "" > /etc/vservers/test01/interfaces/0/ip
echo "" > /etc/vservers/test01/interfaces/0/mask

You can use iptables to make youre system act as a router.

iptables -t nat -A POSTROUTING -s \ 
  -d ! -j SNAT --to-source
iptables-save > /etc/sysconfig/iptables

Now your guest should have outbound connectivity.

[root@34 ~]# vserver test01 enter
bash-3.1# ifconfig 
eth0      Link encap:Ethernet  HWaddr 00:0E:0C:69:ED:E0  
          inet addr:  Bcast:  Mask:
bash-3.1# ping www.google.com
PING www.l.google.com ( 56(84) bytes of data.
64 bytes from yx-in-f99.google.com ( icmp_seq=1 ttl=244 time=22.3 ms
64 bytes from yx-in-f99.google.com ( icmp_seq=2 ttl=244 time=22.5 ms

Inbound Connections and NAT

Now we have to establish inbound connectivity. This can be done with Network Address Translation. We can expose the SSH service through NAT.>
iptables -t nat -A PREROUTING -s ! \
  -m tcp -p tcp --dport 9000  -j DNAT --to-destination
iptables-save > /etc/sysconfig/iptables
Personal tools