The “ip” Command in Linux [9+ Practical Examples]

LINUX
FUNDAMENTALS
A Complete Guide for Beginners Enroll Course Now

The ip command in Linux allows users to display as well as manipulate routing tables, network interfaces, and devices. Moreover, You can extract various network information using this command. In this article, I will demonstrate the basic usage of the ip command in Linux with practical examples.

A. Description

The ip command in Linux is a powerful command line utility that enables users to configure network interfaces. In addition to other applications, you can also assign new IP addresses using this command.

B. Syntax

The syntax of the ip command in Linux is a bit different from the other available commands. It takes multiple parameters as the argument. Here, The argument OBJECT is the type of network attribute you want to work with. And the COMMAND argument specifies the action performed on the mentioned OBJECT.

ip [OPTION]... OBJECT COMMAND

Note: In the above syntax OPTION enclosed by square brackets indicates that it is not mandatory and the 3 dots after the brackets represents that multiple options can be utilized at the same time. As a parameter, if no specific COMMAND is mentioned then the default commands list or, help are assumed. Moreover, the following actions can be passed as the possible COMMAND:

  • add
  • delete/del
  • show

C. Options

Many useful options are available for the ip command. I have listed some of the most used ones here. However, to learn more about the ip command you can always check the man page.

man ip

Useful Options

  • -br/-brief: Displays only basic information.
  • -h/-human: Displays human-readable values.
  • -V: Prints ip utility version
  • -4: Filters only the IPv4 addresses.
  • -6: Filters only the IPv6 addresses.

Note: The options in Linux CLI (Command Line Interface) are all case-sensitive, So be cautious while using them

D. Objects

The ip command in Linux takes special parameters called objects. These are the object type of networks that users can manage. These objects can be used in both full or abbreviated forms. The most useful objects for this command are listed below.

Useful Objects

  • l/link: Displays network interfaces.
  • a/addr/address: Shows IP Addresses.
  • r/route: Prints routing table.
  • n/neigh:– Displays neighbor objects (ARP table).
Note: The objects in Linux CLI (Command Line Interface) are all case-sensitive, So be cautious while using them

Practical Examples of the “ip” Command in Linux

The ip command in Linux is a useful command for viewing network information and configuring related interfaces. Some of the most useful applications of the ip command have been illustrated below.

Example 1: Displaying All IP Addresses Available on the System

You can display all the IP addresses of the networks connected to your system using the ip command in Linux. However, you would need to use the object a or, addr or, address to get this output. In this example, I will display all the IP addresses available on my system. Follow the instructions below to do the same.

Steps to Follow >

➊ At first, open the Ubuntu Terminal.

➋ Type the following command in the command prompt:

ip addr

➌ Now, press the ENTER button.

Output >

In the given image, you can see that I have displayed all the IP addresses of the available network devices on my system.Displaying All IP Addresses Available on the System.


Similar Readings


Example 2: Displaying All Network Interfaces Available on the System Using the “ip” Command in Linux

You can display all the network devices on your system using the ip command in Linux with the object “l” or, “link“. To list the interfaces, you have to use the command show as well. In this example, I will display all the available network devices on my system. You can do the same by following the given steps.

Steps to Follow >

➊ Open the Ubuntu Terminal.

➋ Type the following command in the command prompt:

ip link show

➌ Press the ENTER button.

Output >

In the image below, you can see that I have listed all the available network devices.Displaying All Network Interfaces Available on the System.

Example 3: Displaying Information of a Specified Interface Using the “ip” Command in Linux

You can display a specified network device from your system using the ip command in Linux. You will need to mention the device name after the object “l” or, “link” along with the command show. In this example, I will display only the “ens33” network device on my terminal. To do the same follow the given steps.

Steps to Follow >

➊ At first, launch the Ubuntu Terminal.

➋ Type the following command in the command prompt:

ip link show ens33

➌ Now, hit the ENTER button.

Output >

In the following image, you can see that I have shown only the desired network device.Displaying Information of a Specified Interface Using the ip Command in Linux.

Example 4: Filtering IP Address Using the “ip” Command in Linux

You can filter the network interfaces by their network protocol address family while viewing them in your terminal. In this case, you will need to use option -4 or, -6 for the protocol family and then the object addr or, address. Follow the below examples to filter the devices separately.

Case A: Displaying Only IPv4 Addresses Using the “ip” Command in Linux

To display only the IPv4 addresses follow the steps below.

Steps to Follow >

➊ At first, go to the Ubuntu Terminal.

➋ Type the following command in the command prompt:

ip -4 addr

➌ Now, press the ENTER button.

Output >

In the following image, you can see that I have shown only the IPv4 addresses.Displaying Only IPv4 Addresses Using the ip Command in Linux.

Case B: Displaying Only IPv6 Addresses Using the “ip” Command in Linux

To display only the IPv6 addresses follow the process below.

Steps to Follow >

➊ Launch the Ubuntu Terminal.

➋ Type the following command in the command prompt:

ip -6 addr

➌ Hit the ENTER button.

Output >

In the given image, you can see that I have shown only the IPv6 addresses.Displaying Only IPv6 Addresses Using the ip Command in Linux.

Example 5: Adding IP Address to an Interface Using the “ip” Command in Linux

You can add a new IP address to your available network device using the ip command in Linux. Nevertheless, You must run the command as the superuser using the sudo keyword to achieve this task. The object address and the command add are also needed for this assignment. Below is the syntax you can follow to add an IP address.

