服务器路由配置--Route
第1章命令配置
虚拟服务器⽹卡配置信息虚拟⽹卡名称虚拟⽹卡模式
服务器01eth110.0.0.10/24nat模式
服务器02eth210.0.0.11/24nat模式eth310.0.1.11/24主机模式
服务器03eth210.0.1.10/24主机模式1.1 查看三台主机的路由表
1.1.1 服务器01
[root@route-01 ~]# route -n
Kernel IP routing table
Destination    Gateway        Genmask        Flags Metric Ref    Use Iface
10.0.0.0        0.0.0.0        255.255.255.0  U    0      0        0 eth1
route add 添加路由
169.254.0.0    0.0.0.0        255.255.0.0    U    1002  0        0 eth1
0.0.0.0        10.0.0.254      0.0.0.0        UG    0      0        0 eth1
1.1.2 服务器02
[root@route-02 ~]# route -n
Kernel IP routing table
Destination    Gateway        Genmask        Flags Metric Ref    Use Iface
10.0.0.0        0.0.0.0        255.255.255.0  U    0      0        0 eth2
10.0.1.0        0.0.0.0        255.255.255.0  U    0      0        0 eth3
169.254.0.0    0.0.0.0        255.255.0.0    U    1002  0        0 eth2
169.254.0.0    0.0.0.0        255.255.0.0    U    1003  0        0 eth3
0.0.0.0        10.0.1.254      0.0.0.0        UG    0      0        0 eth3
1.1.3 服务器03
[root@route-03 ~]# route -n
Kernel IP routing table
Destination    Gateway        Genmask        Flags Metric Ref    Use Iface
10.0.1.0        0.0.0.0        255.255.255.0  U    0      0        0 eth2
169.254.0.0    0.0.0.0        255.255.0.0    U    1002  0        0 eth2
0.0.0.0        10.0.1.254      0.0.0.0        UG    0      0        0 eth2
1.2 服务器主机配置
1.2.1 服务器01配置路由信息
[root@route-01 ~]# route add -net 10.0.1.0/24 gw 10.0.0.11
[root@route-01 ~]# route -n
Kernel IP routing table
Destination    Gateway        Genmask        Flags Metric Ref    Use Iface
10.0.0.0        0.0.0.0        255.255.255.0  U    0      0        0 eth1
10.0.1.0        10.0.0.11      255.255.255.0  UG    0      0        0 eth1
169.254.0.0    0.0.0.0        255.255.0.0    U    1002  0        0 eth1
0.0.0.0        10.0.0.254      0.0.0.0        UG    0      0        0 eth1
# 说明:利⽤添加⽹络路由条⽬命令,在服务器01上正确添加上⼀条去往10.0.1.0 ⽹段的路由条⽬
1.2.2 服务器03上配置⽹络路由条⽬
[root@route-03 ~]# route add -net 10.0.0.0/24 gw 10.0.1.11
[root@route-03 ~]# route -n
Kernel IP routing table
Destination    Gateway        Genmask        Flags Metric Ref    Use Iface
10.0.0.0        10.0.1.11      255.255.255.0  UG    0      0        0 eth2
10.0.1.0        0.0.0.0        255.255.255.0  U    0      0        0 eth2
169.254.0.0    0.0.0.0        255.255.0.0    U    1002  0        0 eth2
0.0.0.0        10.0.1.254      0.0.0.0        UG    0      0        0 eth2
说明:利⽤添加⽹络路由条⽬命令,在服务器03上正确添加上⼀条去往10.0.0.0⽹段条⽬
1.2.3 在服务器02 上开启路由转发
服务器02主机在拓扑中负责进⾏路由转发,需要开启相关参数。
[root@route-02 ~]# vim /f
# Kernel sysctl configuration file for Red Hat Linux
#
# For binary values, 0 is disabled, 1 is enabled.  See sysctl(8) and
# f(5) for more details.
#
# Use '/sbin/sysctl -a' to list all possible parameters.
# Controls IP packet forwarding
net.ipv4.ip_forward = 1
1.2.3.1 显⽰转发信息
[root@route-02 ~]# sysctl -p
net.ipv4.ip_forward = 1
f.default.rp_filter = 1
f.default.accept_source_route = 0
kernel.sysrq = 0
<_uses_pid = 1
p_syncookies = 1
kernel.msgmnb = 65536
kernel.msgmax = 65536
kernel.shmmax = 68719476736
kernel.shmall = 4294967296
1.3 虚拟主机路由访问验证
1.3.1 在服务器01 上验证
[root@route-01 ~]# traceroute 10.0.1.10
traceroute to 10.0.1.10 (10.0.1.10), 30 hops max, 60 byte packets
1  10.0.0.11 (10.0.0.11)  0.25
2 ms  0.231 ms  0.199 ms
2  10.0.1.10 (10.0.1.10)  0.999 ms !X  0.970 ms !X  0.940 ms !X
# 说明:通过 traceroute 路由路径追踪命令,已确认路由⾛向符合配置需求,即路由配置正确⽆误。
#    !X 表⽰已经完成路由追踪过程。
1.3.2 服务器03上进⾏验证
[root@route-03 ~]# traceroute 10.0.0.10
traceroute to 10.0.0.10 (10.0.0.10), 30 hops max, 60 byte packets
1  10.0.1.11 (10.0.1.11)  0.287 ms  0.209 ms  0.176 ms
2  10.0.0.10 (10.0.0.10)  0.469 ms !X  0.526 ms !X  0.498 ms !X
#说明:通过 traceroute 路由路径追踪命令,已确认路由⾛向符合配置需求,即路由配置正确⽆误。
#      !X 表⽰已经完成路由追踪过程。
第2章 linux 路由部署项⽬结论
整体配置部署步骤已符合原有项⽬需求,⽣产环境中,已经可以满⾜ 3 台服务器主机在正常访问外⽹的同时,可以利⽤服务器路由转发功能与服务器⽹路路由配置,实现内⽹环境跨⽹段进⾏通讯需求。
2.1 linux 路由部署异常分析
2.1.1 防⽕墙异常问题
服务器主机 02 起到路由转发功能,类似于路由器的⾓⾊,因此服务器上防⽕墙功能需要关闭,否则防⽕墙相应条⽬会阻⽌掉路由转发流量。
2.1.2 虚拟⽹卡异常问题
服务器主机⽹卡信息配置中,尽量选择 nat 模式或者仅主机模式⽹卡进⾏配置,不要选择LAN 区段⽹卡配置⽅式,否则根据虚拟软件⽹络⼯作原理,LAN 区段⽹卡配置模式⽆法进⾏路由的转发,会影响最终配置效果。