ip command Cheat Sheet – Quick Reference Guide

Last updated: March 16, 2024 | Linuxopsys

Introduction

The ip command is an extremely powerful tool used to manage network interfaces, IP addresses, network routing, and ARP/neighbor cache on Linux systems. It comes preinstalled on all modern Linux distros as part of the iproute2 package which is a collection of different network utilities. The ip command is a modern replacement of many deprecated net-tools utilities such as ifconfig, route, arp, etc.

This guide provides an overview of ip command with a cheat sheet.

ip Command Structure

The ip command has the following syntax

ip [ OPTIONS ] OBJECT { COMMAND | help }

Let me break down the syntax for you:

  • OPTIONS - This is optional, options are used to define global parameters. For example, -4 for only displays IPv4 addresses.
  • OBJECT - Specifies a specific component of the network. Here is a list of some of the most frequently used objects:
    • address - represents IPv4 or IPv6 addresses assigned on network interfaces.
    • link (l) - Network interfaces, for example, Wi-Fi adaptors and wired connections
    • route (r) - Routing table entries
    • maddress (m) - Multicast addresses
    • neighbor (n) - Neighbor entry, which contains information (ARP cache) about a neighboring device on the network.
    • mroute (mr) - Multicast routing cache entry
    • rule (ru) - Routing policy database for packet matching and handling based on specific conditions.

When you are working with IP objects, you can save time by using abbreviated or shortened object names. For instance, instead of typing "address," you can simply use "addr" or even just "a."

  • COMMAND - The action you perform on objects. Here is a list of some useful commands:
    • help - display a list of commands and options available to an object.
    • add - assign new object such as the IP address, route, etc.
    • delete - delete the existing object.
    • show or list - display information about the specified object.
    • replace - replace the existing object.

Managing Network Interfaces

The “link” object is used to manage all network interfaces available on a device, for example, wired connections and Wi-Fi adaptors.

Listing all network interfaces

To list all available network interfaces use the following command:

ip link show

This command is generally used to see the state (up or down) of network interfaces. Additionally from its output, you can find the interface name, its MAC address, MTU size, etc.

Activating a network interface

To activate a network interface, use “ip link set dev” followed by the device name and then the “up” state.

Here is an example of activating the wlan0 interface:

ip link set dev wlan0 up

When you execute the command the network interface wlan0 will be activated, in other words, it would be brought up allowing it to start receiving and transmitting network packets.

Deactivating a network interface

To deactivate the interface you would replace the “up” state with the down. For example, to deactivate the wlan0 interface you would run:

ip link set dev wlan0 down

This will bring the interface wlan0 down, and it will no longer transmit data, recieve any network packets or connect to any wireless network if it is a wireless interface which in this case it is.

Renaming a network interface

To rename a network interface using the ip command, you can run the following command:

ip link set eth0 name eth1

This command will change your interface name from eth0 to eth1. You can confirm the changes by running the “ip link show” command

Managing IP Addresses

The address object is used to manage all the IP addresses on network interfaces.

Displaying IP addresses for all interfaces

To display ip addresses for all available network interfaces run the following command:

ip address show

This command will show all the IPv4, IPv6, and also the broadcast address available on each network interface. To display only the IPv4 and IPv6 addresses use the -4 option and -6 option respectively. 

Adding an IP address to an interface

To add an IP address to an interface, for example, wlan0 interface, you would run:

ip addr add 192.168.1.100/24 dev wlan0

This will add the 192.168.1.100 IP address to the wlan0 interface. To verify that the address has been successfully added run the “ip addr show” command. 

Remove an IP address from an interface

When you want to delete the IP address from the interface you use the del command. Here is an example:

ip addr del 192.168.1.100/24 dev wlan0

This command will delete the 192.168.1.100/24 address for the wlan0 interface.

Managing Network Routes

The ip “route” object comes in handy when you want to view and modify routing table entries.

Displaying the routing table

To display the entire routing table, you would use the command.

ip route show

The command will display available route entries on the system. Each routing entry contains information about the destination network, the network interface through which packets will be forwarded, the destination network, and so on.

Adding a route

To add routes, the add command does the job. Following is an example of adding a single route:

ip route add 10.0.0.0/24 via 192.168.1.1

This command will add a new route which instructs the system to forward any network traffic that is destined for the network 10.0.0.0/24 via the gateway 192.168.1.1.

Removing a route

When you no longer need the route, you can delete it using the del command of the route object

ip route del 10.0.0.0/24

The command will remove the route for the network 10.0.0.0/24.

Adding a default gateway

To add a default route, use the default keyword as an argument to the add command. Here is an example:

ip route add default via 192.168.1.254

This command adds a  default route via the 192.168.1.254 address,  where the packets that do not match any route in the routing table will be forwarded to.

Managing ARP or Neighbor Entries

The neighbor object is used to manage ARP or Neighbour entries.

Displaying the neighbor's table

To display a neighbor entry, run the following command:

ip neigh show

The output of this command shows the mapping of IP addresses and their corresponding MAC Addresses along with other information on how the IP address can be reached.

Adding an entry to the neighbor table

The following command is an example of adding an entry to the neighbor table:

ip neigh add 192.168.1.100 lladdr 00:11:22:33:44:55 dev eth0

This commands manually adds an entry in the neighbor cache which maps the 192.168.1.100 address with the 00:11:22:33:44:55 MAC address and also specifying that IP address will be reachable via the eth0 interface.

Removing an entry from the neighbor's table

You can delete an entry from the neighbor’s table using the del command of the neighbor object:

ip neigh del 192.168.1.100 dev eth0

This will remove the entry that maps the IP address 192.168.1.100 with its corresponding MAC Address and the interface through which it is reachable from the neighbor’s table.

Manager Multicast Addresses

The maddress object is used to manage multicast addresses.

Displaying multicast address

To display the multicast addresses, you would use the command.

ip maddress show

The command will display the current configured IPv4 and IPv6 multicast group membership for each network interface on the system.

Adding multicast address

Here is an example of adding the eth0 interface to a multicast group:

ip maddress add 224.1.1.1 dev eth0

This adds add a network interface eth0 to the membership of the multicast group with an  IPv4 address of 224.1.1.1 

Removing multicast address

To delete a multicast address from an interface, use the del command:

ip maddress del 224.1.1.1 dev eth0

Once you run this command, it will remove the network interface eth0 from the multicast group with an IPv4 address of 224.1.1.1.

Download the ip command cheat sheet - PDF

NET-TOOLS COMMANDS vs IPROUTE COMMANDS

If you've spent a lot of time using ifconfig, it could simply be a matter of familiarity and comfort. You might find it easier to remember and use the commands that you've been using for years, even if newer, more efficient options are available.

Here just bringing a comparison between some of the net-tools utilities and iptroute2 utilities.

Net-tools Commandsiproute2 Commands
ifconfigip addr
ifconfig wlan0ip addr show wlan0
ifconfig wlan0 upip link set wlan0 up
ifconfig wlan0 downip link set wlan0 down
ifconfig wlan0 192.168.1.10ip addr add 192.168.1.10 dev wlan0
ifconfig wlan0 netmask 255.255.255.0ip addr add 192.168.1.10/24 dev wlan0
ifconfig wlan0 mtu 1500ip link set wlan0 mtu 1500
arpip neigh
arp -aip neigh
arp -s 192.168.1.20 1:2:3:4:5:6ip neigh add 192.168.1.20 lladdr 1:2:3:4:5:6 nud permanent
arp -i wlan0 -d 192.168.1.20ip neigh del 192.168.1.20 dev wlan0
netstat -rip route
routeip route
route add default gw 192.168.1.1ip route add default via 192.168.1.1
route del default gw 192.168.1.1ip route del default via 192.168.1.1
netstatss
brctlbridge
ipmaddrip maddr
nameif or ifrenameip link set name
iptunnelip tunnel
netstat -neopass -neopa
SHARE

Comments

Please add comments below to provide the author your ideas, appreciation and feedback.

Leave a Reply

Leave a Comment