管理操作系统的路由表
Table of Contents
1 路由表
路由表中的表项内容包括:
- destination:目的地址,用来标识 IP 包的目的地址或者目的网络
- mask:网络掩码,与目的地址一起标识目的主机或者路由器所在的网段的地址
- pre:标识路由加入 IP 路由表的优先级。可能到达一个目的地有多条路由,但是优先 级的存在让他们先选择优先级高的路由进行利用
- cost:路由开销,当到达一个目的地的多个路由优先级相同时,路由开销最小的将成为 最优路由
- interface:输出接口,说明 IP 包将从该路由器哪个接口转发
- nexthop:下一跳 IP 地址,说明 IP 包所经过的下一个路由器
2 Windows
Windows 下可以使用 route 命令来管理路由表
# 查看路由表 route PRINT # ipv4 路由表 route PRINT -4 # ipv6 路由表 route PRINT -6 # 打印匹配 192* 的路由表 route PRINT 192*
=========================================================================== Interface List 11...30 9c 23 bf 31 e9 ......Intel(R) Ethernet Connection (2) I219-LM 16...0a 00 27 00 00 10 ......VirtualBox Host-Only Ethernet Adapter 17...00 50 56 c0 00 01 ......VMware Virtual Ethernet Adapter for VMnet1 18...00 50 56 c0 00 08 ......VMware Virtual Ethernet Adapter for VMnet8 1...........................Software Loopback Interface 1 15...00 00 00 00 00 00 00 e0 Microsoft ISATAP Adapter 13...00 00 00 00 00 00 00 e0 Microsoft ISATAP Adapter #3 14...00 00 00 00 00 00 00 e0 Microsoft ISATAP Adapter #4 20...00 00 00 00 00 00 00 e0 Microsoft ISATAP Adapter #5 =========================================================================== IPv4 Route Table =========================================================================== Active Routes: Network Destination Netmask Gateway Interface Metric 0.0.0.0 0.0.0.0 192.168.0.1 192.168.0.106 266 127.0.0.0 255.0.0.0 On-link 127.0.0.1 306 127.0.0.1 255.255.255.255 On-link 127.0.0.1 306 ... 255.255.255.255 255.255.255.255 On-link 192.168.0.106 266 255.255.255.255 255.255.255.255 On-link 192.168.56.1 266 255.255.255.255 255.255.255.255 On-link 192.168.195.1 276 255.255.255.255 255.255.255.255 On-link 192.168.17.1 276 =========================================================================== Persistent Routes: Network Address Netmask Gateway Address Metric 0.0.0.0 0.0.0.0 192.168.0.1 Default =========================================================================== IPv6 Route Table =========================================================================== Active Routes: If Metric Network Destination Gateway 1 306 ::1/128 On-link 11 266 fe80::/64 On-link 16 266 fe80::/64 On-link 17 276 fe80::/64 On-link 18 276 fe80::/64 On-link 16 266 fe80::17a:6095:c21d:649/128 On-link 18 276 fe80::3d40:689a:d685:3cf7/128 On-link 11 266 fe80::4464:1783:3bfe:efbf/128 On-link 17 276 fe80::74e0:b735:137e:87bd/128 On-link 1 306 ff00::/8 On-link 11 266 ff00::/8 On-link 16 266 ff00::/8 On-link 17 276 ff00::/8 On-link 18 276 ff00::/8 On-link =========================================================================== Persistent Routes: None
route ADD 192.168.0.0 MASK 255.255.255.0 192.168.0.1 METRIC 3 IF 2 route ADD 3ffe::/32 3ffe::1 # CHANGE is used to modify gateway and/or metric only. route CHANGE 157.0.0.0 MASK 255.0.0.0 157.55.80.5 METRIC 2 IF 2 route DELETE 157.0.0.0 route DELETE 3ffe::/32
-- 添加 192.168.43.1 的默认路由 route ADD 0.0.0.0 mask 0.0.0.0 192.168.43.1 -p METRIC 300 -- 添加 192.168.0.0/24 的普通路由,下一跳为 192.168.0.10 route ADD 192.168.0.0 mask 255.255.255.0 192.168.0.10 -p
-- 删除所有的默认路由 route DELETE 0.0.0.0
3 Mac
打印路由表
netstat -nr
Routing tables Internet: Destination Gateway Flags Refs Use Netif Expire default 192.168.1.1 UGSc 31 0 en0 127 127.0.0.1 UCS 0 0 lo0 127.0.0.1 127.0.0.1 UH 6 25526 lo0 169.254 link#6 UCS 0 0 en0 192.168.1 link#6 UCS 0 0 en0 192.168.1.1/32 link#6 UCS 1 0 en0 192.168.1.1 58:c8:76:6b:b5:38 UHLWIir 32 9071 en0 1181 192.168.1.7/32 link#6 UCS 0 0 en0 224.0.0/4 link#6 UmCS 3 0 en0 224.0.0.251 1:0:5e:0:0:fb UHmLWI 0 12 en0 224.0.0.252 1:0:5e:0:0:fc UHmLWI 0 6 en0 239.255.255.250 1:0:5e:7f:ff:fa UHmLWI 0 19 en0 255.255.255.255/32 link#6 UCS 0 0 en0 Internet6: Destination Gateway Flags Netif Expire default fe80::1%en0 UGc en0 default fe80::%utun0 UGcI utun0 ::1 ::1 UHL lo0 2409:8a00:6c44:45f0::/64 link#6 UC en0 2409:8a00:6c44:45f0:48b:3cec:baf8:1b3d a8:20:66:15:c1:6f UHLWI en0 ... ff02::%en0/32 link#6 UmCI en0 ff02::%awdl0/32 link#12 UmCI awdl0 ff02::%utun0/32 fe80::3784:56fb:ef44:a26c%utun0 UmCI utun0