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 aip 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 showip 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 eth0ip 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 showip 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 upip 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 showip 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 aip -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 aip -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 allip 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).

