CentOS7添加永久路由

2019-07-20 00:43:02 4295

一,默认在系统中添加的路由会随着网络重新启动丢失

[root@vm-al-bj2-web01 ~]# route -nKernel IP routing tableDestination     Gateway         Genmask         Flags Metric Ref    Use Iface0.0.0.0         192.168.7.254   0.0.0.0         UG    100    0        0 ens192192.168.0.0     0.0.0.0         255.255.248.0   U     100    0        0 ens192

二,添加网络路由

[root@vm-al-bj2-web01 ~]# route add -net 192.168.13.0 netmask 255.255.255.0 gw 192.168.7.254[root@vm-al-bj2-web01 ~]# route -nKernel IP routing tableDestination     Gateway         Genmask         Flags Metric Ref    Use Iface0.0.0.0         192.168.7.254   0.0.0.0         UG    100    0        0 ens192192.168.0.0     0.0.0.0         255.255.248.0   U     100    0        0 ens192192.168.13.0    192.168.7.254   255.255.255.0   UG    0      0        0 ens192[root@vm-al-bj2-web01 ~]# systemctl restart network[root@vm-al-bj2-web01 ~]# route -nKernel IP routing tableDestination     Gateway         Genmask         Flags Metric Ref    Use Iface0.0.0.0         192.168.7.254   0.0.0.0         UG    100    0        0 ens192192.168.0.0     0.0.0.0         255.255.248.0   U     100    0        0 ens192[root@vm-al-bj2-web01 ~]#

三,添加永久网络路由(route-ens192是网卡,建议跟随网卡名)

[root@vm-al-bj2-web01 ~]# vim /etc/sysconfig/network-scripts/route-ens192ADDRESS0=192.168.13.0NETMASK0=255.255.255.0GATEWAY0=192.168.7.254

四,验证

[root@vm-al-bj2-web01 ~]# systemctl restart network[root@vm-al-bj2-web01 ~]# route -nKernel IP routing tableDestination     Gateway         Genmask         Flags Metric Ref    Use Iface0.0.0.0         192.168.7.254   0.0.0.0         UG    100    0        0 ens192192.168.0.0     0.0.0.0         255.255.248.0   U     100    0        0 ens192192.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亦可。


提交成功!非常感谢您的反馈,我们会继续努力做到更好!

这条文档是否有帮助解决问题?

非常抱歉未能帮助到您。为了给您提供更好的服务,我们很需要您进一步的反馈信息:

在文档使用中是否遇到以下问题: