3

The settings I'm talking about are IP, subnet mask and default gateway (set and get). For setting all of these I use the ioctl function along with options like SIOCSIFADDR and SIOCSIFNETMASK. For getting the IP and mask I use the same approach but with options like SIOCGIFADDR. For getting default gateway I parse the file /proc/net/route and read the corresponding default gateway address for the interface.

This whole thing works perfectly, but with root privilege. Is there any method to change these settings without giving root user ? This is a requirement which I could not resolve. Changing the ownership like this question may solve the problem by putting the code inside a separate executable and change ownership of that executable to root then calling it from the main application.

I just want to know if it is possible to change such settings without giving root access to the application.

Community
  • 1
  • 1
3bdalla
  • 407
  • 1
  • 10
  • 28

1 Answers1

5

There are two ways i know of:

  1. Use sudo to run ifconfig and route as root. Sudo can be set up to work without password and only for some programs.

  2. Use capabilities see the answer to Is there a way for non-root processes to bind to "privileged" ports on Linux? and use CAP_NET_ADMIN insted of cap_net_bind_service.

Community
  • 1
  • 1
rasmusm
  • 599
  • 2
  • 8
  • 2
    what is `=+ep` in the accepted answer in the question you provided ? – 3bdalla Feb 17 '15 at 10:49
  • 1
    OK basically it works (at least with this ep option). But I have a question since I have only added `CAP_NET_ADMIN`, shall I assume that if there is any root operation other than network configuration executed in the application it will not be executed ? – 3bdalla Feb 17 '15 at 11:08