看脚本很重要 -记为Linux加路由表文件

之前给机器加route都是很山寨的把命令写在 /etc/rc.d/rc.local 里,简单是简单但重启network就失效了。

今天终于受不了自己的这种做法了,搜了一下,没有找到……干脆开始看 /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

 

编辑 /etc/sysconfig/static-routes

any net 192.168.0.0/24 gw 192.168.80.1

注意一定要用 any 开头。

留下评论

您的电子邮箱地址不会被公开。 必填项已用*标注