I’ve actually written about ifconfig not found before, but noticed recently another possible scenario so will mention it today.
Make Sure Net-Tools Package is Installed
This is still the most common reason for your shell not finding the ifconfig command: it’s just not installed by default. So install it using apt command:
$ apt install net-tools
Call ifconfig Using Full Path
This is the thing I noticed on my Debian VM earlier today: your regular user may not have /sbin directory in its PATH. Which means ifconfig command will still not work if you just type the command name:
greys@debian9:~$ ifconfig
-bash: ifconfig: command not found
You have new mail in /var/mail/greys
But if you type the full path to the command, it will work:
Edit the .profile file in your home directory. For me it’s /home/greys/.profile.
Somewhere towards the end of it there should be a PATH variable updates section, on my VM it includes linuxbrew that I installed recently:
set PATH so it includes user's private bin if it exists
if [ -d "$HOME/bin" ] ; then
PATH="$HOME/bin:$PATH"
fi
PATH=$PATH:/home/greys/.linuxbrew/bin
eval $(/home/greys/.linuxbrew/bin/brew shellenv)
We need to update this section. And if there isn’t one, just create another one at the end of the file. Both changes should aim to add /sbin directory to the PATH variable.
Update the file:
PATH=$PATH:/home/greys/.linuxbrew/bin
… with this:
PATH=$PATH:/home/greys/.linuxbrew/bin:/sbin
… or create new one:
PATH=$PATH:/sbin
Save the file and read it again to test:
greys@debian9:~$ source .profile
/home/greys/.linuxbrew/Homebrew/Library/Homebrew/brew.sh: line 4: warning: setlocale: LC_ALL: cannot change locale (en_US.UTF-8): No such file or directory
I'm a principal consultant with Tech Stack Solutions. I help with cloud architectrure, AWS deployments and automated management of Unix/Linux infrastructure. Get in touch!