cheat-sheets

ip and ss

ip (from iproute2) shows and changes interfaces, addresses, routes and the neighbour (ARP) table; ss lists sockets and replaces netstat. Both are on every modern Linux distribution. Changes made with ip are lost at reboot unless also written to the network configuration.

Documentation: ip(8) · ss(8) Project: iproute2

Verification: options were checked against the iproute2 6.1 man pages in Ubuntu 24.04 and the read-only commands run in a container. Commands that change the host network were not run.

Interfaces #

COMMANDDESCRIPTION
ip -br linkBrief interface list with state and MAC
ip link show <IF>One interface in detail
ip -s link show <IF>Packet, error and drop counters
sudo ip link set <IF> up / sudo ip link set <IF> downBring an interface up or down
sudo ip link set <IF> mtu 9000Change the MTU
sudo ip link add link <IF> name <IF>.20 type vlan id 20Create a VLAN sub-interface
sudo ip link add <BRIDGE> type bridgeCreate a bridge
sudo ip link set <IF> master <BRIDGE>Attach an interface to a bridge
sudo ip link delete <IF>Remove a virtual interface

Addresses #

COMMANDDESCRIPTION
ip -br addrBrief address list
ip -4 addr show <IF> / ip -6 addr show <IF>One address family only
sudo ip addr add 192.0.2.10/24 dev <IF>Add an address
sudo ip addr del 192.0.2.10/24 dev <IF>Remove an address
sudo ip addr flush dev <IF>Remove all addresses from an interface
ip -j addrJSON output (pipe to jq, see jq)

Routes #

COMMANDDESCRIPTION
ip routeMain routing table
ip route get 198.51.100.1Which route, source address and interface would be used
sudo ip route add default via 192.0.2.1Set the default gateway
sudo ip route add 198.51.100.0/24 via 192.0.2.254 dev <IF>Static route to a network
sudo ip route del 198.51.100.0/24Remove a route
ip -6 routeIPv6 routes
ip rulePolicy routing rules

Neighbours (ARP) #

COMMANDDESCRIPTION
ip neighNeighbour table; REACHABLE, STALE, FAILED
ip neigh show dev <IF>One interface
sudo ip neigh flush dev <IF>Clear cached entries
sudo ip neigh add 192.0.2.50 lladdr 00:00:5e:00:53:01 dev <IF>Add a static entry (the MAC is from the documentation range)

Network Namespaces #

COMMANDDESCRIPTION
ip netns listList namespaces
sudo ip netns add <NAME>Create a namespace
sudo ip netns exec <NAME> ip addrRun a command inside it

Monitor #

COMMANDDESCRIPTION
ip monitorWatch link, address and route changes live
ip -s -s link show <IF>Extra detail on error counters

ss Sockets #

COMMANDDESCRIPTION
ss -tulpnListening TCP and UDP sockets with owning process (sudo shows other users’ processes)
ss -tlnListening TCP, numeric
ss -tn state establishedEstablished TCP connections
ss -tn dst 198.51.100.1Connections to one address
ss -tn 'sport = :443'Filter by local port
ss -tn 'dport = :22'Filter by remote port
ss -sSocket totals per protocol
ss -tnpConnections with process
ss -tiTCP internals (RTT, congestion window, retransmits)
ss -xlListening Unix sockets
ss -ltn sport = :8080Is anything listening on a port

Flags: -t TCP, -u UDP, -l listening, -n numeric, -p process, -a all, -4 / -6 family.

Old Commands #

OLDREPLACEMENT
ifconfigip addr, ip link
route -nip route
arp -aip neigh
netstat -tulpnss -tulpn
netstat -snstat or ss -s

See Also #

Search all sheets

Tip: / or Ctrl/Cmd+K to open, Esc to close.