Ever wondered what the Linux ip command might be able to do for you? Maybe you’re just getting into Linux terminal work or network management. Let me walk you through some basic examples of the ip command at work.
The ip command is a CLI tool for managing network devices, interfaces, tunnels, and routing. You can both view and manipulate those elements of your network with the ip command, changing at least how the device you’re using sees those elements.
Keep in mind that none of the changes you make with the ip command following these examples are permanent. This makes the command nice in that if you make a mistake and destroy your device’s connection to the network, you can right yourself just by rebooting. The other side of that coin, though, is that any persistent changes you’re trying to make will require other commands.
1
See Your Network Interfaces
A common use for the ip command is checking what network devices are connected to your Linux system. You can use this information to connect across the network or to make changes them, and more as we’ll see later.
For example, type the command ip link show to list all your network interfaces along with other potentially useful information about them.
In my screenshot, you can see I have three network interfaces. The first, lo, is an internal loopback device, a “virtual” network interface used only by my Linux system’s internal processes. The second, wlo1, is the name of the wireless network card inside my laptop. The third is an Ethernet interface connected to my laptop via USB-C port.
2
Disable and Enable Network Interfaces
Let’s say you’ve identified a network interface, and now you want to stop it from operating. For whatever reason, you don’t want any data passing through it. You can use the ip command to disable it so Linux never uses it.
The way you do this is to use the “link set” command, telling ip to set the device to “down.” In this example, I’m using ip to disable my wireless interface called wlo1. Your interface may be named the same or something different, so confirm you’re naming the right interface before using the command.
sudo ip link set wlo1 down
From now on, I won’t be able to use my wlo1 interface, and if I use the ip link show command again, I’ll see it’s status is “down.”
Let’s say, though, I changed my mind and I want to use wlo1 again. Easy.
ip link set wlo1 up
As before, there’s no confirmation message that anything happened, which indicates I can consider wlo1 back in operation.
3
See Your Local IP Address
If you want to find out what your IP address relative to your local network is, the ip command is one of the simplest means of doing so. This can be helpful in identifying mapped devices on your network, accessing servers you’re self-hosting, and more.
Type ip address or ip addr or simply ip a into your terminal, and you’ll see all of your device’s IP addresses organized by network device. You most likely only care about the non-loopback addresses, though. Note that they’ll be shown with “/24” or something similar affixed to indicate its CIDR class.
If you have multiple physical network interfaces like I do, you’ll see you have multiple local IP addresses. When connecting to my device from another, I can choose which connection method (aka network interface) I prefer by specifying the correct IP address.
IPV4 Only
The ip address command on its own outputs a lot of info, including both your IPV4 address and IPV6. If you only care about IPV4, you can use the -4 flag to filter for just IPV4 addresses.
ip -4 a
As you can see, the output is a lot easier to scan for the IP address.
IPV6 Only
Similarly, if you’re only interested in the IPV6 version of your IP address, you can use the -6 flag.
ip -6 a
4
Add a Local IP Address
You might sometimes need to create an IP address for your network interface, such as to fix conflicts with other devices, or to make it easy for software looking for a specific address to find your device. You can do that with the ip command.
In my case, I want to give my Ethernet connection the address 192.168.1.130. I confirmed first, of course, that I didn’t have other devices on my local network with this address; I don’t want to cause any IP address collisions. Then, I’m ready to set the new address with this command:
sudo ip addr add 192.168.1.130/24 dev enx00e04c68143d
Now, when I check my Ethernet device stats with ip link show, I can see there are two different addresses.
5
Delete an IP Address
Let’s say after adding my new IP address I want to delete the old one. Of course, I should first make sure nothing on my local network relies on that address for important connections and instead is using my new, preferred IP address. Then I simply pass this command:
sudo ip addr del 192.168.1.129/24 dev enx00e04c68143d
From now on, my device will no longer be reachable by the address 192.168.1.129.
6
View and Manipulate Neighbors
Let’s say you want to see what other devices on your local network are present and reachable. The ip command lets you scan for “neighbors” which are local active devices that make themselves visible on the network. This can be useful for troubleshooting connection issues.
For example, I have a Raspberry Pi and a few other wired devices on my network right now. If I pass the command ip neighbor or ip neigh or simply ip n I can see their addresses listed.
There are MAC addresses shown for each entry, which can help you figure out which device is which. You’ll also see at the end of each device’s entry there’s a description of its current status like “Reachable” or “Stale” or “Delay.” This can help you figure out what, if any, issues there are with a device you’re trying to connect to.
The ip command also lets me manually edit the table of neighbors. Let’s say my Raspberry Pi located at 192.168.1.121 for some reason changed MAC addresses, and I want to quickly update my device’s neighbors list to avoid connection issues. After getting the new MAC address, 3d:2f:a2:a7:a0:74, I’d change my entry this way:
sudo ip n change 192.168.1.121 lladdr 3d:2f:a2:a7:a0:74 dev wlo1
To break a few things down, “n change” followed by the IP address determines which device I’m modifying, and “lladdr 3d:2f:a2:a7:a0:74” specifies the new MAC address, while “dev wlo1” indicates the network interface I’m using to apply the update.
If you were to follow my example, you’d want to replace the IP address, the MAC address, and the interface with the correct labels for your situation. You can also add or remove neighbors via the ip command, but I won’t dive into that in this article.
7
Check Network Routes
You can find out how your device’s internet traffic is being routed on the local network using the ip command’s “route” object. This might be useful if you’re trying to figure out connection issues. Just pass this command:
ip route
Or simply:
ip r
You can see four total unique routes: the default route to 192.168.1.1, the address of my router, and the route to 192.168.1.0/24, which defines the range for other devices connected to my local network, each of which I can access via either my “wl01” wireless interface or my “enx00e04c68143d” wired interface. Each also has a “metric” indicating how preferred the route is. The lower the metric, the more prioritized the route.
There’s a lot more to the ip command, like adding and deleting routes, and also managing tunnels. These examples though are easy and simple steps into the world of Linux networking. Next, I’d recommend checking out examples of the nc command in action, or learning how to set a static IP address in Ubuntu.