Modifying the Path To Include sbin
Posted 10-3-2010 by
Matthew Downey
If you are running Red Hat or CentOS and have added a user to /etc/sudoers, you may be perplexed by the fact that you cannot run ifconfig with sudo:
[matt@localhost ~]$ sudo ifconfig sudo: ifconfig: command not found
This is because /sbin is not in the current user's path. If we run the following command, it works:
[matt@localhost ~]$ sudo /sbin/ifconfig
eth0 Link encap:Ethernet HWaddr 08:00:27:6E:BC:67
inet addr:192.168.1.114 Bcast:192.168.1.255 Mask:255.255.255.0
inet6 addr: fe80::a00:27ff:fe6e:bc67/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:576 errors:0 dropped:0 overruns:0 frame:0
TX packets:528 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:73739 (72.0 KiB) TX bytes:42611 (41.6 KiB)
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:1148 errors:0 dropped:0 overruns:0 frame:0
TX packets:1148 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:1945296 (1.8 MiB) TX bytes:1945296 (1.8 MiB)The solution is to modify the user's .bash_profile and add /sbin to the user's path. We might as well add /usr/sbin to the path, too, to avoid other surprises. Open up .bash_profile with your favorite text editor, and find the following line:
PATH=$PATH:$HOME/bin
Modify it so it looks like this:
PATH=$PATH:$HOME/bin:/sbin:/usr/sbin
Save the file, and logout of GNOME and then log back in. Now sudo ifconfig should behave as expected.