Cheatsheet & Examples: ip

The ip
command is a powerful utility in Linux for managing network interfaces, routing, and address assignments. It replaces older tools like ifconfig
and route
.
Display interface information
Example Usage:ip a
ip addr show
What it does:
Shows details of all network interfaces, including IP addresses, MAC addresses, and status.
Command-line Arguments Explained:
a
: Shorthand foraddr
(address information).show
: Displays the requested information.dev
: Optional flag to filter by a specific interface (e.g.,ip a show dev eth0
).
Show routing table
Example Usage:ip route show
ip r
What it does:
Displays the kernel’s routing table, including default routes, networks, and gateways.
Command-line Arguments Explained:
route
: Subcommand to manage routing information.show
: Displays the routing table.r
: Shorthand forroute
.
Add or remove a route
Example Usage:ip route add default via 192.168.1.1 dev eth0
ip route del 10.0.0.0/24 via 192.168.1.2
What it does:
Modifies the routing table by adding or deleting a route.
Command-line Arguments Explained:
add
: Adds a new route.del
: Deletes an existing route.default
: Specifies the default gateway.via
: Defines the gateway IP address for the route.dev
: Specifies the network interface used for the route.dst
: The destination network or IP address (e.g.,10.0.0.0/24
).
Manage ARP table entries
Example Usage:ip neigh show
ip neigh add 192.168.1.1 lladdr 00:11:22:33:44:55 dev eth0
What it does:
Displays or adds entries to the ARP (Address Resolution Protocol) table, which maps IP addresses to MAC addresses.
Command-line Arguments Explained:
neigh
: Subcommand for ARP table management.show
: Displays the current ARP entries.add
: Adds a new ARP entry.lladdr
: The MAC address to associate with the IP.dev
: The interface where the ARP entry is applied.
Bring a network interface up or down
Example Usage:ip link set eth0 up
ip link set eth0 down
What it does:
Enables or disables a specific network interface (e.g., eth0
).
Command-line Arguments Explained:
link
: Subcommand to manage network interfaces.set
: Modifies the interface’s properties.up
: Enables the interface.down
: Disables the interface.eth0
: The name of the network interface.
Add an IP address to an interface
Example Usage:ip addr add 192.168.1.100/24 dev eth0
What it does:
Assigns a new IP address to a specified network interface.
Command-line Arguments Explained:
addr
: Subcommand for address management.add
: Adds a new IP address.192.168.1.100/24
: The IP address and subnet mask.dev
: Specifies the network interface (e.g.,eth0
).
List all network devices
Example Usage:ip link show
ip l
What it does:
Displays all network interfaces and their statuses (up/down, MAC address, etc.).
Command-line Arguments Explained:
link
: Subcommand for interface-level operations.show
: Displays interface details.l
: Shorthand forlink
.
Check interface statistics
Example Usage:ip -s a
ip -s link show
What it does:
Displays detailed statistics for network interfaces (e.g., packets sent/received).
Command-line Arguments Explained:
-s
: Enables detailed statistics (short for--statistics
).a
: Shorthand foraddr
(address information).link
: Subcommand for interface-level operations.show
: Displays interface details.
Show all IPv4 addresses in brief format
Example Usage:ip -br a
ip -br addr show
What it does:
Lists IPv4 addresses in a compact, easy-to-read format.
Command-line Arguments Explained:
-br
: Enables brief output mode.a
: Shorthand foraddr
.show
: Displays address information.
Flush routes from the routing table
Example Usage:ip route flush all
ip route flush cache
What it does:
Clears all routes or the routing cache, forcing the system to relearn routes.
Command-line Arguments Explained:
flush
: Deletes all routes or the routing cache.all
: Removes all routes.cache
: Clears the routing cache (not the routing table).
Subscribe to my newsletter
Read articles from Hong directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by

Hong
Hong
I am a developer from Malaysia. I work with PHP most of the time, recently I fell in love with Go. When I am not working, I will be ballroom dancing :-)