sendto: Network is unreachable问题的解决

在用busybox生成根文件系统之后,进入系统ping外网是不能用的,因此需要修改一下几个文件:

配置ip为固定,并且开机自动启动网卡:

在/etc/init.d/rcS中添加一下内容:

#网络开机自启动设置
 ifconfig eth0 up
 #udhcpc -i eth0
 ifconfig eth0 192.168.1.251 netmask 255.255.255.0

此时,ping内网的ip是可以ping通的但是外网的还是不能,ping外网会出现“sendto: Network is unreachable”的问题。首先用route命令查看下路由表:

#route
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
192.168.1.0     *               255.255.255.0   U     0      0        0 eth0

可以看到是由于网关没有配置(gateway),

配置网关,并且开机自动启动:

在/etc/init.d/rcS中添加一下内容:

route add default gw 192.168.1.1

在此查看路由表:

Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
default         192.168.1.1     0.0.0.0         UG    0      0        0 eth0
192.168.1.0     *               255.255.255.0   U     0      0        0 eth0

ping一下外网发现还是不通,这是我们要添加一下默认的DNS。

配置DNS解析:

在/etc目录下新建一个resolv.conf配置文件设置内容如下:

#114 DNS服务器
nameserver 114.114.114.114    

#微软 DNS服务器
nameserver 233.5.5.5

#google DNS服务器
nameserver 8.8.8.8

最后ping一下百度发现可以ping通了,如下所示:

PING www.baidu.com (180.101.49.12): 56 data bytes
64 bytes from 180.101.49.12: seq=0 ttl=52 time=26.429 ms
64 bytes from 180.101.49.12: seq=1 ttl=52 time=26.678 ms
64 bytes from 180.101.49.12: seq=2 ttl=52 time=26.105 ms
发布了21 篇原创文章 · 获赞 12 · 访问量 1万+

猜你喜欢

转载自blog.csdn.net/Argon_Ghost/article/details/104419600