CentOS 如何配置永久静态路由

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

[root@vm-al-bj2-web01 ~]# 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
二,添加网络路由

[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 -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
[root@vm-al-bj2-web01 ~]# systemctl restart network
[root@vm-al-bj2-web01 ~]# 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
[root@vm-al-bj2-web01 ~]#
三,添加永久网络路由(route-ens192是网卡,建议跟随网卡名)

[root@vm-al-bj2-web01 ~]# vim /etc/sysconfig/network-scripts/route-ens192
ADDRESS0=192.168.13.0
NETMASK0=255.255.255.0
GATEWAY0=192.168.7.254
四,验证

[root@vm-al-bj2-web01 ~]# systemctl restart network
[root@vm-al-bj2-web01 ~]# 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亦可。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值