BCLinux系统路由冲突无法访问外网的解决方法

影响版本
 
   BigCloud Enterprise Linux 6.5 64bit
 
   BigCloud Enterprise Linux 7.1 64bit
 
解决方案:
 
   BCLinux6 默认未安装NetworkManager,使用DHCP方式,可以在if-eth*配置文件中添加METRIC=xx参数(注意:每个if-eth配置文件均需添加此参数),并重启网络即可生效,默认值越小,路由选择越优先,用户预期想使用的那个路由的METRIC值必须是最小的。
 
   BCLinux7 安装NetworkManager,使用DHCP方式,可以在if-eth*配置文件中添加IPV4_ROUTE_METRIC=xx参数(注意:每个if-eth配置文件均需添加此参数),并重启网络即可生效,默认值越小,路由选择越优先,用户预期想使用的那个路由的IPV4_ROUTE_METRIC值必须是最小的。
 
问题分析:
 
1. BigCloud Enterprise Linux 6.5 64bit
 
默认未安装NetworkManager
 
默认采用DHCP方式获取网卡信息
 
创建时默认一个网卡:
 
名称  port163709
 
编码  5ea1ee92-c7ac-42f8-9e99-b84dac032c26
 
关联腾讯云服务器   TestNetRoute
 
IP地址    10.112.137.225
 
公网IP    112.35.30.85
 
进入腾讯云服务器:
 
[root@testnetroute ~]#  ip a s
 
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue state UNKNOWN
 
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
 
    inet 127.0.0.1/8 scope host lo
 
    inet6 ::1/128 scope host
 
       valid_lft forever preferred_lft forever
 
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
 
    link/ether fa:16:3e:87:44:46 brd ff:ff:ff:ff:ff:ff
 
    inet 10.112.137.225/22 brd 10.112.139.255 scope global eth0
 
    inet6 fe80::f816:3eff:fe87:4446/64 scope link
 
       valid_lft forever preferred_lft forever
 
 
 
[root@testnetroute ~]#  ip route show
 
10.112.136.0/22 dev eth0  proto kernel  scope link  src 10.112.137.225
 
169.254.0.0/16 dev eth0  scope link  metric 1002
 
default via 10.112.136.1 dev eth0
 
此种情况下,用户通过云平台上提供的接口,新增了一个网卡,
 
名称  wyytest01
 
编码  4087a96b-6d38-4253-a2a9-f32c6fd64ce5
 
关联腾讯云服务器   TestNetRoute
 
IP地址    192.168.138.4
 
公网IP 
 
进入腾讯云服务器,查看其信息:
 
[root@testnetroute ~]#  ip a s
 
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue state UNKNOWN
 
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
 
    inet 127.0.0.1/8 scope host lo
 
    inet6 ::1/128 scope host
 
       valid_lft forever preferred_lft forever
 
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
 
    link/ether fa:16:3e:87:44:46 brd ff:ff:ff:ff:ff:ff
 
    inet 10.112.137.225/22 brd 10.112.139.255 scope global eth0
 
    inet6 fe80::f816:3eff:fe87:4446/64 scope link
 
       valid_lft forever preferred_lft forever
 
3: eth1: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN qlen 1000
 
    link/ether fa:16:3e:6f:67:6b brd ff:ff:ff:ff:ff:ff
 
 
 
[root@testnetroute ~]#  ip route show
 
10.112.136.0/22 dev eth0  proto kernel  scope link  src 10.112.137.225
 
169.254.0.0/16 dev eth0  scope link  metric 1002
 
default via 10.112.136.1 dev eth0
 
由于el6系统中无NetworkManager,因此可以看到,eth1没有获取到ip,手动配置网络文件:
 
[root@testnetroute ~]#  cd /etc/sysconfig/network-scripts/
 
[root@testnetroute /etc/sysconfig/network-scripts]#  cp ifcfg-eth0 ifcfg-eth1
 
[root@testnetroute /etc/sysconfig/network-scripts]#  vi ifcfg-eth1  #修改文件如下
 
DEVICE=eth1
 
TYPE=Ethernet
 
ONBOOT=yes
 
BOOTPROTO=dhcp
 
重启网络:
 
[root@testnetroute ~]#  ifup eth1
 
发现默认路由变为了:
 
[root@testnetroute ~]#  ip route show
 
192.168.138.0/24 dev eth1  proto kernel  scope link  src 192.168.138.4
 
10.112.136.0/22 dev eth0  proto kernel  scope link  src 10.112.137.225
 
169.254.0.0/16 dev eth0  scope link  metric 1002
 
169.254.0.0/16 dev eth1  scope link  metric 1003
 
default via 192.168.138.1 dev eth1
 
此时,为了使默认路由仍走10.112.136.1,可为2个网卡分别配置METRIC参数,配置如下:
 
[root@testnetroute /etc/sysconfig/network-scripts]#  cat ifcfg-eth0
 
DEVICE=eth0
 
TYPE=Ethernet
 
ONBOOT=yes
 
BOOTPROTO=dhcp
 
METRIC=10       #增加此行如左
 
[root@testnetroute /etc/sysconfig/network-scripts]#  cat ifcfg-eth1
 
DEVICE=eth1
 
TYPE=Ethernet
 
ONBOOT=yes
 
BOOTPROTO=dhcp
 
METRIC=20       #增加此行如左
 
重启网络:
 
[root@testnetroute ~]#  service network restart
 
重新查看路由:
 
[root@testnetroute ~]#  ip route show
 
192.168.138.0/24 dev eth1  proto kernel  scope link  src 192.168.138.4
 
10.112.136.0/22 dev eth0  proto kernel  scope link  src 10.112.137.225
 
