【linux】[网络配置] 使用wpa_spplicant连接wifi,无法ping通网关,请问 这样的情况如何解决
配置环境:
- 操作环境:ubuntu
- 网络连接:USB无线网卡链接WIFI
- 连接方式:wpa_supplicant
- 监测方式:iwconfig
出现情况:
- wpa_supplicant连接成功
- 能ping通网关、路由中也能查看到主机连接上
- 但不能ping通外网
场合:家、公司
ubuntu设置情况如下:
wpa_supplicant连接wifi:
wpa_supplicant.conf设置如下
# cat /etc/wpa_supplicant.confctrl_interface=/var/run/wpa_supplicant GROUP=wheel
network={
ssid="TP-LINK_413"
#psk=""
psk=e69abb9b46dcbf8df67738a2eda466c54b3f12043e54157d58e097c3e19fa2e3
proto=RSN
key_mgmt=WPA-PSK
pairwise=CCMP TKIP
group=CCMP TKIP
}
连接wifi:
# wpa_supplicant -Dwext -iwlan0 -c/etc/wpa_supplicant.conf -dd -B
结果如下:
查看wifi信息
# iwconfig
结果如下:
至此wifi连接完毕,附上一张路由上的主机列表,划线的就是ubuntu,不过收包、发包太少了
设置网卡IP:
# cat /etc/network/interfaces# interfaces(5) file used by ifup(8) and ifdown(8)
auto lo
iface lo inet loopback
# auto eth0
# iface eth0 inet static
auto wlan0
iface wlan0 inet static
address 192.168.1.192
netmask 255.255.255.0
# home
gateway 192.168.1.253
# work
# gateway 192.168.1.1
network 192.168.1.253
设置DNS
# cat /etc/resolv.confnameserver 192.168.1.253
nameserver 8.8.8.8
重新启动网络服务
# service networking restart
结果如下:
启动wlan0:
# ifconfig wlan0 up# ifconfig
结果如下:
ping网关
# vi /etc/resolv.conf[email protected]:~# ping -c 4 192.168.1.253
PING 192.168.1.253 (192.168.1.253) 56(84) bytes of data.
64 bytes from 192.168.1.253: icmp_req=1 ttl=64 time=1.90 ms
64 bytes from 192.168.1.253: icmp_req=2 ttl=64 time=1.59 ms
64 bytes from 192.168.1.253: icmp_req=3 ttl=64 time=1.99 ms
64 bytes from 192.168.1.253: icmp_req=4 ttl=64 time=1.60 ms
--- 192.168.1.253 ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 3004ms
rtt min/avg/max/mdev = 1.597/1.776/1.999/0.178 ms
ping 外网,失败了
# ping -c 4 baidu.comPING baidu.com (123.125.114.144) 56(84) bytes of data.
rtw_set_ps_mode: Leave 802.11 power save
rtl8188e_set_FwPwrMode_cmd: Mode=0 SmartPS=2 UAPSD=0
rtw_set_ps_mode: Enter 802.11 power save
rtl8188e_set_FwPwrMode_cmd: Mode=1 SmartPS=2 UAPSD=0
--- baidu.com ping statistics ---
4 packets transmitted, 0 received, 100% packet loss, time 3008ms
查看route
请问如何解决?怎样能ping通外网
回答
不需要解决,已经连续成功啦(CONNECTED
)。加 -B
选项它才会自动 fork 到后台去。
现在你可以用 dhcpcd
或者 dhclient
程序来获取动态 IP 地址了,然后就可以上网了。
以上是 【linux】[网络配置] 使用wpa_spplicant连接wifi,无法ping通网关,请问 这样的情况如何解决 的全部内容, 来源链接: utcz.com/a/85323.html