在 Linux 里,ifconfig 本身并不能直接看到网关(默认路由)。
ifconfig 只能看 IP 地址、子网掩码、MAC、接口状态 等。
要看网关,通常用下面这些命令:
ip route
或
ip route show
你会看到类似:
default via 192.168.1.1 dev eth0
其中 192.168.1.1 就是网关。
route -n
或
netstat -rn
示例:
0.0.0.0 192.168.1.1 0.0.0.0 UG eth0
ifconfig
只能看到:
例如:
inet 192.168.1.10 netmask 255.255.255.0
但看不到网关。
| 需求 | 命令 |
|---|---|
| 看 IP | ifconfig / ip addr |
| 看网关 | ip route |
| 看路由表 | route -n |
如果你愿意,可以贴一下 ifconfig 的输出,我可以帮你判断网关大概在哪一段。