Linux Command Reference ยท Networking
Linux ip command
Reference for the Linux ip command: show and change addresses, links, routes and neighbors, with ifconfig and route equivalents and CIDR notation explained.
ip is the modern tool for looking at and configuring the Linux network stack. It is part of the iproute2 package and replaces the older ifconfig, route and arp. One command with subcommands covers links (interfaces), addresses, routes, neighbors (the ARP/NDP cache), policy rules and namespaces.
Reading is safe for everyone. Changing things needs root and takes effect immediately, but does not survive a reboot; permanent settings belong in your distribution's network configuration.
ip addr # addresses (short: ip a) ip -br link # one-line link summary ip route # routing table ip route get 8.8.8.8
Try it
ip is not installed in our sandbox, so its output is read-only below. The runnable example handles the part people find hardest: CIDR notation. It converts a prefix length to a netmask and counts the addresses.
Read-only: typical output.
$ ip -br addr lo UNKNOWN 127.0.0.1/8 ::1/128 eth0 UP 192.168.1.20/24 fe80::a00:27ff:fe4e:66a1/64 $ ip route default via 192.168.1.1 dev eth0 proto dhcp metric 100 192.168.1.0/24 dev eth0 proto kernel scope link src 192.168.1.20
Press Run (or Ctrl + Enter) to see the result here.
Program input ยท what you'd type while the program runs
Type the answers before you press Run, one per line. Each time the program reads a line (with read or cat), it gets the next line from this box.
Syntax
ip [OPTIONS] OBJECT COMMAND [ARGUMENTS]
| Object | Common commands | Meaning |
|---|---|---|
link |
show, set DEV up |
Network devices: state, MTU, MAC address. |
addr |
show, add, del |
IP addresses on devices. |
route |
show, add, del, get |
The routing table. |
neigh |
show, flush |
ARP/NDP neighbor cache. |
rule |
show, add |
Policy routing rules. |
netns |
add, exec, list |
Network namespaces. |
-s |
option | Add statistics (counters). |
| Option | Description |
|---|---|
-br |
Brief, one line per interface. |
-c |
Colored output. |
-4, -6 |
Only IPv4 or IPv6. |
-j, -p |
JSON output; -p pretty-prints it (good with jq). |
-s |
Statistics. |
Objects and commands can be abbreviated: ip a, ip r, ip l.
Returns: 0 on success; non-zero for unknown objects, bad arguments or missing privileges ("RTNETLINK answers: Operation not permitted").
Usage notes
- Old versus new.
ifconfigisip addr/ip link,route -nisip route,arp -nisip neigh,netstat -risip route. Seenetstatandss. - Add an address:
sudo ip addr add 192.168.1.50/24 dev eth0. It adds, not replaces, so a device can carry several addresses. - Bring a link up or down:
sudo ip link set eth0 up. Taking down the interface you are logged in through will cut your SSH session. - Default gateway:
sudo ip route add default via 192.168.1.1. If one exists, usereplaceinstead ofadd. - Which way will a packet go?
ip route get ADDRESSprints the chosen interface, source address and gateway: the fastest routing check. - Not persistent. Changes vanish at reboot or when the network manager reapplies its settings; edit Netplan, NetworkManager or systemd-networkd files for lasting changes.
- Prefix lengths:
/24is 256 addresses (254 usable for hosts),/32is a single host,/0matches everything. - Scripting: prefer
-jwithjqover parsing human-readable output, whose layout changes between versions. - Interface names such as
enp3s0come from the hardware path;lois the loopback and is always127.0.0.1.
Related
ss,netstat,ping,traceroute,hostname- Lessons: Network Configuration, Networking Basics