网创优客建站品牌官网
为成都网站建设公司企业提供高品质网站建设
热线:028-86922220
成都专业网站建设公司

定制建站费用3500元

符合中小企业对网站设计、功能常规化式的企业展示型网站建设

成都品牌网站建设

品牌网站建设费用6000元

本套餐主要针对企业品牌型网站、中高端设计、前端互动体验...

成都商城网站建设

商城网站建设费用8000元

商城网站建设因基本功能的需求不同费用上面也有很大的差别...

成都微信网站建设

手机微信网站建站3000元

手机微信网站开发、微信官网、微信商城网站...

建站知识

当前位置:首页 > 建站知识

Linux添加永久静态路由信息-创新互联

因为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
这样无论是重启主机还是重启网络服务路由信息都不会丢了。

文章标题:Linux添加永久静态路由信息-创新互联
文章来源:http://bjjierui.cn/article/ccidds.html

其他资讯