Basic syntax
ip [-OPTIONS] OBJECT [COMMAND [ARGUMENTS]]
The main OBJECTs:
| object | what it covers |
|---|---|
addr | IP addresses on interfaces |
link | network interfaces (up/down, MAC, MTU, type) |
route | routing table |
neigh | neighbors (ARP/NDP) |
rule | policy-routing rules |
netns | network namespaces (see namespaces) |
tunnel | tunnel interfaces (gre, ipip, sit) |
xfrm | IPsec |
monitor | live stream of netlink events |
Useful options
-br- brief format (one line per entry)-4/-6- IPv4 only / IPv6 only-c- colorize-j- JSON output (useful in scripts)-s- statistics (counters)
Examples by object
addr
ip -4 -br addr # compact IPv4 list
ip addr show eth0 # one interface in detail
sudo ip addr add 10.0.0.5/24 dev eth0
sudo ip addr del 10.0.0.5/24 dev eth0
link
ip -br link # all interfaces, brief
sudo ip link set eth0 down / up
sudo ip link set eth0 mtu 9000
sudo ip link set eth0 address aa:bb:cc:00:11:22
sudo ip link add veth0 type veth peer name veth1 # see [[veth-pair]]
route
ip route # all routes
ip route get 8.8.8.8 # which route will be selected for this address
sudo ip route add 10.5.0.0/16 via 10.0.0.1
sudo ip route add default via 192.168.1.1
sudo ip route del 10.5.0.0/16
neigh
ip neigh # ARP table (see [[arp]])
sudo ip neigh flush all
sudo ip neigh add 10.0.0.5 lladdr aa:bb:cc:dd:ee:ff dev eth0
netns
sudo ip netns add red
ip netns list
sudo ip netns exec red bash # run a command inside the netns
sudo ip link set veth1 netns red
ip monitor: live events
A useful mode for debugging network events:
ip monitor # stream all netlink events: link/addr/route/neigh
ip monitor route # route changes only
When something changes on its own, run monitor to see what triggered it.
JSON for automation
ip -j addr show eth0 | jq '.[0].addr_info[] | select(.family=="inet") | .local'
# -> "10.0.0.5"
This is the right way to parse ip output in scripts. Do not grep plain text.