How to Fix "ifconfig: Command not Found" on Linux

July 23, 2024

Introduction

The ifconfig command is a legacy tool used to configure network interfaces in Linux. Even though the utility was deprecated and replaced with the ip command, ifconfig is still used often. Configuring the network interfaces on your Linux system with ifconfig may result in the "ifconfig: command not found" error.

This guide explains how to fix the "ifconfig: command not found" error using one of the four methods. 

How to fix "ifconfig: command not found" on Linux - a tutorial.

Prerequisites

How to Fix ifconfig Command Not Found?

The ifconfig command is part of the net-tools package, a Linux network utility deprecated because of a lack of maintenance and IPv6 support. While certain distributions still come with net-tools preinstalled, others don't, which can cause this error.

For example:

Example of the ifconfig command not found error in Linux.

The error can occur because the system does not have net-tools or because the ifconfig directory is not added to the standard PATH variable.

The following sections explain how to fix the "ifconfig: command not found" issue.

Option 1: Install net-tools

The most straightforward solution to resolving the issue is to install the net-tools package. Most Linux distributions support net-tools, although it might not be pre-installed in some of them. This section outlines how to install net-tools in several common Linux distros.

Debian-based Distros (Ubuntu, Debian, Linux Mint, etc.)

Follow the steps below to install net-tools on Debian-based distributions:

1. Update the system package repository information to ensure you get the latest package version. Run the following command:

sudo apt update

2. Install net-tools with apt:

sudo apt install net-tools
Installing net-tools to fix the ifconfig not found error in Linux.

RHEL-based Distros (Rocky Linux, Red Hat Enterprise Linux, Fedora, etc.)

This section outlines the steps for installing net-tools on RHEL-based distros. Follow the instructions depending on the package manager you are using, dnf or yum:

Rocky Linux and RHEL:

1. Refresh the system package repository information with:

sudo yum update

2. Install net-tools with:

sudo yum install net-tools

Fedora:

1. Update the system package repository information with:

sudo dnf update

2. Run the command below to install net-tools:

sudo dnf install net-tools

Arch-based Distros (Arch Linux, Manjaro, etc.)

The steps below show how to install net-tools on Arch-based Linux distributions:

1. Refresh the system package repository information:

sudo pacman -Sy

2. Install net-tools with:

sudo pacman -S net-tools

Verify Installation

After installing net-tools on your system, run ifconfig to confirm the installation:

ifconfig
ifconfig command output in Ubuntu.

If the system still prints the same error as before the installation and does not execute ifconfig even after installing net-tools, move on to the following sections and try a different approach.

Option 2: Use the Full Path to the Command

If installing net-tools does not resolve the issue, try running the command with the full path. Sometimes, ifconfig may not be in the user's PATH environment variable. Running it with the full path ensures it is executed correctly.

Follow the steps below:

1. Use the which command to find the full path of the ifconfig command:

which ifconfig
Find ifconfig command path with which.

2. Run ifconfig as a regular user. Prepend the command with the full path you obtained in the previous step. For example:

usr/sbin/ifconfig
Running ifconfig with full path specified.

This method is a workaround, but it requires users to remember the path, which is not practical if you plan to use ifconfig often.

Option 3: Update the System PATH Variable

The "ifconfig: command not found" issue often occurs when the system installs ifconfig in /sbin/, which is not a part of the standard user PATH variable. By default, regular users cannot invoke ifconfig unless they use the full path when running the command or use sudo.

However, using sudo or the entire path for the command to work is not practical in the long run. When you run ifconfig multiple times, it is best to add the /sbin/ directory to the PATH variable permanently.

If you have root privileges on your system, follow the steps below to add the ifconfig command to PATH:

1. Edit the .profile file in Vim, nano or another text editor.

sudo nano /etc/profile

Note: To set up ifconfig for the current user only, change the $HOME/.profile file. To make changes system-wide, edit /etc/profile.

2. Go to the end of the file and paste the following line:

export PATH=$PATH: /sbin/

3. Save and close the file.

4. Reboot the system to apply the changes. Save any changes, close running apps, and run:

sudo reboot

5. Run ifconfig to check if it works:

ifconfig

Option 4: Run ifconfig with sudo or as root

Another way to run ifconfig without adding the command to PATH is to use sudo or switch to root with su. If you only need to execute ifconfig once, use sudo instead of su since the former is a safer option:

sudo ifconfig

Using ip Command Instead of ifconfig

While effective, ifconfig is deprecated, and most systems are moving to ip as the go-to utility for network configuration. The ip tool is installed by default on most distributions.

Run the command without any options to see the basic functions:

ip
ip command output in Linux.

The ip command prints the list of network interfaces with the link show arguments:

ip link show
Print network interfaces with the ip command.

For more information about the utility and how to use it, check out our comprehensive ip command tutorial with practical hands-on examples.

Conclusion

After reading this tutorial, you know how to fix the ifconfig: command not found error in Linux. Although deprecated, ifconfig is still used across different Linux distributions.

Next, see how to fix the SSH failed permission denied error, or learn how to change the hostname in Debian 10.

Was this article helpful?
YesNo
Sara Zivanov
Sara Zivanov is a technical writer at phoenixNAP who is passionate about making high-tech concepts accessible to everyone. Her experience as a content writer and her background in Engineering and Project Management allows her to streamline complex processes and make them user-friendly through her content.
Next you should read
How to Install and Use ifconfig on CentOS 7
December 23, 2024

The ifconfig command is a tool for network interface management that is used to...
Read more
Best Tools to Monitor Network Bandwidth on a Linux Server
September 19, 2024

There are many different tools for monitoring network traffic...
Read more
What is SNMP (Simple Network Management Protocol)?
October 20, 2022

This article explains what SNMP is, its basic components, and how it woks. See which network...
Read more
How to Find or Check Your IP Address in Linux
November 17, 2023

An IP address is a code assigned to a computer on a network. It works as a postal...
Read more