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

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

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文件是否存在,存在的情况下会添加到系统中,所以修改静态路由应使用第三种方法。

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值