linux中网关设置对网络连接的影响
001、
[root@PC1 network-scripts]# cat ifcfg-ens32 TYPE="Ethernet" PROXY_METHOD="none" BROWSER_ONLY="no" BOOTPROTO="static" DEFROUTE="yes" IPV4_FAILURE_FATAL="no" IPV6INIT="yes" IPV6_AUTOCONF="yes" IPV6_DEFROUTE="yes" IPV6_FAILURE_FATAL="no" IPV6_ADDR_GEN_MODE="stable-privacy" NAME="ens32" UUID="829f59a3-6c84-4f74-8265-0abfd9f63178" DEVICE="ens32" ONBOOT="yes" IPADDR=192.168.71.130 GATEWAY=192.168.71.1 ## 网关1 NETMASK=255.255.255.0 DNS1=8.8.8.8 DNS2=114.114.114.114
[root@PC1 network-scripts]# systemctl restart network ## 重启网络服务 [root@PC1 network-scripts]# ping -c 3 www.baidu.com ## 测试网络连通性 ping: www.baidu.com: Name or service not known
002、修改网关,测试网络
[root@PC1 network-scripts]# cat ifcfg-ens32 TYPE="Ethernet" PROXY_METHOD="none" BROWSER_ONLY="no" BOOTPROTO="static" DEFROUTE="yes" IPV4_FAILURE_FATAL="no" IPV6INIT="yes" IPV6_AUTOCONF="yes" IPV6_DEFROUTE="yes" IPV6_FAILURE_FATAL="no" IPV6_ADDR_GEN_MODE="stable-privacy" NAME="ens32" UUID="829f59a3-6c84-4f74-8265-0abfd9f63178" DEVICE="ens32" ONBOOT="yes" IPADDR=192.168.71.130 GATEWAY=192.168.71.2 ## 调整后的网关2 NETMASK=255.255.255.0 DNS1=8.8.8.8 DNS2=114.114.114.114
[root@PC1 network-scripts]# systemctl restart network ## 重启网络服务 [root@PC1 network-scripts]# ping -c 3 www.baidu.com ## 测试网络联通性, 可以联通 PING www.a.shifen.com (110.242.68.4) 56(84) bytes of data. 64 bytes from 110.242.68.4 (110.242.68.4): icmp_seq=1 ttl=128 time=12.8 ms 64 bytes from 110.242.68.4 (110.242.68.4): icmp_seq=2 ttl=128 time=11.7 ms 64 bytes from 110.242.68.4 (110.242.68.4): icmp_seq=3 ttl=128 time=11.9 ms --- www.a.shifen.com ping statistics --- 3 packets transmitted, 3 received, 0% packet loss, time 2005ms rtt min/avg/max/mdev = 11.756/12.198/12.875/0.502 ms