Fix 'bash: command not found' for ifconfig and other tools on Linux
Missing commands like ifconfig? Here's the fix. Start with installing the missing package (30 sec), then check your PATH, or reinstall core tools.
You type ifconfig and get bash: ifconfig: command not found. I've been there—on a fresh Ubuntu 22.04 install, staring at a blinking cursor, wondering if my network card even exists. Don't panic. This error usually means the command wasn't installed, not that your system is broken.
Here's the fix chain. Start with the quickest option—30 seconds. If that doesn't work, move to the next. You'll be back to poking at your network settings in no time.
The 30-Second Fix: Install the missing package
On modern Linux distros (Ubuntu 20.04+, Debian 11+, CentOS 8+, Fedora 36+), many classic commands like ifconfig aren't included by default. They've been replaced by ip from the iproute2 package. But if you need the old-school tool, just install it.
For Debian/Ubuntu:
sudo apt update && sudo apt install net-toolsFor CentOS/RHEL/Fedora:
sudo dnf install net-toolsThat's it. After that, ifconfig should work. Same goes for route, arp, and netstat—they're all in the net-tools package.
If you're on a minimal install like a Docker container or a bare-bones server, you might also need to install iproute2 for ip:
sudo apt install iproute2But here's my advice: learn ip instead. It's the modern replacement. ip addr replaces ifconfig, ip route replaces route, ip neigh for arp. But I get it—old habits die hard, and scripts still use ifconfig. So install net-tools and move on.
The Moderate Fix (5 minutes): Check your PATH variable
If you installed the package and still get the error, your shell might not be looking in the right places. The PATH environment variable tells bash where to find executables. If /sbin or /usr/sbin isn't in your PATH, commands like ifconfig (which live in /sbin) won't be found.
Check your PATH:
echo $PATHIf you don't see /sbin or /usr/sbin, you need to add them. This is common on some user accounts or custom installs. For a one-time fix in the current session:
export PATH=$PATH:/sbin:/usr/sbinThen try ifconfig again. If it works, make it permanent by adding that line to your ~/.bashrc file:
echo 'export PATH=$PATH:/sbin:/usr/sbin' >> ~/.bashrc && source ~/.bashrcThis happens more often than you'd think—especially on headless servers or when you've switched from root to a regular user. I've tripped over this myself after creating a new user and forgetting to copy over the skeleton files.
The Advanced Fix (15+ minutes): Reinstall or repair core packages
If the command still isn't found at this point, something's gone wrong with your package manager or your system's file structure. Maybe you accidentally removed a critical package, or your package database is corrupted.
Start by checking if the package is actually installed:
dpkg -l | grep net-toolsor on RPM-based systems:
rpm -qa | grep net-toolsIf it shows as installed but the binary doesn't exist, the package files might be missing. Reinstall it:
sudo apt install --reinstall net-toolsStill no luck? Let's verify the package manager itself isn't broken. On Debian/Ubuntu, run:
sudo apt --fix-broken install && sudo apt update && sudo apt upgradeOn CentOS/Fedora:
sudo dnf distro-syncThis will realign your installed packages with what's in the repository. Don't be surprised if it wants to remove or reinstall a bunch of things—that's normal.
If even that doesn't work, you might have a symlink issue. Check where the binary should be:
which ifconfigShould return something like /sbin/ifconfig. If it returns nothing, the file might be missing. List the /sbin directory:
ls -la /sbin/ | grep ifconfigIf it's not there but net-tools is installed, your package manager's file list might be wrong. Re-download and install the .deb or .rpm manually:
For Debian/Ubuntu:
apt download net-tools && sudo dpkg -i net-tools*.debFor CentOS/Fedora:
dnf reinstall net-toolsWorst case: your system's filesystem is read-only (common in recovery mode). Check with:
mount | grep ' / 'If it shows ro (read-only), remount it:
mount -o remount,rw /Then repeat the reinstall steps.
One more weird one: if you're inside a container like Docker, some minimal images (e.g., alpine) don't use apt or dnf. For Alpine, use apk:
apk add net-toolsFor busybox containers, you might need to install a full net-tools package explicitly.
Honestly, 95% of the time the 30-second fix is all you need. But if you're reading this from a rescue shell at 3 AM, you've got options.
Was this solution helpful?