问题由这篇文章引出:AM335x添加WiFi模块WILC1000_pingis58的博客-CSDN博客。
板子硬件状态:有一个有线网口,一个WIFI模块。从NFS系统启动。WIFI驱动加载成功后,连接手机AP成功,IP地址已获成功。如下:
wlan0 Link encap:Ethernet HWaddr 60:8A:10:B6:68:60
inet addr:192.168.192.120 Bcast:192.168.192.255 Mask:255.255.255.0
inet6 addr: fe80::628a:10ff:feb6:6860/64 Scope:Link
inet6 addr: 240e:479:4a00:ce1a:628a:10ff:feb6:6860/64 Scope:Global
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:11 errors:0 dropped:0 overruns:0 frame:0
TX packets:97 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:2164 (2.1 KiB) TX bytes:15352 (14.9 KiB)
ping www.baidu.com 或指定网卡命令
ping -I wlan0 www.baidu.com 无法成功,没有响应。
root@am335x-evm:~# ping -I wlan0 www.baidu.com
PING www.baidu.com (180.101.49.12): 56 data bytes
后来有套板子,NFS加载后,是可以直接ping 通外网的。所以一直查文件系统上是否有差异。
网上有说法查看DNS配置文件 /etc/resolv.conf
nameserver 192.168.192.215
nameserver 240e:479:4a00:ce1a::87
跟另一台可用的板配置一模样。
包括网卡的配置文件 。
针对system V的配置文件 ,这个配置文件重新配置网络的指令:/etc/init.d/networking restart
# /etc/network/interfaces -- configuration file for ifup(8), ifdown(8)
# The loopback interface
auto lo
iface lo inet loopback
# Wireless interfaces
iface wlan0 inet dhcp
wireless_mode managed
wireless_essid any
wpa-driver wext
wpa-conf /etc/wpa_supplicant.conf
iface tiwlan0 inet dhcp
wireless_mode managed
wireless_essid any
iface atml0 inet dhcp
# Wired or wireless interfaces
#auto eth0
#iface eth0 inet dhcp
# pre-up /bin/grep -v -e "ip=[0-9]\+\.[0-9]\+\.[0-9]\+\.[0-9]\+" /proc/cmdline > /dev/null
# udhcpc_opts -R -b
auto eth0
iface eth0 inet static
address 192.168.1.99
netmask 255.255.254.0
gateway 192.168.1.1
iface eth1 inet dhcp
# Ethernet/RNDIS gadget (g_ether)
# ... or on host side, usbnet and random hwaddr
auto usb0
iface usb0 inet static
address 192.168.7.2
netmask 255.255.255.252
# Bluetooth networking
iface bnep0 inet dhcp
从上面看出,已经有DHCP功能了。重启启动服务也没用。
针对systemD的网络配置文件
/etc/systemd/network/30-wlan.network
[Match]
Name=wlan*
[Network]
DHCP=yes
针对WIFI的网卡,也是DHCP开启,配置完全一样。
重新启动服务:systemctl restart systemd-networkd.service 。也是无效的。
后来baidu搜索一下,ARM LINUX无法 ping外网的问题:基本都是描述,在手工设置IP的时候,没有设置网关,手动添加网卡即可。而调用DHCP动态获取IP后,就可以使用。
route指令查看网关:
root@am335x-evm:~# route
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
default 192.168.6.1 0.0.0.0 UG 0 0 0 eth0
default 192.168.192.215 0.0.0.0 UG 1024 0 0 wlan0
192.168.6.0 * 255.255.255.0 U 0 0 0 eth0
192.168.192.0 * 255.255.255.0 U 0 0 0 wlan0
192.168.192.215 * 255.255.255.255 UH 1024 0 0 wlan0
从状态来看,网关是有的。即wlan0对应的网关是 192.168.192.215,即手机的IP地址。
而且ping 网关,ping 192.168.192.215也是通的。后来就没有怀疑网关的问题。
再udhcpc 指令,重新dhcp获取IP地址,网关。
root@am335x-evm:~# udhcpc -i wlan0
udhcpc: started, v1.29.3
Failed to revert interface configuration: Link wlan0 is managed.
udhcpc: sending discover
udhcpc: sending select for 192.168.192.121
udhcpc: lease of 192.168.192.121 obtained, lease time 3599
/etc/udhcpc.d/50default: Adding DNS 192.168.192.215
The specified interface wlan0 is managed by systemd-networkd. Operation refused.
Please configure DNS settings for systemd-networkd managed interfaces directly in their .network files.
root@am335x-evm:~# route
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
default 192.168.6.1 0.0.0.0 UG 0 0 0 eth0
default 192.168.192.215 0.0.0.0 UG 10 0 0 wlan0
default 192.168.192.215 0.0.0.0 UG 1024 0 0 wlan0
192.168.6.0 * 255.255.255.0 U 0 0 0 eth0
192.168.192.0 * 255.255.255.0 U 0 0 0 wlan0
192.168.192.215 * 255.255.255.255 UH 1024 0 0 wlan0
从上面可以看出,udhcpc已经成功,且额外添加了一个网关。但ping www.baidu.com依然不通。没有办法情况下,按照网上尝试,手动添加网关后,居然可以ping 通外网了。如下:
root@am335x-evm:~# route add default gw 192.168.192.215
root@am335x-evm:~# ping www.baidu.com
PING www.baidu.com (180.101.49.11): 56 data bytes
64 bytes from 180.101.49.11: seq=0 ttl=52 time=27.118 ms
64 bytes from 180.101.49.11: seq=1 ttl=52 time=35.011 ms
64 bytes from 180.101.49.11: seq=2 ttl=52 time=44.327 ms
^C
--- www.baidu.com ping statistics ---
3 packets transmitted, 3 packets received, 0% packet loss
round-trip min/avg/max = 27.118/35.485/44.327 ms
接着对比网关状态:
root@am335x-evm:~# route
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
default 192.168.192.215 0.0.0.0 UG 0 0 0 wlan0
default 192.168.6.1 0.0.0.0 UG 0 0 0 eth0
default 192.168.192.215 0.0.0.0 UG 10 0 0 wlan0
default 192.168.192.215 0.0.0.0 UG 1024 0 0 wlan0
192.168.6.0 * 255.255.255.0 U 0 0 0 eth0
192.168.192.0 * 255.255.255.0 U 0 0 0 wlan0
192.168.192.215 * 255.255.255.255 UH 1024 0 0 wlan0
从上面可以看出,在第一个网关的位置,添加了个正确的网关。由此猜想,可能网关要匹配到第一个网关,要是第一个网关不正确,就无法ping通外网。而NFS启动时,有线网的网关是192.168.6.1。后来wifi通过udhcpc获取的IP对应的网关,添加在网络列表后面。所以一直ping不了外网。而手动route添加网关,在网络列表前添加了,就可以成功了。
这时返回到可以正常使用的AM335板子验证,发现route后,第一个网关就是 wifi ap 的网络IP。所以就解释通了这个问题。因为那块板子,NFS系统挂载,在uboot阶段设置网关的时候,网关和IP地址不匹配,没设置对,所以就没有生效。
知道问题所在了。虽然变相的可以使用。没有从根本上解决,如果在udhcpc自动获取IP时,对应的网关信息能直接可用,这个问题目前还无法解决。
udhcpc 脚本的借鉴资料:留作后续学习,可能有助于解决这个问题。