
在 Linux 系统中,可以使用几种不同的方法来查看路由接口。最常见的方法是使用 route 命令。
打开终端,输入以下命令即可查看系统的路由表:
$ route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 192.168.1.1 0.0.0.0 UG 100 0 0 eth0
169.254.0.0 0.0.0.0 255.255.0.0 U 1000 0 0 eth0
192.168.1.0 0.0.0.0 255.255.255.0 U 100 0 0 eth0
这个命令会列出系统中所有的路由条目,包括目标网络、网关地址、子网掩码、标志位和使用接口等信息。
另一种查看路由接口的方法是使用 ip route show 命令:
$ ip route show
default via 192.168.1.1 dev eth0
169.254.0.0/16 dev eth0 scope link
192.168.1.0/24 dev eth0 proto kernel scope link src 192.168.1.100
这个命令提供更加详细的路由信息,包括路由协议、作用域等。
除此之外,还可以使用 netstat 命令来查看路由信息:
$ netstat -nr
Kernel IP routing table
Destination Gateway Genmask Flags MSS Window irtt Iface
0.0.0.0 192.168.1.1 0.0.0.0 UG 0 0 0 eth0
169.254.0.0 0.0.0.0 255.255.0.0 U 0 0 0 eth0
192.168.1.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
这个命令与 route -n 的输出非常相似。