linux 添加主机静态路由

因为 /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中,因为那样必须重启主机才会生效。

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容