Difference between revisions of "Networking vserver guests"
From Linux-VServer
(initial migration/copy from oldwiki) |
(→Private networking: added TOC and outlined sections) |
||
Line 1: | Line 1: | ||
− | == | + | Setting up network access to and from your vserver guests. |
+ | __TOC__ | ||
+ | ==Introduction== | ||
Lets imagine, you have only one external IP -- <code>$EXTIP</code>. | Lets imagine, you have only one external IP -- <code>$EXTIP</code>. | ||
Line 15: | Line 17: | ||
* Control port forwarding on "parent" host. That is, run a router. | * Control port forwarding on "parent" host. That is, run a router. | ||
+ | ==Configuration== | ||
This is how to set it up: | This is how to set it up: | ||
− | + | ===Host=== | |
1. Set up dummy0 interface on the parent host | 1. Set up dummy0 interface on the parent host | ||
# /etc/network/interfaces on a Debian box, | # /etc/network/interfaces on a Debian box, | ||
Line 24: | Line 27: | ||
address 192.168.1.250 | address 192.168.1.250 | ||
netmask 255.255.255.0 | netmask 255.255.255.0 | ||
+ | ===Guests=== | ||
2. Set up each guest vserver: | 2. Set up each guest vserver: | ||
cd /etc/vservers/$VSERVER/interfaces/0 | cd /etc/vservers/$VSERVER/interfaces/0 | ||
Line 31: | Line 35: | ||
echo 24 > prefix | echo 24 > prefix | ||
I suggest you use value of <code>name</code> equal to last digit of the IP -- for easy separation. | I suggest you use value of <code>name</code> equal to last digit of the IP -- for easy separation. | ||
− | + | ===Host as router=== | |
3. Now, configure the host to act as a router. | 3. Now, configure the host to act as a router. | ||
Line 39: | Line 43: | ||
iptables -t nat -A PREROUTING -s ! 192.168.1.0/24 -m tcp -p tcp --dport $EXTPORT -j DNAT --to-destination $VHOST:$INTPORT | iptables -t nat -A PREROUTING -s ! 192.168.1.0/24 -m tcp -p tcp --dport $EXTPORT -j DNAT --to-destination $VHOST:$INTPORT | ||
That's all! | That's all! | ||
− | + | ==Verifying== | |
Try <code>ping pool.ntp.org</code> from your vserver -- it should ping fine. | Try <code>ping pool.ntp.org</code> from your vserver -- it should ping fine. | ||
Try to connect to your <code>$EXTIP:$EXTPORT</code> (from another external host) -- you will successfully connect to service running on a guest vserver. | Try to connect to your <code>$EXTIP:$EXTPORT</code> (from another external host) -- you will successfully connect to service running on a guest vserver. |
Revision as of 21:39, 29 May 2007
Setting up network access to and from your vserver guests.
Contents |
Introduction
Lets imagine, you have only one external IP -- $EXTIP
.
You want to have several vservers running without worrying about port overlapping.
Example:
Two vservers run a default webserver, running on port 80. If each "guest" vserver shares an IP with the host, then the two webservers will confict.
One solution is:
- All vservers are contained in a "virtual lan", say 192.168.1.x
- Each vserver has its own IP
- Control port forwarding on "parent" host. That is, run a router.
Configuration
This is how to set it up:
Host
1. Set up dummy0 interface on the parent host
# /etc/network/interfaces on a Debian box, # configure on other distros with your preferred way auto dummy0 iface dummy0 inet static address 192.168.1.250 netmask 255.255.255.0
Guests
2. Set up each guest vserver:
cd /etc/vservers/$VSERVER/interfaces/0 echo dummy0 > dev echo 192.168.1.1 > ip echo 1 > name echo 24 > prefix
I suggest you use value of name
equal to last digit of the IP -- for easy separation.
Host as router
3. Now, configure the host to act as a router.
3a: For internal packets going outside, pretend each packet came from our external IP:
iptables -t nat -A POSTROUTING -s 192.168.1.0/24 -d ! 192.168.1.0/24 -j SNAT --to-source $EXTIP
3b: For each service that runs on a vserver, map it to an external port. Vserver local address $VHOST
and port $INTPORT
you select one external port $EXTPORT
and run the following:
iptables -t nat -A PREROUTING -s ! 192.168.1.0/24 -m tcp -p tcp --dport $EXTPORT -j DNAT --to-destination $VHOST:$INTPORT
That's all!
Verifying
Try ping pool.ntp.org
from your vserver -- it should ping fine.
Try to connect to your $EXTIP:$EXTPORT
(from another external host) -- you will successfully connect to service running on a guest vserver.