ubuntu 静态路由 route 重启继续生效


   
和前文(Linux添加静态路由,重启继续生效: http://blog.sina.com.cn/s/blog_67be3b450101de43.html)提及的稍有不同,在ubuntu里面的额各种配置方式和主流的rhel系列不甚相同,比如说你找不到了你经常用到的/etc/sysconfig里面的众多文件,所以我们静态路由的配置难道也木有结果了?肯定有,在interfaces里面(/etc/network/interfaces),在ubuntu中,这个文件是一个很强大的文件(瞬间想起了板蓝根有木有!包治百病有木有!)

第一种方法和之前(参见前文)提到的方法相同,使用route命令,在此就不提了,感兴趣的话,可以翻看下前文

第二种方法无非是修改/etc/rc.local,只是要注意的一点是不要卸载 "exit0"的后面,这样就等于白写了

第三种就是修改interfaces文件了,写在文件的末尾,基本格式如下:
up route add -net 192.168.1.0 netmask 255.255.255.0 gw192.168.1.1
可以看到这个格式和route命令的唯一区别在于,在前面多了一个up
下面列出我的interface文件仅供参考,由于安全因素,这里的ip我都用xx替代了:
# This file describes the network interfaces available on yoursystem
# and how to activate them. For more information, seeinterfaces(5).

# The loopback network interface
auto lo
iface lo inet loopback

# The primary network interface
auto eth0
iface eth0 inet static
address xxx.xxx.xxx.xxx
netmask xxx.xxx.xxx.xxx
gateway xxx.xxx.xxx.xxx

auto eth0:0
iface eth0:0 inet static
address xxx.xxx.xxx.xxx
netmask xxx.xxx.xxx.xxx

#dns-nameservers 202.102.224.68 202.102.227.68
up route add -net xxx.xxx.xxx.xxx netmask xxx.xxx.xxx.xxx gwxxx.xxx.xxx.xxx eth0
up route add -net xxx.xxx.xxx.xxx netmask xxx.xxx.xxx.xxx gwxxx.xxx.xxx.xxx eth0
up route add -net xxx.xxx.xxx.xxx netmask xxx.xxx.xxx.xxx gwxxx.xxx.xxx.xxx eth0

你可能感兴趣的:(ubuntu 静态路由 route 重启继续生效)