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:/#
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· 三行代码完成国际化适配,妙~啊~
· .NET Core 中如何实现缓存的预热?
· 如何调用 DeepSeek 的自然语言处理 API 接口并集成到在线客服系统