温馨提示×

linux ifconfig怎么查网关

小樊
46
2026-09-23 06:52:14
栏目: 智能运维

在 Linux 里 ifconfig 本身不能直接查到网关(gateway),它只能看 IP、子网掩码、MAC 等接口信息。

方法一:用 route(最常用)

route -n

或

netstat -rn

看这一行:

Destination     Gateway         Genmask         Flags   Mertic  Ref     Use Iface
0.0.0.0        192.168.1.1     0.0.0.0         UG      100     0       0 eth0

其中 Gateway 列 = 网关地址(UG 表示是默认网关)


方法二:用 ip 命令(推荐,替代 ifconfig)

ip route

或

ip route show default

示例输出:

default via 192.168.1.1 dev eth0

via 后面就是网关


方法三:结合 ifconfig 看网卡,再查网关

ifconfig
ip route | grep default

✅ 总结:

  • ifconfig ❌ 看不到网关
  • 查网关用:route -n 或 ip route

如果你是用 CentOS / Ubuntu / 嵌入式 Linux,我也可以给你对应具体命令。

0 踩