Privileges for ifconfig
In order to do ifconfig
in Linux and change the IP and VIP does it require root privileges?
Or it is also possible to do this via a non-root account?
Solution 1:
You do not need root access to use ifconfig
to change IP addresses, only CAP_NET_ADMIN. Let's create a copy of ifconfig
with CAP_NET_ADMIN
enabled to see this:
cp /sbin/ifconfig .
sudo setcap cap_net_admin=eip ./ifconfig
./ifconfig eth0 1.2.3.4 # succeeds
# Wouldn't want to leave this copy of ifconfig around,
# It's a security hole!
rm ifconfig
Solution 2:
Yes, you must be root for use ifconfig since it is usually located in /usr/sbin
or /sbin
directory. Being non-root, ifconfig binary is not even in your PATH environment variable.
So, you should be root, or sudo must be set up.
But the modern way is to use ip
utility from iproute2
packet. You could use it under non-privileged user to see info about links, interfaces and routing. However, you must be root to change the settings.