sudo ip address add IP_ADDRESS dev DEVICE_Name

In this example, I will add the address 192.168.48.200/24 to the ens33 network on my system. You can do so by following the process below.

Steps to Follow >

➊ At first, open the Ubuntu Terminal.

➋ Type the following command in the command prompt:

sudo ip address add 192.168.48.200/24 dev ens33

➌ Now, press the ENTER button.

Output >

In the image below, you can see that I have added the desired IP address to the ens33 interface.Adding IP Address to an Interface Using the ip Command in Linux.

Example 6: Removing IP Address from an Interface Using the “ip” Command in Linux

You can remove an IP address from your available network device using the ip command in Linux. Nevertheless, you must run the command as the superuser (sudo as prefix) to achieve this task. The object address and the command del are also needed for this deletion. You must follow the given syntax to delete an IP address.

sudo ip address del IP_ADDRESS dev DEVICE_Name

In this example, I will delete the address 192.168.48.200/24 from the ens33 network on my system. You can do so by following the steps below.

Viewing IP addresses available on the system.

Steps to Follow >

➊ Launch the Ubuntu Terminal.

➋ Type the following command in the command prompt:

sudo ip address del 192.168.48.200/24 dev ens33

➌ Finally, Hit ENTER.

Output >

In the given image, you can see that I have deleted the desired IP address and the ens33 interface is left with only one IP address.Removing IP Address from an Interface Using the ip Command in Linux.


Similar Readings


Example 7: Altering Status of Network Interfaces Using the “ip” Command in Linux

You can alter the network interface status from your terminal using the ip command in Linux. You can bring an interface up or, down by running commands as a superuser using the sudo command. To do so, you will need to use the commands set up or, set down and the object link. You must maintain the given syntax to alter a network interface.

sudo ip link set dev DEVICE_Name up/down

Follow the below examples to change the statuses separately.

Case A: Bringing an Interface Up Using the “ip” Command in Linux

To bring an interface up follow the given steps.

Steps to Follow >

➊ Open the Ubuntu Terminal.

➋ Type the following command in the command prompt:

sudo ip link set dev ens33 up

➌ Press ENTER.

Output >

In the image below, you can see that I have changed the interface status to UP.Bringing an Interface Up Using the ip Command in Linux.

Case B: Bringing an Interface Down Using the “ip” Command in Linux

To bring an interface down follow the given steps.

Steps to Follow >

➊ At first, open the Ubuntu Terminal.

➋ Type the following command in the command prompt:

sudo ip link set dev ens33 down

➌ Now, press the ENTER button.

Output >

In the following image, you can see that I have changed the interface status to DOWN.Bringing an Interface Down Using the ip Command in Linux.

Example 8: Displaying Routing Table Using the “ip” Command in Linux

You can display all the routing tables of the networks connected to your system using the ip command in Linux. You will need to use the object route to get this output. In this example, I will display all the routing information available on my system. Follow the instructions below to do the same.

Steps to Follow >

➊ At first, open the Ubuntu Terminal.

➋ Type the following command in the command prompt:

ip route

➌ Now, press the ENTER button.

Output >

In the given image, you can see that I have displayed the routing table of my system.Displaying Routing Table Using the ip Command in Linux.

Example 9: Altering Routing Table Using the “ip” Command in Linux

You can alter the routing table of your network system from the terminal using the ip command in Linux. In this case, you must run commands as a superuser using the sudo keyword. To do this, you will also need to use the commands add or, del and the object route. You must maintain the given syntax to alter the routing table.

sudo ip route add/del IP_ADDRESS dev DEVICE_Name

Follow the below examples to learn more about the two different tasks.

Case A: Adding New Route to the Routing Table Using the “ip” Command in Linux

Follow the steps given to add a new route “192.168.48.0/24” to the routing table.

Steps to Follow >

➊ Open the Ubuntu Terminal.

➋ Type the following command in the command prompt:

sudo ip route add 192.168.48.0/24 dev ens33

➌ Now, press the ENTER button.

Output >

In the image below, you can see that I have added the desired route to the existing table.Adding New Route to the Routing Table.

Case B: Deleting Route from the Routing Table Using the “ip” Command in Linux

You can see that I have marked the route “192.168.48.0/24” in the image below. To delete this particular route follow the given instructions.Viewing available routes.

Steps to Follow >

➊ Launch the Ubuntu Terminal.

➋ Type the following command in the command prompt:

sudo ip route del 192.168.48.0/24 dev ens33

➌ Now, hit the ENTER button.

Output >

In the following image, you can see that I have deleted the mentioned route from the routing table.Deleting route from ip table.

Conclusion

This article presents the most frequent uses of the ip command in Linux. Exercising these provided hands-on examples, you will be able to handle network devices along with viewing their information. I hope, these practical examples will aid your experience in the command line and help you become a power user of Linux.


Similar Readings

Rate this post
Anonnya Ghosh

Hello there! I am Anonnya Ghosh, a Computer Science and Engineering graduate from Ahsanullah University of Science and Technology (AUST). Currently, I am working as a Linux Content Developer Executive at SOFTEKO. The strong bond between Linux and cybersecurity drives me to explore this world of open-source architecture. I aspire to learn new things further and contribute to the field of CS with my experience. Read Full Bio

Leave a Comment