第一步,获取IP地址,可手动设置,也可以通过dhcp获取;dhcp可以在uboot传参数的时候加入,也可以在文件系统挂载的时候执行udhcpc;
uboot传参:setenv bootargs console=ttyS0,115200n8 noinitrd rw ip=dhcp
在文件系统中自动获取Ip地址后,会将DNS服务器地址写入/etc/resolv.conf中(可在/usr/share/udhcpc/default.script中指定),以下是default.script的内容:
#!/bin/sh
# udhcpc script edited by Tim Riker <Tim@Rikers.org>
RESOLV_CONF="/etc/resolv.conf"
[ -n "$1" ] || { echo "Error: should be called from udhcpc"; exit 1; }
NETMASK=""
[ -n "$subnet" ] && NETMASK="netmask $subnet"
BROADCAST="broadcast +"
[ -n "$broadcast" ] && BROADCAST="broadcast $broadcast"
case "$1" in
deconfig)
echo "Setting IP address 0.0.0.0 on $interface"
ifconfig $interface 0.0.0.0
;;
renew|bound)
echo "Setting IP address $ip on $interface"
ifconfig $interface $ip $NETMASK $BROADCAST
if [ -n "$router" ] ; then
echo "Deleting routers"
while route del default gw 0.0.0.0 dev $interface ; do
:
done
metric=0
for i in $router ; do
echo "Adding router $i"
route add default gw $i dev $interface metric $((metric++))
done
fi
echo "Recreating $RESOLV_CONF"
echo -n > $RESOLV_CONF-$$
[ -n "$domain" ] && echo "search $domain" >> $RESOLV_CONF-$$
for i in $dns ; do
echo " Adding DNS server $i"
echo "nameserver $i" >> $RESOLV_CONF-$$
done
mv $RESOLV_CONF-$$ $RESOLV_CONF
;;
esac
exit 0
如果不能获取到DNS服务器的地址,查看路由器的设置,以下是我的设置,指定了DNS服务器:
第二步、连接外网,首先在PC上找一个外网的IP地址,比方说www.baidu.com的IP,可以通过ping www.baidu.com获取,然后在板子上ping这个地址,如果能ping通,是个好消息,然后直接在板子上ping域名:ping www.baidu.com,如果不能ping通,可以尝试以下方法:
查看/etc/nsswitch.conf ,确定
hosts: files dns
如果以上方法不能解决问题,那就要根据个人情况不同来处理了,good luck!