192.168.45.0 netmask 255.255.255.0 dev enp4s0 metric 3 永久添加静态路由 参照 /etc/init.d/network 中对 /etc/sysconfig/static-routes 是如何处理的 /etc/sysconfig/static-routes 文件不存在的话,创建一个即可 # Add non interface-specific static-routes. if [ -f /etc/sysconfig/static-routes ]; then if [ -x /sbin/route ]; then grep "^any " /etc/sysconfig/static-routes | while read ignore args ; do /sbin/route add -$args 如果添加一条静态路由的路由如下 route add -net 192.168.45.0 netmask 255.255.255.0 dev enp4s0 metric 3 那么,在 /etc/sysconfig/static-routes
/etc/sysconfig/static-routes : any net 192.168.3.0/24 gw 192.168.3.254 any net 10.250.228.128 netmask 255.255.255.192 gw 10.250.228.129 使用static-routes的方法是最好的。 static-routes文件又是什么呢,这个是network脚本执行时调用的一个文件,这个文件的放置在/etc/sysconfig目录下,在network脚本中的位置是: # Add non interface-specific if [ -f /etc/sysconfig/static-routes ]; then grep "^any" /etc/sysconfig/static-routes | while read ignore args ; do /sbin/route add -$args done fi 从这段脚本可以看到,这个就是添加静态路由的方法,static-routes的写法是
/etc/sysconfig/static-routes : (没有static-routes的话就手动建立一个这样的文件) any net 192.168.3.0/24 gw 192.168.3.254 any net 10.250.228.128 netmask 255.255.255.192 gw 10.250.228.129 如果在rc.local中添加路由会造成NFS无法自动挂载问题,所以使用static-routes static-routes. if [ -f /etc/sysconfig/static-routes ]; then grep “^any” /etc/sysconfig/static-routes | while read ignore args ; do /sbin/route add -$args done fi 从这段脚本可以看到,这个就是添加静态路由的方法,static-routes的写法是 这样看来,如果需要添加静态路由,使用static-routes文件要比使用rc.local好,而且当改变了网络配置,需要重启network脚本的时候,相应的静态路由是可以自动添加上的,但这时如果使用rc.local
/etc/rc.d/init.d/network中有这么几行: # Add non interface-specific static-routes. if [ -f /etc/sysconfig/static-routes ]; then grep “^any” /etc/sysconfig/static-routes | while read ignore args ; do /sbin/route add -$args done fi 也就是说,将静态路由加到/etc/sysconfig/static-routes 文件中就行了。 如加入: route add -net 11.1.1.0 netmask 255.255.255.0 gw 11.1.1.1 则static-routes的格式为 any net 11.1.1.0 netmask
/etc/sysconfig/static-routes : (没有static-routes的话就手动建立一个这样的文件) any net 192.168.3.0/24 gw 192.168.3.254 现在回到主题,关于static-routes的设置。 然后我们在看下static-routes这个文件的作用,根据网上的说法,static-routes其实在被network这个脚本调用的,打开这个脚本: /etc/rc.d/init.d/network 里面有写到: Add non interface-specific static-routes. if [ -f /etc/sysconfig/static-routes ]; then grep “^any” /etc/sysconfig/static-routes | while read ignore args ; do /sbin/route add – a r g s d o n e
重启网络验证 /etc/rc.d/init.d/network中有这么几行: Add non interface-specific static-routes. if [ -f /etc/sysconfig/static-routes ]; then grep “^any” /etc/sysconfig/static-routes | while read ignore args ; do /sbin/route add - $args done fi 也就是说,将静态路由加到/etc/sysconfig/static-routes 文件中就行了。 如加入: route add -net 11.1.1.0 netmask 255.255.255.0 gw 11.1.1.1 则static-routes的格式为 any net 11.1.1.0
2、在/etc/sysconfig/network里添加到末尾 方法:GATEWAY=gw-ip 或者GATEWAY=gw-dev 3、/etc/sysconfig/static-routes :any any net 10.250.228.128 netmask 255.255.255.192 gw 10.250.228.129 如果在rc.local中添加路由可能会造成NFS无法自动挂载问题,所以使用static-routes
route add -net 192.168.2.0/24 gw 192.168.2.254 注:如果在rc.local中添加路由会造成NFS无法自动挂载问题,可以使用/etc/sysconfig/static-routes /etc/sysconfig/static-routes : any net 192.168.3.0/24 gw 192.168.3.254 any net 10.30.27.128 netmask
/etc/sysconfig/static-routes any net 192.168.1.0/24 gw 192.168.1.1# 或者any net 192.168.1.0 netmask 255.255.255.0
1、在系统视图下执行delete static-routes all,可以一次删除所有静态路由,包括缺省路由 2、查看中低端路由器回收站中的文件 (1)中低端路由器提供回收站功能,在VRP1.74-0113
/24 gw 192.168.2.254 要永久生效的话要这样做: # echo "any net 192.168.2.0/24 gw 192.168.2.254" >>/etc/sysconfig/static-routes 192.168.2.2 gw 192.168.2.254 要永久生效的话要这样做: # echo "any host 192.168.2.2 gw 192.168.2.254 " >>/etc/sysconfig/static-routes
RHEL7官网文档没有提到 /etc/sysconfig/static-routes,经测试此文件已经无效; /etc/sysconfig/network 配置文件仅仅可以提供全局默认网关,语法同 Centos6
external-lb01 ~]# vim /etc/sysconfig/network GATEWAY=10.0.36.1 [root@external-lb01 ~]# vim /etc/sysconfig/static-routes
ip route-static IP_ADDR<X.X.X.X> Destination IP address default-preference Preference-value for IPv4 static-routes
route add -net 224.0.0.0 netmask 240.0.0.0 dev eth0]命令开通Linux组播服务 如果需要服务器启动时即开通组播,则需/etc/sysconfig/static-routes
/etc/sysconfig/static-routes文件为路由固化文件,但是linux系统一般不会自动生成,需要手动创建。
方法二: vi /etc/sysconfig/static-routes #默认不存在此文件 加入如下内容: any net 192.168.1.0/24 gw 192.168.1.1 提示:写到配置里
/etc/sysconfig/network-scipts/route-eth0 172.16.1.0/24 via 192.168.1.1 1.10.3.2 方法二 /etc/sysconfig/static-routes
net 172.16.0.0 netmask 255.255.0.0 gw 10.39.111.254 # 删除静态路由网关 } 静态路由{ vim /etc/sysconfig/static-routes
rc.local具有开机执行权限,该方法的缺陷是在/etc/init.d/network服务重启后添加的路由会消失 方法2:增加文件,并写入如下需要添加的路由信息:vim /etc/sysconfig/static-routes 192.168.72.2 any host 220.181.9.2 gw 192.168.72.2 该方法的原理为:/etc/init.d/network在启动时,会调用执行/etc/sysconfig/static-routes