情景:
电脑更换连接的无线网络后使用ping命令,一直无法正常访问外面的链接。
解决方案:
导致原因:之前电脑一直在网段为1的局域网使用,对应的网关是GATEWAY=192.168.1.1,而现在的网络段是2.
步骤:
使用ifconfig查看当前的网卡信息
[root@cqs network-scripts]# ifconfig
eth0 Link encap:Ethernet HWaddr 00:0C:29:CF:DB:D0
inet addr:192.168.2.204 Bcast:192.168.2.255 Mask:255.255.255.0
inet6 addr: fe80::20c:29ff:fecf:dbd0/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:557 errors:0 dropped:0 overruns:0 frame:0
TX packets:388 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:49499 (48.3 KiB) TX bytes:44666 (43.6 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:368 errors:0 dropped:0 overruns:0 frame:0
TX packets:368 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:116361 (113.6 KiB) TX bytes:116361 (113.6 KiB)
修改对应的配置:
[root@cqs ~]# cd /etc/sysconfig/network-scripts/
[root@cqs network-scripts]# ls
ifcfg-eth0 ifdown-eth ifdown-post ifdown-tunnel ifup-eth ifup-plip ifup-routes init.ipv6-global
ifcfg-lo ifdown-ippp ifdown-ppp ifup ifup-ippp ifup-plusb ifup-sit net.hotplug
ifdown ifdown-ipv6 ifdown-routes ifup-aliases ifup-ipv6 ifup-post ifup-tunnel network-functions
ifdown-bnep ifdown-isdn ifdown-sit ifup-bnep ifup-isdn ifup-ppp ifup-wireless network-functions-ipv6
[root@cqs network-scripts]# vim ifcfg-eth0
DEVICE=eth0
TYPE=Ethernet
UUID=b29165ed-1590-4dcd-9038-45c8d09d9762
ONBOOT=yes
NM_CONTROLLED=yes
BOOTPROTO=dhcp
IPV4_FAILURE_FATAL=yes
IPV6INIT=no
NAME="System eth0"
HWADDR=00:0C:29:CF:DB:D0
PEERDNS=yes
PEERROUTES=yes
LAST_CONNECT=1442250556
GATEWAY=192.168.2.1 #原来为GATEWAY=192.168.1.1
按wq保存退出,重启网络服务
[root@cqs network-scripts]# service network restart
正在关闭接口 eth0: [确定]
关闭环回接口: [确定]
弹出环回接口: [确定]
弹出界面 eth0:
正在决定 eth0 的 IP 信息...完成。 [确定]
使用ping命令测试
[root@cqs network-scripts]# ping www.baidu.com
PING www.baidu.com (14.215.177.37) 56(84) bytes of data.
64 bytes from 14.215.177.37: icmp_seq=1 ttl=55 time=6.33 ms
64 bytes from 14.215.177.37: icmp_seq=2 ttl=55 time=7.44 ms
--- www.baidu.com ping statistics ---
11 packets transmitted, 11 received, 0% packet loss, time 10152ms
rtt min/avg/max/mdev = 5.886/11.123/21.355/4.534 ms