iproute2 是 Linux 提供的一组管理网络连接的用户态工具。

ip [link|addr|route|rule] help
man ip [link|addr|route|rule]

ip link

ip link # Show information for all interfaces
ip link show dev em1 # Display information only for device em1
ip link -d show dev em1 # show interface details
ip -s link # Display interface statistics

ip link set em1 up # Bring em1 online
ip link set em1 down # Bring em1 offline
ip link set em1 mtu 1492 # Set the MTU on em1 to 1492
ip link set em1 promisc on # Enable promiscuous mode for em1

ip addr

ip addr #Show information for all addresses
ip addr show dev em1

ip addr add dev em1
ip addr del dev em1

ip rule

ip rule # show all route rules
ip rule add from table main prio 10
ip rule add fwmark 0x1/0x1 table 4 prio 4 # match fwmark bit(s) mark/mask
# 可以使用的所有条件:
# [ not ] [ from PREFIX ] [ to PREFIX ] [ tos TOS ] [ fwmark FWMARK[/MASK] ] [ iif STRING ] [ oif STRING ] [ pref NUMBER ] [ l3mdev ]

ip route

PS. "route" 可以简写为 "r"

ip route show table main # == ip route

ip route add default via dev em1 # Add a default route (for all addresses) via the local gateway that can be reached on device em1
ip route add via #Add a route to via the gateway at
ip route add dev em1 #Add a route to that can be reached on
device em1
ip route add default via [dev em1] [src] [table main]
ip route delete via
ip route replace dev em1 # Replace the defined route for to use
device em1
ip route get # Display the actual route taken for IP


 # Display the actual route for a dst ip and fwmark
ip route get mark 0x2

ip neigh

ip neigh # Display neighbour objects
ip neigh show dev em1 # Show the ARP cache for device em1

ip neigh add lladdr 1:2:3:4:5:6 dev em1 nud permanent
ip neigh add lladdr 1:2:3:4:5:6 dev em1 # Add address with MAC 1:2:3:4:5:6 to em1
ip neigh del dev em1 # Invalidate the entry for on em1
ip neigh replace lladdr 1:2:3:4:5:6 dev em1 # Replace the entry for address to use MAC 1:2:3:4:5:6 on em1

ip maddr

ip maddr # Display multicast information for all devices
ip maddr show dev em1 # Display multicast information for device em1

ip maddr add 33:33:00:00:00:01 dev em1 # Add mutlicast address 33:33:00:00:00:01 to em1
ip maddr del 33:33:00:00:00:01 dev em1 # Delete address 33:33:00:00:00:01 from em1

Other ethtools


arping -I eth0 # Send ARP request to via interface eth0
arping -D -I eth0 # Check for duplicate MAC addresses at on eth0


ethtool -g eth0 # Display ring buffer for eth0
ethtool -i eth0 # Display driver information for eth0
ethtool -p eth0 # Identify eth0 by sight, typically by causing LEDs to blink on the network port
ethtool -S eth0 # Display network and driver statistics for eth0


Display socket statistics. The below options can be combined

ss -a # Show all sockets (Without this flag, will only show non-listening sockets)
ss -e # Show detailed socket information
ss -o # Show timer information
ss -n # Do not resolve addresses
ss -p # Show process using the socket
ss -neopa # show above all

Compare NET-TOOLS vs. IPROUTE commands

arp -a ip neigh
arp -v ip -s neigh
arp -s 1:2:3:4:5:6 ip neigh add lladdr 1:2:3:4:5:6 dev eth1
arp -i eth1 -d ip neigh del dev eth1
ifconfig -a ip addr
ifconfig eth0 down ip link set eth0 down
ifconfig eth0 up ip link set eth0 up
ifconfig eth0 ip addr add dev eth0
ifconfig eth0 netmask ip addr add dev eth0
ifconfig eth0 mtu 9000 ip link set eth0 mtu 9000
ifconfig eth0:0 ip addr add dev eth0
netstat ss
netstat -neopa ss -neopa
netstat -g ip maddr
route ip route
route add -net netmask dev eth0 ip route add dev eth0
route add default gw ip route add default via

Last update: 2021-01-14 05:54:26 UTC