[iyunv@template ~]# grep -n '# Add non interface-specific static-routes.' /etc/init.d/network
138: # Add non interface-specific static-routes.
[iyunv@template ~]#
2. vim打开/etc/init.d/network文件找到刚才查找到行
[iyunv@template ~]# vi /etc/init.d/network
打开之后
137
138 # Add non interface-specific static-routes.
139 if [ -f /etc/sysconfig/static-routes ]; then
140 grep "^any" /etc/sysconfig/static-routes | while read ignore args ; do
141 /sbin/route add -$args
142 done
143 fi
144 # Add non interface-specific static arp entries.
:set nu
将第140和141行改为
#Add noninterface-specific static-routes.
if [ -f/etc/sysconfig/static-routes ]; then
egrep "^1" /etc/sysconfig/static-routes | while read ignore args ;
do
/sbin/route $args
done
fi
这样/sbin/route命令后面就可以接任何参数 , 不用只接add
在 /etc/sysconfig/目录下建立static-routes,并添加命令
[iyunv@backup ~]# vi /etc/sysconfig/static-routes
写入
1 add default gw 10.0.0.254
1 del default gw 172.16.1.254
do
/sbin/route $args
echo 1111111111111##############
done
让每次执行route命令时输出一个标识符 好通知已经执行
5. 最后执行验证
[iyunv@backup ~]# /etc/init.d/network restart
Shutting down interface eth0: [ OK ]
Shutting down interface eth1: [ OK ]
Shutting down loopback interface: [ OK ]
Bringing up loopback interface: [ OK ]
Bringing up interface eth0: Determining if ip address 10.0.0.41 is already in use for device eth0...
[ OK ]
Bringing up interface eth1: Determining if ip address 172.16.1.41 is already in use for device eth1...
[ OK ]
1111111111111##############
1111111111111##############
[iyunv@backup ~]#
查看路由表
[iyunv@backup ~]# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
10.0.0.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
172.16.1.0 0.0.0.0 255.255.255.0 U 0 0 0 eth1
169.254.0.0 0.0.0.0 255.255.0.0 U 1002 0 0 eth0
169.254.0.0 0.0.0.0 255.255.0.0 U 1003 0 0 eth1
0.0.0.0 10.0.0.254 0.0.0.0 UG 0 0 0 eth0
[iyunv@backup ~]#