配置了多块网卡后,需要指定数据包由哪块网卡发送,否则可能无法访问内网,这就要用到静态路由了。

  配置静态路由有多种方式:

  1、修改 /etc/rc.local 文件,这样每次重启后就会自动添加,如:

    echo "route add default gw 10.0.2.2 dev eth0" >> /etc/rc.local

    echo "route add -net 192.168.100.0 netmask 255.255.255.0 dev eth1" >> /etc/rc.local

    此方法有个弊端:使用 service network restart 重启网络后,静态路由失效

  2、[推荐]查看网络启动脚本 : /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
if [ -f /etc/sysconfig/static-routes ] , -f 意思是存在 /etc/sysconfig/static-routes 且为普通文件,则执行下面的语句
  grep "^any" /etc/sysconfig/static-routes 将 any 开头的行取出
  while read ignore args 执行后 ignore="any" args=其他
  /sbin/route add -$args 添加路由的命令   现在可以加入我们自己的静态路由,查看 static-routes 格式如下:     any net 192.168.100.0 netmask 255.255.255.0 dev eth1
    any net 0.0.0.0 netmask 0.0.0.0 gw 10.0.2.2 dev eth0   然后重启网络,路由还在:
[root@centos1 ~]# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
192.168.100.0 0.0.0.0 255.255.255.0 U eth1
10.0.2.0 0.0.0.0 255.255.255.0 U eth0
169.254.0.0 0.0.0.0 255.255.0.0 U eth0
169.254.0.0 0.0.0.0 255.255.0.0 U eth1
0.0.0.0 10.0.2.2 0.0.0.0 UG eth0

  

最新文章

  1. MlLib--逻辑回归笔记
  2. [mobi文件格式详细介绍一]_[资料篇]
  3. VNC server grey screen under ubuntu 14.04
  4. LintCode "k Sum" !!
  5. LINUX系统备份
  6. 构建ASP.NET MVC4+EF5+EasyUI+Unity2.x注入的后台管理系统(30)-本地化(多语言)
  7. sql server sys.object表字段说明
  8. 小程序bindtap和cachetap的区别
  9. openstack网络基础:网络叠加模式VLAN、VxLAN、GRE
  10. 清北澡堂 Day2 下午 一些比较重要的数论知识整理
  11. centos7 设置nginx和php开机自启动
  12. poj2886(线段树求序列第k小)
  13. linuxDNS配置
  14. Mysql Window 解压版 忘记密码
  15. Echarts地图展示及属性分析
  16. 《Gradle权威指南》--Android Gradle多项目构建
  17. spring整合ssmXML版
  18. webpack打包jQuery,jQuery未定义
  19. mysql5.7 安装错误解决
  20. VS2013 生成事件,删除不必要的DLL

热门文章

  1. CentOS7.5 部署Ceph luminous
  2. maven cmd 命令
  3. Python学习日记(二十二) 初识面向对象
  4. 微信小程序 wxml 中使用 js函数
  5. 怎么查看二进制文件内容?linux下nm命令告诉你!
  6. java连接mysql数据库时的时区设置问题(time_zone)
  7. spark-submit python egg 解决三方件依赖问题
  8. 关于jquery的事件委托-bind,live,delegate,on的区别发展
  9. 3-html块-语义化的标签
  10. 【贪心】Moving Tables POJ 1083