Select Page

Introduction

The ip command in Linux is used to configure network interfaces in a Linux machine. It is short for Internet Protocol. It is mostly used by system and network administrators to add, remove, show and manipulate things like network routes, tunnels, etc. 

In the early days before the ip command was a thing, Linux users had to use a command called ifconfig to fulfill these tasks. However, that command is deprecated and lacks a lot in many ways as compared to the ip command. In other words, it can be called a successor to the ifconfig command. 

However, many users seem to have issues running the ip command in their Linux machines, and have faced the following error message:

$ ip: command not found 

My task in this article would be to help you eradicate this error message, in case you’re unable to run the command yourself and are facing a similar problem. 


Why is the ip command not found?

Most distributions don’t have the package which contains the ip command installed by default. Instead, you’d find the ifconfig command installed by default in most distributions, given that it is quite the old dog in the game of interface management tools. Nevertheless, you’ll first need to install the package which contains the ip command, in order to be able to run it. 

If however, you’re 100% sure that you’ve already installed the command but are still not able to execute it, then you’ll need to fix your path variable so that your system can trace for the command when you try to execute it.  

In the following sections, we’ll discuss both of these fixes in detail.


Install the ip command in Linux

Hold your seats tight, comrades! Because we’re about to enter the vast world of Linux distributions and their package managers (I do exaggerate sometimes, but this one deserves it all by itself). The fact that there are more than 600 active Linux distributions at present (no, they’re not deprecated) is insane, and this insanity brings more trouble than good. Many Distribution developers like to give in their very own package managers and repositories.

But luckily, more than half of these distributions are actually based on some top-tier distributions who’ve been dominating Linux most. These include distributions like Ubuntu, Arch Linux, Fedora, and Debian. When distributions are forked, they usually use the same package manager for their distributions too, so you probably won’t need to worry much as long as you’re using one of these, or at least know that your system is based on one of these.

Moving on, these are some of the commands you’d need to execute in your terminal emulator in order to install the package which contains the ip command. Be careful about using the right package manager listed under the name of your specific distribution, as otherwise you’d end up getting even more error messages:

Arch Linux

$ sudo pacman -Syu
$ sudo pacman -S iproute2

Ubuntu

$ sudo apt-get update
$ sudo apt-get install iproute2

Debian

$ sudo apt-get update
$ sudo apt-get install iproute2

Fedora

$ sudo yum makecache
$ sudo yum install iproute2

CentOS

$ sudo dnf makecache
$ sudo dnf install iproute2

RedHat

$ sudo dnf makecache
$ sudo dnf install iproute2

Kali Linux

$ sudo apt-get update
$ sudo apt-get install iproute2

MacOS (using Homebrew)

$ brew update
$ brew install iproute2mac

The first line of command is important as it refreshes your local database for the package manager. The second line of command installs the iproute2 package which contains the ip command. (There are tips online where it is said that the net-tools package also contains the ip command, but it actually doesn’t).

Once the installation is over, you should be able to run the ip command now. If you’re still getting the error message, there’s one thing left to be done.


Fix your path variable

The ip command is stored in the /sbin directory, which may not be listed in your system’s global PATH variable. As a result, you’d not be able to run the command unless you append the /sbin path. To do this, we need to use the export command, and insert a line under your shell’s configuration file. If you’re using the Bourne Again Shell, then there should be a hidden file in your home directory called .bashrc. Open the file using the text editor you like and append the following line in it:

$ export PATH=$PATH:/sbin/

Save and exit the file, and then restart your terminal emulator for changes to take effect. This time around, you should successfully be able to run the ip command in your Linux machine! 


Alternatives to ip command

Whether or not you like it, the possibility of encountering situations when you’re unable to even install the ip command should not be avoided, especially when you’re using some mysterious distribution, which does not have the package in its repository, or doesn’t even have a package manager in the first place! (Yeah, there’s one I’ve seen called RancherOS). Even if it is not your situation, you might as well consider knowing about a few alternatives of the ip command (just in case):

  • ifconfig (it’s deprecated, but is still capable. You’ll find it preinstalled in most systems)
  • ipconfig (use this if you’re in Windows)
  • netstat (works in conjunction with the ifconfig command)