服务器:IBM X3650
  系统    :Red Hat Enterprise Linux Server release 5.4
  eth0     :  IP=10.30.10.19
                 NETMASK=255.255.255.0
                 GATEWAY=10.30.10.254
                 DNS1=10.30.10.1
  eth1     :  IP=192.168.0.11
                  NETMASK=255.255.255.0
                  GATEWAY=192.168.0.1
                  DNS1=192.168.0.1

以上分别为两张网卡设置的IP地址
    开启ip forward功能,并让其永久生效
 # vim /etc/sysctl.conf
         net.ipv4.ip_forward = 0            #将此行的0参数修改为1,表示开启
    执行sysctl -p 让其生效
上述配置完成后需增加路由,具体操作如下:
route add -net 0.0.0.0 netmask 0.0.0.0 gw 10.30.10.254 dev eth0
route add -net 192.168.0.0 netmask 255.255.255.0 gw 192.168.0.1 dev eth1

   再使用route -n查看路由信息
# route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
10.30.10.0      0.0.0.0         255.255.255.0   U     1      0        0 eth0
169.254.95.0    0.0.0.0         255.255.255.0   U     1      0        0 usb0
192.168.0.0    192.168.0.1    255.255.255.0   UG    0      0        0 eth1
0.0.0.0         10.30.10.254    0.0.0.0         UG    0      0        0 eth0

路由信息己设置OK了,接下来就是进行测试了
  可以通过ping 这两个网卡的IP地址,测试是否能正常通讯(其它因素不在本文范围考虑)
  C:\Users\fzh>ping 192.168.0.11

Pinging 192.168.0.11 with 32 bytes of data:
Reply from 192.168.0.11: bytes=32 time<1ms TTL=62
Reply from 192.168.0.11: bytes=32 time<1ms TTL=62
Reply from 192.168.0.11: bytes=32 time<1ms TTL=62
Reply from 192.168.0.11: bytes=32 time<1ms TTL=62

Ping statistics for 192.168.0.11:
    Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
    Minimum = 0ms, Maximum = 0ms, Average = 0ms

C:\Users\fzh>ping 10.30.10.19

Pinging 10.30.10.19 with 32 bytes of data:
Reply from 10.30.10.19: bytes=32 time=1ms TTL=63
Reply from 10.30.10.19: bytes=32 time<1ms TTL=63
Reply from 10.30.10.19: bytes=32 time<1ms TTL=63
Reply from 10.30.10.19: bytes=32 time<1ms TTL=63

Ping statistics for 10.30.10.19:
    Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
    Minimum = 0ms, Maximum = 1ms, Average = 0ms


 两张网卡地址都能正常ping通,再将路由设置到开启启动脚本里边:
# vim /etc/rc.local
route add -net 0.0.0.0 netmask 0.0.0.0 gw 10.30.10.254 dev eth0
route add -net 192.168.0.0 netmask 255.255.255.0 gw 192.168.0.1 dev eth1

 
  重启下,再测试,OK!!

  备注: 涉及到的公网IP部分己经使用192.168.0.11代替,其余部分为未做更改。

转载请加上版权