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
- 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.
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).
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.
Similar Readings
- The “ftp” Command in Linux [14 Practical Examples]
- The “host” Command in Linux [10 Practical Examples]
- The “scp” Command in Linux [4 Practical Examples]
- The “sftp” Command in Linux [6 Practical Examples]
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.
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.
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.
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.
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.
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.
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.
Similar Readings
- The “ dig” Command in Linux [10 Practical Examples]
- The “hostname” Command in Linux [12 Practical Examples]
- The “iptables” Command in Linux [6 Practical Examples]
- The “ifconfig” Command in Linux [6+ Practical Examples]
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.
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.
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.
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.
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.
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.
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
- The “netstat” Command in Linux [22 Practical Examples]
- The “nslookup” Command in Linux [12 Practical Examples]
- The “ufw” Command in Linux [12+ Practical Examples]
- The “ssh” Command in Linux [18 Practical Examples]
- The “traceroute” Command in Linux [13 Practical Examples]
- The “rsync” Command in Linux [10 Practical Examples]
FUNDAMENTALS A Complete Guide for Beginners