Difference between revisions of "Networking vserver guests RHEL"

From Linux-VServer

Jump to: navigation, search
m (New page: ==Public IP Space== ==Chose a private IP range== Private IP Range: 192.168.1.0<br> Host Private IP: 192.168.1.1<br> Guest Private IP: 192.168.1.2<br> ==network-scripts== In a RHEL based ...)
 
(catchg)
 
(7 intermediate revisions by 3 users not shown)
Line 1: Line 1:
 
==Public IP Space==
 
==Public IP Space==
 
+
5.5.5.5
 
==Chose a private IP range==
 
==Chose a private IP range==
 
Private IP Range: 192.168.1.0<br>
 
Private IP Range: 192.168.1.0<br>
Line 27: Line 27:
 
ifup eth0:1
 
ifup eth0:1
 
</pre>
 
</pre>
 +
 +
Assuming your vserver is test01
 +
<pre>
 +
echo "eth0:1" > /etc/vservers/test01/interfaces/0/dev
 +
echo "192.168.1.2" > /etc/vservers/test01/interfaces/0/ip
 +
echo "255.255.255.0" > /etc/vservers/test01/interfaces/0/mask
 +
</pre>
 +
 +
You can use iptables to make youre system act as a router.
 +
 +
<pre>
 +
iptables -t nat -A POSTROUTING -s 192.168.1.0/24 \
 +
  -d ! 192.168.1.0/24 -j SNAT --to-source 5.5.5.5
 +
iptables-save > /etc/sysconfig/iptables
 +
</pre>
 +
 +
Now your guest should have outbound connectivity.
 +
 +
<pre>
 +
[root@34 ~]# vserver test01 enter
 +
bash-3.1# ifconfig
 +
eth0      Link encap:Ethernet  HWaddr 00:0E:0C:69:ED:E0 
 +
          inet addr:10.10.10.2  Bcast:10.10.10.255  Mask:255.255.255.0
 +
...
 +
bash-3.1# ping www.google.com
 +
PING www.l.google.com (74.125.45.99) 56(84) bytes of data.
 +
64 bytes from yx-in-f99.google.com (74.125.45.99): icmp_seq=1 ttl=244 time=22.3 ms
 +
64 bytes from yx-in-f99.google.com (74.125.45.99): icmp_seq=2 ttl=244 time=22.5 ms
 +
</pre>
 +
 +
==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.
 +
 +
<pre>
 +
5.5.5.5:9000->192.168.1.2:22
 +
</pre>
 +
 +
<pre>
 +
iptables -t nat -A PREROUTING -s ! 192.168.1.0/24 \
 +
  -m tcp -p tcp --dport 9000  -j DNAT --to-destination 192.168.1.2:22
 +
iptables-save > /etc/sysconfig/iptables
 +
</pre>
 +
 +
[[Category:Network related]]

Latest revision as of 22:25, 21 October 2011

Contents

[edit] Public IP Space

5.5.5.5

[edit] Chose a private IP range

Private IP Range: 192.168.1.0
Host Private IP: 192.168.1.1
Guest Private IP: 192.168.1.2

[edit] network-scripts

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
DEVICE=eth0:1
HWADDR=00:0e:0c:69:ed:e0
ONBOOT=yes
NETMASK=255.255.255.0
IPADDR=192.168.1.1
TYPE=Ethernet

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 "192.168.1.2" > /etc/vservers/test01/interfaces/0/ip
echo "255.255.255.0" > /etc/vservers/test01/interfaces/0/mask

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

iptables -t nat -A POSTROUTING -s 192.168.1.0/24 \ 
  -d ! 192.168.1.0/24 -j SNAT --to-source 5.5.5.5
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:10.10.10.2  Bcast:10.10.10.255  Mask:255.255.255.0
...
bash-3.1# ping www.google.com
PING www.l.google.com (74.125.45.99) 56(84) bytes of data.
64 bytes from yx-in-f99.google.com (74.125.45.99): icmp_seq=1 ttl=244 time=22.3 ms
64 bytes from yx-in-f99.google.com (74.125.45.99): icmp_seq=2 ttl=244 time=22.5 ms

[edit] 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.

5.5.5.5:9000->192.168.1.2:22
iptables -t nat -A PREROUTING -s ! 192.168.1.0/24 \
  -m tcp -p tcp --dport 9000  -j DNAT --to-destination 192.168.1.2:22
iptables-save > /etc/sysconfig/iptables
Personal tools