iproute2 與 net-tools
- iproute2 旨在從功能上取代 net-tools
- 自 2001 年起,Linux 社區其中止對 net-tools 的維護
- 到目前(2020年)爲止,iproute2仍處在持續開發中。
- 組件對比
用途 |
net-tools |
iproute2 |
地址和鏈路配置 |
ifconfig |
ip addr, ip link |
路由 |
route |
ip route |
ARP |
arp |
ip neigh |
VLAN |
vconfig |
ip link |
隧道 |
iptunnel |
ip tunnel |
組播 |
ipmaddr |
ip maddr |
統計 |
netstat |
ss |
- ip 命令速查表(出自《Linux 大棚·命令百篇》)
![ip 命令速查表 ip 命令速查表](http://static.javashuo.com/static/loading.gif)
示例
路由表(ip rule)
# 第一列是優先級,數值越小優先級越高
# local:路由表 local 包含本機路由及廣播信息。
# main:使用傳統命令 route -n 所看到的路由表就是 main 的內容。
# default:default 路由表在默認狀況下內容爲空;除非有特別的要求,不然保持其內容爲空便可。
$ ip rule
0: from all lookup local
32763: from all fwmark 0x3 lookup out3
32764: from all fwmark 0x3 lookup out3
32765: from 192.168.0.0/16 lookup out1
32766: from all lookup main
32767: from all lookup default
$ ip rule del table out3 prio 32763
$ ip rule
0: from all lookup local
32764: from all fwmark 0x3 lookup out3
32765: from 192.168.0.0/16 lookup out1
32766: from all lookup main
32767: from all lookup default
$ sudo echo "4 out4" >> /etc/iproute2/rt_tables
# 此時 ip rule 不能顯示新增路由表
# 在新路由表添加應用規則後才能顯示出來
# 給 out4 路由表添加應用規則: 來自 192.168.111.111 的數據使用 out4 路由表
$ sudo ip rule add from 192.168.111.111/32 table out4
$ ip rule
0: from all lookup local
32763: from 192.168.111.111 lookup out4
32764: from all fwmark 0x3 lookup out3
32765: from 192.168.0.0/16 lookup out1
32766: from all lookup main
32767: from all lookup default
路由(ip route)
ip route show
# 相似
route -n
ip route del default dev eth0
ip route show table local
ip route show table main
# 等價於
ip route show
ip route list
ip route ls
ip route
# 相似
route -n
ip route add 192.168.2.0/24 via 192.168.0.1 table main
# 相似
route add -net 192.168.2.0/24 gw 192.168.0.1
地址(ip addr)
ip addr show
# 相似
ifconfig
鏈路(ip link)
ip link show
ARP(ip neigh)
- ARP,Address Resolution Protocol,地址解析協議,由 IP 地址獲取 MAC 地址
- 顯示 arp 表
# ping 192.168.30.44,若是主機在同一局域網內,直接加到 arp 表
ip neigh show
# 條目仍然存在狀態爲stale,下次通訊須要確認
ip neigh delete 192.168.95.50 dev eth0
本文出自
qbit snap