Linux 系统添加永久静态路由


原文:Linux 系统添加永久静态路由

linux下面可以使用route add命令添加静态路由,但是在网卡重启、系统重启后会丢失,添加永久静态路由的方法如下:

在/etc/sysconfig/目录下创建静态路由文件 static-routes,编辑内容如下:

vim /etc/sysconfig/static-routes

  1. any net 172.16.1.0 netmask 255.255.255.0 gw 192.168.0.254
  2. any net 172.16.2.0 netmask 255.255.255.0 gw 192.168.1.254

其中172.16.1.0和172.16.2.0分别为目标网络,后面跟掩码,gw后面跟下一跳地址。

其实以上文件也是利用route命令在添加路由,在/etc/init.d/network 里面有这么几行:

  1. # Add non interface-specific static-routes.
  2. if [ -f /etc/sysconfig/static-routes ]; then
  3. grep "^any" /etc/sysconfig/static-routes | while read ignore args ; do
  4. /sbin/route add -$args
  5. done
  6. fi

local 2022年8月12日 11:34 收藏文档