Fix “ifconfig: command not found” Error

The ifconfig command is used to configure the network interface in Linux. This command helps us to allocate a unique address to the network interface and fetch the current network configuration details. The developers have depreciated this command due to lack of maintenance and upgraded it with the “ip” command in the “iproute2” package.

The older versions still have the ifconfig command by default, but the new versions show the  “ifconfig: command not found” error. This guide will help you to remove this error, and it includes these topics:

Let’s begin!

How to Fix the “ifconfig: command not found” Error?

The ifconfig (interfaces configuration) command is utilized to check the network interface configuration and change it. It helps to give useful data about the network interface of the system.

How to install Kali Linux in Window...

The ifconfig command was a built-in utility in the previous versions of the Linux distros, but the developers did not update and maintain it regularly, so this command is depreciated. In the latest versions, when you run the “ifconfig” command, it shows this error:

Error: Command ‘ifconfig’ not found”

Let’s discuss the possible solutions for this error.

Reason 1: net-tools Package is Missing

The ifconfig command exists within the net-tools package in Linux. For executing the ifconfig command, we must install the missing “net-tools” package, which does not come by default on installing the Operating System.

Solution 1: Install & Configure net-tools Package

$ sudo apt install net-tools                 #for Ubuntu.
$ sudo dnf install net-tools                 #for Fedora & CentOS.
$ sudo pacman -S net-tools                   #for Arch Linux

For installing the net-tools package in different distributions, execute the following commands:

The net-tools package is installed in the system. Let’s run the ifconfig command now!

If it still shows the same error “ifconfig: command not found” error, we must install it manually. Let’s do it!

Fix Error After Installing the net-tools Package

To remove the error after installing the net-tools package, follow the below steps

  • Check ifconfig Path
  • Resolve Issues with the ifconfig Path
  • Restart the system

Step 1: Check ifconfig Path

We can check the existence of the ifconfig path binary in the system, with the “/sbin/ifconfig” directory, which contains its system variables to perform the desired tasks. To check in Linux, use any of the below-mentioned commands:

Note: The output must include the “usr/sbin/” file if the binary path exists.

For Debian-Based Distros:

$ which ifconfig                                    #must display path
$ [[ -f /sbin/ifconfig ]] && echo "ifconfig Exists" #must display ifconfig exists
$ [ -e /sbin/ifconfig ] && echo “ifconfig Exists”   #must display ifconfig exists

For Fedora:

$ sudo yum whatprovides ifconfig

For RPM-based Distros:

$ sudo rpm -qf /usr/sbin/ifconfig

If the binary does not exist, we must reinstall the net-tools package. Otherwise, the output shows the binary exists, and we can move to the next step.

Step 2: Resolve Issues with the ifconfig Path

The ifconfig exists in the “/sbin” or “/usr/sbin” directory. The several distros do not include this in the PATH variable. To include the PATH variable, first, use the following command to check the path variable:

$ echo $PATH

The output must include the “/sbin” path, and you can use the ifconfig command.

If the output shows the “/sbin” path, you must export/manually add the missing PATH variable to that directory. For that, utilize this command:

$ export PATH="/sbin:/usr/sbin:${PATH}"

Step 3: Restart the system

Restart the system with the below command and use the ifconfig command error-free:

$ sudo reboot

Let’s work on the next solution.

Reason 2: ifconfig Replaced With ip Command

The ifconfig command is present within the net-tools package utility, replaced with the iproute2 utility package from Ubuntu 18.04. For others, the net-tools package is not available by default on the latest distros. The modern alternative of the ifconfig command is the “ip” command utility in the iproute2 package utility.

Solution 2: Use ip Command

The ifconfig command provides the details about the network interface that can be accessed using the ip command in the system by default. The “ip addr” command provides the same details about the network configuration as the ifconfig command. Run any of the below commands to check the behavior of the ip command (alternative of ifconfig):

$ ip a
$ ip addr

The output shows the “ip addr” command provides:

  • Network Interface: Displays the network interface like ens33.
  • ip Address:  The local server ip address.
  • mac Address: The mac address of the machine.

The ip command comes up with advanced built-in functions from the “ifconfig”. This ip command shows the statistics (s), human-readable mode (h), details (d), configuration colors (c), and other useful details for ip address & its configuration.

The options in the “ip” command include:

-sTo show statistics. ($ ip -s addr)
-hTo display in human readable mode.
-dFor details of ip.
-cFor configuration of output colors.
-rResolve the ip address to the mac address.

That’s the end of the post.

Conclusion

The ifconfig error can be removed by installing & configuring the “net-tools” package. Use commands “sudo apt install net-tools”, “sudo dnf install net-tools”, and  “sudo pacman -S net-tools” commands for  Debian, Fedora/CentOS, and Arch-based Linux distros, respectively. This article guides you through the possible reasons and their solutions to fix the “ifconfig: command not found” error.