The Linux Crash Course gives you the scoop on an important Linux-related concept in each and every video, one video at a time. In this episode, Jay explains how to use the ip command – which is now the go-to for managing network interfaces in Linux.
Basic usage
Let’s start with a very basic example.
ip addr show
Here, we can view some useful information about the host system’s networking situation. We can see the interface names, the IP addresses, MAC addresses, and so on.
We can shorten the ip command quite a bit:
ip a
This example was exactly the same as the previous one. It’s just abbreviated, and the command is smart enough to know what you’re trying to do if you type at least that. I’m not going to give you any other abbreviation examples since that might get confusing, but I wanted to give you that example to save your typing a bit, since that’s easily the most common example of this command that you’ll be using.
ip addr show dev eth0
Before we go any further, I wanted to let you know that some of the commands we’ll be running will make actual changes to our server’s network configuration, so proceed with caution.
For example, if you’re using SSH to connect to a cloud server, these commands will likely result in you getting disconnected. You don’t have to actually follow along and perform each and every command. Sometimes, it’s better to be a bit cautious.
Also, Learn Linux TV is not responsible if you damage anything, cause an outage, or anything else that pertains to odd behavior, summoning demons, or anything else that may happen.
One more thing before we continue. There’s more than one way to manage network connections on Linux systems. Specifically, GUI and commandline methods. In practice, if a GUI is installed, use that to tweak your network connections. If a GUI or desktop environment is not present, then do it via the commandline.
However, even with a GUI, the ip command can still be useful.
Anyway, speaking of that, let’s see an example of turning an interface on or off. This might be useful if you’re testing DHCP and want to test the assignment again, but if you’re connected remotely you’ll definitely not want to execute this.
ip link set etho0 down
ip link set etho0 up
With those examples, we were able to bring an interface down, and then bring it up again.
Continuing, let’s see an example of changing the IP address of a system with the ip command:
sudo ip addr add 172.16.1.120/24 dev eth0
Of course, this is just a made-up example. But before we execute it, let’s understand what we’re doing here.
Suppose we need to change the IP address of our server. There’s no desktop environment, so the ip command can get this done. We’ll use sudo, because anything that constitutes change at this level is going to need permission, and we request root permission through sudo.
Routing
As I mentioned earlier, the iproute2 suite handles the work that the ip and route commands performed previously. We’ve just seen examples of showing the current IP address info and changing a device’s IP address, let’s look at routing now.
First, let’s print the routing table:
ip route show
We don’t need sudo for this, since we’re not changing anything. With this command, we’re simply taking a look at the routing table.
One reason why this might be useful, is suppose you’re not able to SSH into a server, but you know for sure it’s powered on and connected to the switch.
One culprit might be that you’re routing table doesn’t have a route to the network that the server is connected to, so your system has no idea how to navigate to it.
And that’s the key here, navigation. To get a server, the request has to be able to navigate its way to its target, and the routing table is how this happens.
Another thing to be careful about is creating a bigger problem. I’m going to show you a command that will let you add a route to your routing table, but keep in mind that more than one thing is often responsible for this.
For instance, suppose you’re using a cloud provider and one cloud server isn’t able to talk to another. In that case, the ip command may not be the best way to solve this because networking is generally handled by the cloud provider, and network routes are generally added through your cloud dashboard.
Don’t get me wrong, the ip command is definitely a great tool, it’s just that it’s easy to create conflicting routes in multiple places if you use more than one means of configuring something.
Anyway, to add a route to our routing table, the command would look like this:
ip route add 172.16.2.0/24 via 172.168.2.1 dev eth0
To delete an entry:
ip route delete 172.16.2.0/24 via 172.16.2.1 dev eth0
Speaking of default gateway, if you need to change the default gateway for an interface, here’s how that would look:
sudo ip route add default via 172.16.2.1 dev eth0
link option
The link option is used to display information related to the link layer.
ip link show
ip link show eth0
Show statistics:
ip link show -s
ip -s link show eth0