169.254.0.0/16 dev eth0  scope link  metric 1002
 
169.254.0.0/16 dev eth1  scope link  metric 1003
 
default via 10.112.136.1 dev eth0  metric 10
 
default via 192.168.138.1 dev eth1  metric 20
 
测试访问8.8.8.8所走的默认路由:
 
[root@testnetroute ~]#  ip route get 8.8.8.8
 
8.8.8.8 via 10.112.136.1 dev eth0  src 10.112.137.225
 
    cache  mtu 1500 advmss 1460 hoplimit 64
 
更改默认路由成功。
 
2. BigCloud Enterprise Linux 7.1 64bit
 
默认安装NetworkManager
 
默认采用DHCP方式获取网卡信息
 
创建时默认一个网卡:
 
名称  port499273
 
编码  70ed40b5-ba0c-4dcd-88e5-c10df1efb371
 
关联腾讯云服务器   TestNetRoute7
 
IP地址    10.112.137.226
 
公网IP    112.35.30.90
 
进入腾讯云服务器:
 
[root@testnetroute7 ~]#  ip a s
 
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN
 
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
 
    inet 127.0.0.1/8 scope host lo
 
       valid_lft forever preferred_lft forever
 
    inet6 ::1/128 scope host
 
       valid_lft forever preferred_lft forever
 
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
 
    link/ether fa:16:3e:8d:8e:61 brd ff:ff:ff:ff:ff:ff
 
    inet 10.112.137.226/22 brd 10.112.139.255 scope global eth0
 
       valid_lft forever preferred_lft forever
 
    inet6 fe80::f816:3eff:fe8d:8e61/64 scope link
 
       valid_lft forever preferred_lft forever
 
[root@testnetroute7 ~]#  ip route show
 
default via 10.112.136.1 dev eth0  proto static  metric 100
 
10.112.136.0/22 dev eth0  proto kernel  scope link  src 10.112.137.226  metric 100
 
此种情况下,用户通过云平台上提供的接口,新增了一个网卡,
 
名称  wyytest02
 
编码  90bdcbc2-2729-486f-a58b-e3601db27f61
 
关联腾讯云服务器   TestNetRoute7
 
IP地址    192.168.137.4
 
公网IP 
 
进入腾讯云服务器,查看网络信息(由于el7系统中默认安装了NetworkManager,因此eth1自动获取到ip:192.168.137.4):
 
[root@testnetroute7 ~]#  ip a s
 
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN
 
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
 
    inet 127.0.0.1/8 scope host lo
 
       valid_lft forever preferred_lft forever
 
    inet6 ::1/128 scope host
 
       valid_lft forever preferred_lft forever
 
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
 
    link/ether fa:16:3e:8d:8e:61 brd ff:ff:ff:ff:ff:ff
 
    inet 10.112.137.226/22 brd 10.112.139.255 scope global eth0
 
       valid_lft forever preferred_lft forever
 
    inet6 fe80::f816:3eff:fe8d:8e61/64 scope link
 
       valid_lft forever preferred_lft forever
 
3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
 
    link/ether fa:16:3e:dd:4a:8e brd ff:ff:ff:ff:ff:ff
 
    inet 192.168.137.4/24 brd 192.168.137.255 scope global eth1
 
       valid_lft forever preferred_lft forever
 
    inet6 fe80::f816:3eff:fedd:4a8e/64 scope link
 
       valid_lft forever preferred_lft forever
 
查看路由状态:
 
[root@testnetroute7 ~]#  ip route show
 
default via 10.112.136.1 dev eth0  proto static  metric 100
 
default via 192.168.137.1 dev eth1  proto static  metric 101
 
10.112.136.0/22 dev eth0  proto kernel  scope link  src 10.112.137.226  metric 100
 
192.168.137.0/24 dev eth1  proto kernel  scope link  src 192.168.137.4  metric 100
 
测试系统访问8.8.8.8所走默认路由:
 
[root@testnetroute7 ~]#  ip route get 8.8.8.8
 
8.8.8.8 via 10.112.136.1 dev eth0  src 10.112.137.226
 
    cache
 
若当前路由并不是想要的,则用户可以自行更改(假设想使用192.168.137.1):
 
[root@testnetroute7 /etc/sysconfig/network-scripts]#  cat ifcfg-eth0
 
NAME=eth0
 
TYPE=Ethernet
 
BOOTPROTO=dhcp
 
DEVICE=eth0
 
ONBOOT=yes
 
IPV4_ROUTE_METRIC=20    #添加内容如左
 
 
 
[root@testnetroute7 /etc/sysconfig/network-scripts]#  cat ifcfg-eth1
 
NAME=eth1
 
TYPE=Ethernet
 
BOOTPROTO=dhcp
 
DEVICE=eth1
 
ONBOOT=yes
 
IPV4_ROUTE_METRIC=10    #添加内容如左
 
重启服务:
 
[root@testnetroute7 ~]#  systemctl restart network
 
查看路由状态:
 
[root@testnetroute7 ~]#  ip route show
 
default via 192.168.137.1 dev eth1  proto static  metric 10
 
default via 10.112.136.1 dev eth0  proto static  metric 20
 
10.112.136.0/22 dev eth0  proto kernel  scope link  src 10.112.137.226  metric 20
 
192.168.137.0/24 dev eth1  proto kernel  scope link  src 192.168.137.4  metric 10
 
测试系统访问8.8.8.8所走默认路由:
 
[root@testnetroute7 ~]#  ip route get 8.8.8.8
 
8.8.8.8 via 192.168.137.1 dev eth0  src 192.168.137.4
 
    cache
 
更改默认路由成功。

标签