修复Linux双网卡无法打通外网,配置默认路由

今天遇到本地虚机的怪问题,内网访问登录响应慢,而且登陆后无法使用外网进行yum安装。(虚机配置了双网卡进行内外网的连接)。

登陆后查看网卡状态,看着正常但无法ping通外网(114.114.114.114)

[root@OEL612C ~]# ifconfig -a
eth0      Link encap:Ethernet  HWaddr 08:00:27:E2:F6:9A  
          inet addr:10.0.2.15  Bcast:10.0.2.255  Mask:255.255.255.0
          inet6 addr: fe80::a00:27ff:fee2:f69a/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:3 errors:0 dropped:0 overruns:0 frame:0
          TX packets:13 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:790 (790.0 b)  TX bytes:1255 (1.2 KiB)

eth1      Link encap:Ethernet  HWaddr 08:00:27:88:EF:3B  
          inet addr:192.168.56.62  Bcast:192.168.56.255  Mask:255.255.255.0
          inet6 addr: fe80::a00:27ff:fe88:ef3b/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:71 errors:0 dropped:0 overruns:0 frame:0
          TX packets:73 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:8742 (8.5 KiB)  TX bytes:9271 (9.0 KiB)

lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:0 (0.0 b)  TX bytes:0 (0.0 b)

这种问题一般都是出在本地路由错乱上,一看路由果然有问题

[root@OEL612C ~]# route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         192.168.56.1    0.0.0.0         UG    0      0        0 eth1
10.0.2.0        0.0.0.0         255.255.255.0   U     0      0        0 eth0
169.254.0.0     0.0.0.0         255.255.0.0     U     1002   0        0 eth0
169.254.0.0     0.0.0.0         255.255.0.0     U     1003   0        0 eth1
192.168.56.0    0.0.0.0         255.255.255.0   U     0      0        0 eth1

内网网卡成默认路由了,用命令修改外网网卡为默认路由

[root@OEL612C ~]# route del -net 0.0.0.0
[root@OEL612C ~]# route add -net 0.0.0.0/0 gw 10.0.2.2 netmask 0.0.0.0 dev eth0
[root@OEL612C ~]# route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         10.0.2.2        0.0.0.0         UG    0      0        0 eth0
10.0.2.0        0.0.0.0         255.255.255.0   U     0      0        0 eth0
169.254.0.0     0.0.0.0         255.255.0.0     U     1002   0        0 eth0
169.254.0.0     0.0.0.0         255.255.0.0     U     1003   0        0 eth1
192.168.56.0    0.0.0.0         255.255.255.0   U     0      0        0 eth1

然后成功可以使用yum安装外网软件,内网也能正常工作

[root@OEL612C ~]# yum list gcc
Loaded plugins: ulninfo
Available Packages
gcc.x86_64                                          4.4.7-23.0.1.el6                                          public_ol6_latest

可是一重启,默认路由就又变回内网网卡了!
使用最简方法处理重启失效问题:往rc.local里写命令,注意文件要有运行权限。

echo "route del -net 0.0.0.0
route add -net 0.0.0.0/0 gw 10.0.2.2 netmask 0.0.0.0 dev eth0" >> /etc/rc.local
chmod +x /etc/rc.local

轻松搞定。

  • 2
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值