因为 /etc/init.d/network 脚本中有检测路由模块
[root@localhost ysw]# cat /etc/init.d/network | grep -A3 static-routes
# 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
[root@localhost ysw]#
因此创建/etc/sysconfig/static-routes文件即可
[root@localhost ysw]# cat /etc/sysconfig/static-routes
any net 172.17.2.0/24 gw 172.17.2.129
[root@localhost ysw]#
重启网卡生效
[root@localhost ysw~]# service network restart
路由将在每次重启网卡服务的时候写入,不建议将路由写在/etc/rc.local中,因为那样必须重启主机才会生效。
网友评论