Linux添加永久静态路由信息

发布时间:2020-08-10 22:06:42 作者:ywxj_001
来源:ITPUB博客 阅读:139
因为linux服务器有多网卡,需要有些网卡走指定的路由,就需要单独设置静态路由。
通过route add添加的静态路由,如果服务器重启或者是网卡重启,这个静态路由就会丢失。
[root@test ~]# route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
192.168.123.0   0.0.0.0         255.255.255.0   U     0      0        0 eth2
10.0.0.0        0.0.0.0         255.255.0.0     U     0      0        0 eth0
169.254.0.0     0.0.0.0         255.255.0.0     U     0      0        0 eth2
0.0.0.0         192.168.123.254 0.0.0.0         UG    0      0        0 eth2

用route add添加静态路由。
[root@test ~]# route add -net 10.0.0.0 netmask 255.0.0.0 dev eth0
[root@test ~]# route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
192.168.123.0   0.0.0.0         255.255.255.0   U     0      0        0 eth2
10.0.0.0        0.0.0.0         255.255.0.0     U     0      0        0 eth0
169.254.0.0     0.0.0.0         255.255.0.0     U     0      0        0 eth2
10.0.0.0        0.0.0.0         255.0.0.0       U     0      0        0 eth0
0.0.0.0         192.168.123.254 0.0.0.0         UG    0      0        0 eth2

添加成功,但是重启网络服务后路由丢失,证明这个路由是动态参数。
[root@test ~]# service network restart
Shutting down interface eth0:                              [  OK  ]
Shutting down interface eth2:                              [  OK  ]
Shutting down loopback interface:                          [  OK  ]
Bringing up loopback interface:                            [  OK  ]
Bringing up interface eth0:                                [  OK  ]
Bringing up interface eth2:                                [  OK  ]
[root@test ~]# route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
192.168.123.0   0.0.0.0         255.255.255.0   U     0      0        0 eth2
10.0.0.0        0.0.0.0         255.255.0.0     U     0      0        0 eth0
169.254.0.0     0.0.0.0         255.255.0.0     U     0      0        0 eth2
0.0.0.0         192.168.123.254 0.0.0.0         UG    0      0        0 eth2

需要永久添加静态路由:
/etc/sysconfig/network-scripts/下面
[root@test ~]# cd /etc/sysconfig/network-scripts/
加入一条静态路由到route-eth0,让网络服务每次重启都会自动加载这些信息。保证路由不丢失。
[root@shwmsdb1 network-scripts]# cat route-eth0
10.0.0.0/8  via  10.0.0.254

[root@test ~]# route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
192.168.123.0   0.0.0.0         255.255.255.0   U     0      0        0 eth2
10.0.0.0        0.0.0.0         255.255.0.0     U     0      0        0 eth0
169.254.0.0     0.0.0.0         255.255.0.0     U     0      0        0 eth2
10.0.0.0        10.0.0.254      255.0.0.0       UG    0      0        0 eth0
0.0.0.0         192.168.123.254 0.0.0.0         UG    0      0        0 eth2

这样无论是重启主机还是重启网络服务路由信息都不会丢了。

推荐阅读:
  1. Linux添加永久路由
  2. Windows 系统添加静态路由。

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

linux 信息 永久

上一篇:数据库事务

下一篇:手把手带你体验Stream流

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》