Centos 6.x 多宿主路由问题

Centos 6.x 多宿主路由问题

我有一个难题,想听听任何指示(现在已经为此工作了 2 天,需要将此服务器投入生产)。

我的“google-foo”对此并不强。

我有一个多宿主 Linux 服务器 - Centos 6.x

我删除了该服务器上双 10 Gig 端口上的 LACP/绑定。

尽管尝试为每个 NIC 设置单独的 ip 路由,但一切都是通过 NIC em3(系统的默认路由)发出的。我希望这个系统的行为是为了:

   - em3 to only handle external (internet) traffic.
   - em2 to only handle 10 Gig traffic
   - em1 to handle everything else / internal traffic.

网络上的下一跳是:

  - em1 & em2 go to a good L2/L3, 10 Gig switch 
  - em3 goes to a decent L2/L3, 1 Gig switch

注意:IP 地址已被修改了一点。

em1 是一个内部 1 Gig 网络,它有权查看内部网络上的所有内容,并且能够通过我们的默认防火墙/路由器访问开放互联网。

em1 is  10.10.18.21/16    gw is to be 10.10.5.1

em2 是一个内部 10 Gig 网络,只能看到该网段上的其他 10 Gig 设备。

em2 is  10.16.64.21/26    gw is to be 10.16.64.21

em3 是允许远程连接授权用户的外部网络。

em3 is  10.48.61.80/24    gw is to be 10.48.61.1

我在 /etc/iproute/rt_tables 文件中添加了条目,如下所示:

#
# reserved values
#
255 local
254 main
253 default
0   unspec
#
# local
#
#1  inr.ruhep
10 em1table
20 em2table
30 em3table

我还创建了“路线”和“规则”文件。

-rw-r--r--  1 root root    98 Feb 15 08:54 route-em1
-rw-r--r--  1 root root    87 Feb 16 12:31 route-em2
-rw-r--r--  1 root root   102 Feb 16 10:37 route-em3
-rw-r--r--  1 root root    65 Feb 15 08:11 rule-em1
-rw-r--r--  1 root root    68 Feb 16 12:32 rule-em2
-rw-r--r--  1 root root    68 Feb 16 10:37 rule-em3


[/etc/sysconfig/network-scripts]$ cat route-em1
10.10.18.0 dev em1 src 10.10.18.21 table em1table
default via 10.10.5.1 dev em1 table em1table
[/etc/sysconfig/network-scripts]$ cat rule-em1
from 10.10.18.21/16 table em1table
to 10.10.5.1 table em1table


[/etc/sysconfig/network-scripts]$ cat route-em2
10.16.64.0/28 dev em2 table em2table
default via 10.16.64.254 dev em2 table em2table
[/etc/sysconfig/network-scripts]$ cat rule-em2
from 10.16.64.21/28 table em2table
to 10.16.64.254 table em2table

67.134
[/etc/sysconfig/network-scripts]$ cat route-em3
10.48.161.0 dev em3 src 10.48.161.82 table em3table
default via 10.48.161.1 dev em3 table em3table
[/etc/sysconfig/network-scripts]$ cat rule-em3
from 10.48.161.82/24 table em3table
to 10.48.161.1 table em3table


[/etc/sysconfig/network-scripts]$ ip route show table em1table
10.10.18.0 dev em1  scope link  src 10.10.18.21 
default via 10.10.5.1 dev em1 

[/etc/sysconfig/network-scripts]$ ip route show table em2table
10.16.64.0/28 dev em2  scope link 
default via 10.16.64.254 dev em2 

[/etc/sysconfig/network-scripts]$ ip route show table em3table
10.48.161.0 dev em3  scope link  src 10.48.161.82 
default via 10.48.161.1 dev em3 

以下是一些附加信息:

[/etc/sysconfig/network-scripts]$ route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
10.48.161.0     0.0.0.0         255.255.255.0   U     0      0        0 em3
10.16.64.0      0.0.0.0         255.255.192.0   U     0      0        0 em2
10.10.0.0       0.0.0.0         255.255.0.0     U     0      0        0 em1
169.254.0.0     0.0.0.0         255.255.0.0     U     1002   0        0 em1
169.254.0.0     0.0.0.0         255.255.0.0     U     1003   0        0 em2
169.254.0.0     0.0.0.0         255.255.0.0     U     1004   0        0 em3
0.0.0.0         10.48.161.1     0.0.0.0         UG    0      0        0 em3
[/etc/sysconfig/network-scripts]$ 


[/etc/sysconfig/network-scripts]$ ip route show
10.48.161.0/24 dev em3  proto kernel  scope link  src 10.48.161.82 
10.16.64.0/18 dev em2  proto kernel  scope link  src 10.16.64.21 
10.10.0.0/16 dev em1  proto kernel  scope link  src 10.10.18.21 
169.254.0.0/16 dev em1  scope link  metric 1002 
169.254.0.0/16 dev em2  scope link  metric 1003 
169.254.0.0/16 dev em3  scope link  metric 1004 
default via 10.48.161.1 dev em3 
[/etc/sysconfig/network-scripts]$ 


