一,默认在系统中添加的路由会随着网络重新启动丢失
[[email protected] ~]# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 192.168.7.254 0.0.0.0 UG 100 0 0 ens192
192.168.0.0 0.0.0.0 255.255.248.0 U 100 0 0 ens192
二,添加网络路由
[[email protected] ~]# route add -net 192.168.13.0 netmask 255.255.255.0 gw 192.168.7.254
[[email protected] ~]# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 192.168.7.254 0.0.0.0 UG 100 0 0 ens192
192.168.0.0 0.0.0.0 255.255.248.0 U 100 0 0 ens192
192.168.13.0 192.168.7.254 255.255.255.0 UG 0 0 0 ens192
[[email protected] ~]# systemctl restart network
[[email protected] ~]# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 192.168.7.254 0.0.0.0 UG 100 0 0 ens192
192.168.0.0 0.0.0.0 255.255.248.0 U 100 0 0 ens192
[[email protected] ~]#
三,添加永久网络路由(route-ens192是建立的一半更具网卡命名)
[[email protected] ~]# vim /etc/sysconfig/network-scripts/route-ens192
ADDRESS0=192.168.13.0
NETMASK0=255.255.255.0
GATEWAY0=192.168.7.254
四,验证
[[email protected] ~]# systemctl restart network
[[email protected] ~]# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 192.168.7.254 0.0.0.0 UG 100 0 0 ens192
192.168.0.0 0.0.0.0 255.255.248.0 U 100 0 0 ens192
192.168.13.0 192.168.7.254 255.255.255.0 UG 100 0 0 ens192
注意:
1.ADDRESS后面是数字0表示第一条有多条路由就是0,1,2,3依次
2.这种方法只是其中之一,放入/etc/rc.local亦可。
原文地址:https://blog.51cto.com/zhangchengjie/2391061
时间: 2024-10-03 15:48:04