openwrt ping: sendto: Network unreachable解决办法

567 字
3 分钟
openwrt ping: sendto: Network unreachable解决办法

pixiv
pixiv

报错如下#

root@OpenWrt:/# ping zhihu.com
PING zhihu.com (103.41.167.234): 56 data bytes
ping: sendto: Network unreachable
  • 这个错误一般是由于网关配置错误导致的
  • 通过 route 查看路由表
root@OpenWrt:/# route
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
172.17.0.0 * 255.255.0.0 U 0 0 0 docker0
192.168.11.0 * 255.255.255.0 U 1 0 0 eth1
192.168.12.0 * 255.255.255.0 U 1 0 0 eth2
192.168.233.0 * 255.255.255.0 U 0 0 0 br-lan
  • 可以看到Gateway一栏为空,也就是没有配置网关,路由不知将数据转发到哪个网口。解决办法是增加一条默认网关。添加命令: route add default gw XXX.XXX.XXX.XXX ,XXX.XXX.XXX.XXX为你的上级网关,一般为光猫的IP。添加完成后通过 route 查看路由表是否生效
route add default gw 192.168.11.1
root@OpenWrt:/# route
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
default 192.168.11.1 0.0.0.0 UG 0 0 0 eth1
172.17.0.0 * 255.255.0.0 U 0 0 0 docker0
192.168.11.0 * 255.255.255.0 U 1 0 0 eth1
192.168.12.0 * 255.255.255.0 U 1 0 0 eth2
192.168.233.0 * 255.255.255.0 U 0 0 0 br-lan
root@OpenWrt:/#
  • 可以看到默认网关default已被添加进路由表,ping外网成功
root@OpenWrt:/# ping bilibili.com
PING bilibili.com (110.43.34.66): 56 data bytes
64 bytes from 110.43.34.66: seq=0 ttl=51 time=27.996 ms
64 bytes from 110.43.34.66: seq=1 ttl=51 time=18.906 ms
64 bytes from 110.43.34.66: seq=2 ttl=51 time=19.691 ms
64 bytes from 110.43.34.66: seq=3 ttl=51 time=19.945 ms
64 bytes from 110.43.34.66: seq=4 ttl=51 time=19.169 ms
64 bytes from 110.43.34.66: seq=5 ttl=51 time=22.988 ms
64 bytes from 110.43.34.66: seq=6 ttl=51 time=19.152 ms
^C
--- bilibili.com ping statistics ---
7 packets transmitted, 7 packets received, 0% packet loss
round-trip min/avg/max = 18.906/21.121/27.996 ms
root@OpenWrt:/#

拓展知识-luinx路由表命令#

  • route 命令的输出项说明

Destination—目标网段或者主机 Gateway—网关地址,”*” 表示目标是本主机所属的网络,不需要路由 Genmask—网络掩码 Flags —标记。一些可能的标记如下: U — 路由是活动的 H — 目标是一个主机 G — 路由指向网关 R — 恢复动态路由产生的表项 D — 由路由的后台程序动态地安装 M — 由路由的后台程序修改 ! — 拒绝路由 Metric—路由距离,到达指定网络所需的中转数(linux 内核中没有使用) Ref—路由项引用次数(linux 内核中没有使用) Use—此路由项被路由软件查找的次数 Iface—该路由表项对应的输出接口

参考:linux 路由表设置 之 route 指令详解

文章分享

如果这篇文章对你有帮助,欢迎分享给更多人!

openwrt ping: sendto: Network unreachable解决办法
https://kanochan.net/posts/openwrt-network-unreachable-fix/
作者
KanoChan
发布于
2021-04-01
许可协议
CC BY-NC-SA 4.0

评论区

文章目录