[/etc/sysconfig/network-scripts]$ ip route show to match 10.16.64.0/28
10.16.64.0/18 dev em2  proto kernel  scope link  src 10.16.64.21 
default via 67.134.161.1 dev em3 

[/etc/sysconfig/network-scripts]$ ip route show to match 10.10.18.0/16
10.10.0.0/16 dev em1  proto kernel  scope link  src 10.10.18.21 
default via 67.134.161.1 dev em3 

[/etc/sysconfig/network-scripts]$ ip route show to match 67.134.161.0/24
10.48.161.0/24 dev em3  proto kernel  scope link  src 10.48.161.82 
default via 10.48.161.1 dev em3 



[/etc/sysconfig/network-scripts]$ cat ifcfg-em1
DEVICE=em1
#MASTER=bond0
#SLAVE=yes
HWADDR=c8:1f:66:f4:ce:10
TYPE=Ethernet
UUID=bfa14e4a-66b0-4b83-93a4-094f9090aea7
ONBOOT=yes
NM_CONTROLLED=no
BOOTPROTO=none
IPADDR=10.10.18.21
PREFIX=16
#GATEWAY=10.10.5.1
DNS1=10.10.5.8
DNS2=10.10.5.9
DOMAIN=AXS
DEFROUTE=YES
IP4_FAILURE_FATAL=yes
IP6INIT=no
NAME="em1"
NETMASK=255.255.0.0
IPV6INIT=no
USERCTL=no

[/etc/sysconfig/network-scripts]$ cat ifcfg-em2
DEVICE=em2
#MASTER=bond0
#SLAVE=yes
HWADDR=c8:1f:66:f4:ce:12
TYPE=Ethernet
UUID=c8c5e1fb-ba40-4537-89ad-f7df5de59f8b
ONBOOT=yes
NM_CONTROLLED=no
BOOTPROTO=none
IPADDR=10.16.64.21
PREFIX=18
#GATEWAY=10.16.64.254
DNS1=10.10.5.8
DNS2=10.10.5.9
DOMAIN=AXS
#DEFROUTE=YES
IP4_FAILURE_FATAL=yes
IP6INIT=no
NAME="em2"
#IPADDR=10.16.64.21
NETMASK=255.255.192.0
IPV6INIT=no
USERCTL=no

[/etc/sysconfig/network-scripts]$ cat ifcfg-em3
DEVICE=em3
HWADDR=C8:1F:66:F4:CE:14
TYPE=Ethernet
UUID=aa9552be-0075-46b2-8eff-b7c49c8c999f
ONBOOT=yes
NM_CONTROLLED=no
BOOTPROTO=none
IPADDR=10.48.161.82
PREFIX=24
GATEWAY=10.48.161.1
DNS1=10.10.5.8
DNS2=10.10.5.9
DNS3=205.171.3.65
DNS4=8.8.8.8
DOMAIN=axs.tv
DEFROUTE=yes
IPV4_FAILURE_FATAL=yes
IPV6INIT=no
USERCTL=no

而且,当我尝试 ping 每个接口时:

[/etc/sysconfig/network-scripts]$ ping -I em1 10.10.5.1
PING 10.10.5.1 (10.10.5.1) from 10.10.18.21 em1: 56(84) bytes of data.
--- 10.10.5.1 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2846ms
rtt min/avg/max/mdev = 0.081/0.101/0.135/0.024 ms

[/etc/sysconfig/network-scripts]$ ping -I em2 10.16.64.154
PING 10.16.64.154 (10.16.64.154) from 10.16.64.21 em2: 56(84) bytes of data.
--- 10.16.64.154 ping statistics ---
5 packets transmitted, 0 received, +3 errors, 100% packet loss, time 4022ms
pipe 3

[/etc/sysconfig/network-scripts]$ ping -I em3 www.google.com
--- www.google.com ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 3366ms
rtt min/avg/max/mdev = 2.657/2.679/2.711/0.041 ms

答案1

我知道这是旧条目,但是,仍然出现在多家庭搜索中。
添加额外网关时我很困惑,一次只能使用一个网关。
指定主网关,始终抢占所有流量。
我只用三个设置解决了我的问题:
在您最喜欢的 sysctl 脚本上添加以下内容:(我在 Centos 上使用 /usr/lib/sysctl.d/99-multihome)

# add forwarding
net.ipv4.ip_forward = 1
# Accept source routing
net.ipv4.conf.default.accept_source_route = 1
net.ipv4.conf.all.accept_source_route = 1

请注意,可以确定您的防火墙在处理此更改时能够胜任其工作。

相关内容