通过指定的接口将数据传送到互联网

我有一个主要的服务器(Centos 6.2)作为路由器/防火墙和虚拟机。 虚拟机在networking10.0.0.0/8中,其他人(有DHCP服务器)在192.168.0.0/16。

我有两个面向互联网的接口,带有一个可变IP的ppp0和带有一个静态IP的ppp1。 我需要做的是将所有从10.0.0.0/8开始的传出stream量通过ppp1,这样虚拟机将被视为静态IP。 192.168.0.0/16中的机器必须能够直接与10.0.0.0/8中的机器通信。

…基本上,所有stream量都是上网,如果源自10.0.0.0/8,则通过ppp1。 保持不同networking的能力互相交stream。

我已经尝试了几个基于源代码的路由示例,但没有运气,最终没有从主服务器访问虚拟机。 iptables似乎也没有工作。

我的整个模式如下所示:

Server: ppp0: facing internet variable ip ppp1: facing internet static ip vnet0: bridge with ips: 192.168.0.1, 10.0.0.1 eth1: facing the local network vnet1: interface to the first virtual server vnet2: interface to the second virtual server Virtual server 1: eth0: interface connected to main server, with ip: 10.0.0.10. Virtual server 2: eth0: interface connected to main server, with ip: 10.0.0.11. Local Machine *: (All the computers of people working in the office) eth*: interface connected to main server, with ip: 192.168.0.*. 

ip route show在服务器上ip route show的输出是:

 10.9.100.1 dev ppp1 proto kernel scope link src 190.196.26.245 10.52.173.3 dev ppp0 proto kernel scope link src 190.21.97.109 192.168.0.0/24 dev vnet0 proto kernel scope link src 192.168.0.1 169.254.0.0/16 dev eth0 scope link metric 1002 169.254.0.0/16 dev eth2 scope link metric 1004 169.254.0.0/16 dev vnet0 scope link metric 1005 10.0.0.0/8 dev vnet0 proto kernel scope link src 10.0.0.1 default dev ppp0 scope link 

ip link show的输出是:

 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue state UNKNOWN link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP qlen 1000 link/ether 00:21:5e:c2:af:20 brd ff:ff:ff:ff:ff:ff 3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000 link/ether 00:14:78:7c:47:87 brd ff:ff:ff:ff:ff:ff 4: eth2: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000 link/ether ac:f1:df:69:5c:70 brd ff:ff:ff:ff:ff:ff 5: vnet0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UNKNOWN link/ether 00:14:78:7c:47:87 brd ff:ff:ff:ff:ff:ff 7: ppp0: <POINTOPOINT,MULTICAST,NOARP,UP,LOWER_UP> mtu 1492 qdisc pfifo_fast state UNKNOWN qlen 3 link/ppp 8: ppp1: <POINTOPOINT,MULTICAST,NOARP,UP,LOWER_UP> mtu 1492 qdisc pfifo_fast state UNKNOWN qlen 3 link/ppp 9: vnet1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UNKNOWN qlen 500 link/ether fe:54:00:54:f8:48 brd ff:ff:ff:ff:ff:ff 10: vnet2: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UNKNOWN qlen 500 link/ether fe:54:00:d0:14:24 brd ff:ff:ff:ff:ff:ff 

您应该安装iproute软件包来执行策略路由。

 # create a new ip routing table entry echo "66 static-ip" >> /etc/iproute2/rt_tables # add the rule entry to have packets with source 10.0.0.0/8 routed through the # alternate "static-ip" routing table ip rule add from 10.0.0.0/8 lookup static-ip # add the routes to the "static-ip" table ip route add default dev ppp1 table static-ip ip route add 192.168.0.0/16 dev vnet0 table static-ip ip route add 10.0.0.0/8 dev vnet0 table static-ip 

这基本上就是这样,但是你需要弄清楚如何使项目重新启动 – 持久化(这通常是通过将它们放入启动脚本并将它们稍微参数化来满足您的需要来完成的)。 看看这个邮件列表文章 ,举例说明如何以CentOS风格来完成。

请注意,使用具有两个IP别名的桥接接口可能不是您想要的,因为您无法安全地过滤stream量 – 无论您如何configurationIPfilter,桥接连接总是会将stream量从一个网段传递到另一个网段。 您应该使用分别连接到10.0.0.0/8和192.168.0.0/16networking的两个独立接口(如果您不使用桥接AFAICS,则在您的configuration中使用eth0和eth2)。 还应从路由中删除APIPAnetworking(169.254.0.0/16) – 将NOZEROCONF=yes添加到/etc/sysconfig/network并重新启动networking(或主机)。

你想要做基于策略的路由,沿着这些线:

echo 200 Static >> /etc/iproute2/rt_tables
ip rule add from 10.0.0.0/8 table Static
ip route add default via <ppp1 IP> dev ppp1 table Static
ip route flush cache

这将路由从10.0.0.0到ppp1的任何stream量,任何其他stream量应服从常规路由规则。 你可能需要添加一个规则来告诉networking如何相互交谈,这应该做你所问的但..

一些进一步的阅读,这是一个很好的概念介绍: http : //lartc.org/howto/