阿里企业网站建设评估网站程序和空间区别
1、问题说明
A服务器有两张网卡,A1对应公网,A2对应私网,公网访问时,访问异常,内网访问服务则显示正常。
问题判断:数据包从公网进来时,路由无需判断,但数据包出去时,有两个网口皆可出去,如果出去的数据包走了默认路由,那就出不去。因此判断问题出现在系统的默认路由配置上。
-----数据包入---->--->--->----------|------公网-----------------------------------------------------<---<----<-----|------内网---------数据包出------------默认路由-----------
 
2、验证设想
[root@idszt-node001 ~]# route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         192.168.240.1   0.0.0.0         UG    104    0        0 ens1f1
0.0.0.0         113.98.244.1*1  0.0.0.0         UG    105    0        0 ens1f0
113.98.244.160  0.0.0.0         255.255.255.224 U     105    0        0 ens1f0
172.17.0.0      0.0.0.0         255.255.0.0     U     0      0        0 docker0
172.19.0.0      0.0.0.0         255.255.0.0     U     0      0        0 br-5bbdc4e99100
192.168.122.0   0.0.0.0         255.255.255.0   U     0      0        0 virbr0
192.168.240.0   0.0.0.0         255.255.255.0   U     104    0        0 ens1f1cd /etc/sysconfig/network-scripts
vi ifcfg-ens1f0
# 添加以下配置,设置ens1f0优先级在ens1f1之前
IPV4_ROUTE_METRIC="103"[root@idszt-node001 network-scripts]# ifdown enp2s0f0
用法:ifdown <设备名>
[root@idszt-node001 network-scripts]# ifdown ens1f0
成功断开设备 "ens1f0"。
[root@idszt-node001 network-scripts]# ifup ens1f0
连接已成功激活(D-Bus 活动路径:/org/freedesktop/NetworkManager/ActiveConnection/15)# 路由调整后
[root@idszt-node001 network-scripts]# route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         113.98.244.1*1  0.0.0.0         UG    103    0        0 ens1f0
0.0.0.0         192.168.240.1   0.0.0.0         UG    104    0        0 ens1f1
113.98.244.160  0.0.0.0         255.255.255.224 U     103    0        0 ens1f0
172.17.0.0      0.0.0.0         255.255.0.0     U     0      0        0 docker0
172.19.0.0      0.0.0.0         255.255.0.0     U     0      0        0 br-5bbdc4e99100
192.168.122.0   0.0.0.0         255.255.255.0   U     0      0        0 virbr0
192.168.240.0   0.0.0.0         255.255.255.0   U     104    0        0 ens1f1 
3、总结
将公网的网卡路由优先级设计为最高即可。
[root@idszt-node001 network-scripts]# ifconfig
ens1f0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500inet 113.98.244.1*0  netmask 255.255.255.224  broadcast 113.98.244.1*1inet6 fe80::d1bb:57a4:aa28:2dd9  prefixlen 64  scopeid 0x20<link>ether c4:b8:b4:b5:73:d1  txqueuelen 1000  (Ethernet)RX packets 506382  bytes 31938370 (30.4 MiB)RX errors 0  dropped 31937  overruns 0  frame 0TX packets 26388  bytes 2608732 (2.4 MiB)TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0device memory 0xab500000-ab5fffff
