查看当前路由表与网卡状态
1/5
首先查看当前系统的路由表状态,运行命令:route -n
[root@vnode33 network-scripts]# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 135.252.214.1 0.0.0.0 UG 100 0 0 eth0
135.252.214.0 0.0.0.0 255.255.255.0 U 100 0 0 eth0
172.86.40.0 0.0.0.0 255.255.255.0 U 100 0 0 eth1
192.168.122.0 0.0.0.0 255.255.255.0 U 0 0 0 virbr0
2/5
确认当前正在使用的网卡接口,本例中使用的是 eth1。
补充说明:若服务器配备多块网卡,可为不同网卡分别指定独立的静态路由规则。
例如存在 eth0 和 eth2 等其他网卡时,操作方法相同,需依次为每块网卡创建对应的路由配置文件,如 route-eth0、route-eth1 和 route-eth2。
[root@vnode33 network-scripts]# ls
ifcfg-eth0 ifcfg-eth1:enodeb2 ifcfg-eth1:mme2 ifdown ifdown-ib ifdown-isdn ifdown-routes ifdown-TeamPort ifup-aliases ifup-ib ifup-isdn ifup-post ifup-sit ifup-tunnel network-functions
ifcfg-eth1 ifcfg-eth1:gx ifcfg-eth1:sgi ifdown-bnep ifdown-ippp ifdown-post ifdown-sit ifdown-tunnel ifup-bnep ifup-ippp ifup-plip ifup-ppp ifup-Team ifup-wireless network-functions-ipv6
ifcfg-eth1:enodeb1 ifcfg-eth1:mme1 ifcfg-lo ifdown-eth ifdown-ipv6 ifdown-ppp ifdown-Team ifup ifup-eth ifup-ipv6 ifup-plusb ifup-routes ifup-TeamPort init.ipv6-global route-eth1
3/5
接下来添加一条静态路由,使得访问 172.0.0.0/8 网段的数据包经由网关 172.86.40.254 转发。
执行以下命令编辑配置文件:
vi /etc/sysconfig/network-scripts/route-eth1
在文件中添加如下路由条目:
172.0.0.0/8 via 172.86.40.254
保存更改并退出编辑器。
4/5
随后需要重启网络服务以使配置生效:
service network restart
5/5
最后进行验证,再次执行 route -n 命令;此时可观察到新路由已加入路由表,且无论重启主机还是仅重启网络服务,该路由信息均会保留。
[root@vnode33 network-scripts]# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 135.252.214.1 0.0.0.0 UG 100 0 0 eth0
135.252.214.0 0.0.0.0 255.255.255.0 U 100 0 0 eth0
172.0.0.0 172.86.40.254 255.0.0.0 UG 100 0 0 eth1
172.86.40.0 0.0.0.0 255.255.255.0 U 100 0 0 eth1
192.168.122.0 0.0.0.0 255.255.255.0 U 0 0 0 virbr0
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持本站。