If you are new to the IP command or are curious to understand why it replaced the “ifconfig” command, this post digs in on numerous instances with examples on how to work with the Linux IP command.
Working with the Linux IP Command
The Linux IP command replaces the “ifconfig” command and is used by the administrators to configure the network interfaces on their Linux systems. There are four main categories of options that you can use with the IP command. We will discuss each category while giving examples of executing different commands for different solutions.
1. IP Address
It is mainly used when you want to display the different protocol addresses in your network and modify them when needed.
You can display the IP address of your system by running the “ip address/addr/a” command.
You can display the IPv4 or IPv6 address by specifying the version as -4 or -6 as follows:
To access the IP address of a specific network interface, specify its name with the following syntax:
Here, we specify the enp0s3 as our interface.
Suppose you want to add an IP address to a network interface. You must include the add option.
We can verify that we managed to change the IP address of the enp0s3 interface.
You can also delete the added IP address by replacing the “addr add” with the “addr del” option as shown in the following:
2. IP Link
The option is mainly used when you want to access and modify the network interfaces.
When you want to get the link-layer information of all devices, use the following command:
You can target a specific device by specifying its name with the following syntax:
To get the statistics for your network interfaces, execute the link command with the “-s” flag:
Add the name of the specific network interface that you want to extract its information like in the following example where we specify the enp0s3 interface:
Still, with the link option, you can enable or disable an interface using the up or down option like in the following example. We first disable the interface and then enable it:
You can check more IP link options by checking the help page using the “ip link help” command.
3. IP Route
It is used when working with the network routing table. You can check your routing table by running the “ip route” command.
You can check all the configured routes in your Linux system from the displayed output. The routes display the network address to help identify the next hop and the interface that the packets will go through.
You can modify your routing table using the IP command to add new routes. The manual way involves the following syntax:
You can also delete an existing route in your table with the following syntax:
To get the details about a given route to view what route a given address will take, execute the following command and replace it with your target IP address:
Here’s an example:
4. IP Neigh
The option executes the commands that access and manipulate the neighbor objects.
You can access the current ARP table to see the neighbor entries with the following command:
Use the following syntax to add new entries to your ATP table:
To remove an entry, the syntax changes to the one in the following:
The provided examples are the common examples on how you use the Linux IP command.
Linux offers the IP command to replace the deprecated “ifconfig” command. Linux IP command is ideal in network and system administration, and you can use it with four main options: route, link, address, and neigh. We provided different examples of the commands that you can execute for different tasks. Use this guide to get comfortable with the Linux IP command.