关于Redhat下静态路由添加的几种方法

来源:互联网 发布:mac上app store打不开 编辑:程序博客网 时间:2024/05/28 15:37

在网络上,常见有三种办法:

1、将路由添加命令写入 /etc/rc.local 文件中,如:

[root@mu01 ~]# cat /etc/rc.local 
#!/bin/sh
#
# This script will be executed *after* all the other init scripts.
# You can put your own initialization stuff in here if you don't
# want to do the full Sys V style init stuff.


touch /var/lock/subsys/local

route add -net 192.168.3.0/24 gw 192.168.3.254


2、将静态路由添加的命令写入profile文件中,如:

[root@mu01 ~]# cat /etc/profile
# /etc/profile

route add -net 192.168.3.0/24 gw 192.168.3.254


3、新建/etc/sysconfig/static-routes文件,修改此配置文件,如:
[root@mu01 ~]# cat /etc/sysconfig/static-routes
any net 192.168.3.0/24 gw 192.168.3.254


其中前两种方法,也许配置后重启操作系统也可以生效,但在操作系统运行时重启网络服务,静态路由就会丢失,为什么第三种方法添加的静态路由即使重启网络服务也不会丢失:

[root@mu01 ~]# cat /etc/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    
***

检查配置文件得知,脚本会检测static-routes文件是否存在,存在的情况下会添加到系统中,所以修改静态路由应使用第三种方法。

0 0
原创粉丝点击