2

I need to provide a Python program allowing the user to change dynamically the network parameters of his device (IP, mask, DNS & Gateway). For example, changing his IP from 192.168.1.10/24 to 192.168.1.15/24. I don't want to run my program as root - but I can give to my user some specifics rights (for instance add the user to a group which can modify the /usr/network/interfaces file).

What I found is the pynetlinux library but it only provides IP and mask modifications and needs to be run as root (or maybe I missused it).

I could probably do it by parsing the interfaces file and running some bash/shell commands but I don't want to re-invent the wheel. I'm pretty sure some people already had my issue and did something great about it.

I'm running on Ubuntu 12.04. I would need my programm to work also on Ubuntu 14.04, CentOS and RedHat

2
  • 1
    Can you clarify if you want to modify the network configuration files or you want to change the IP address and subnet mask on the fly, like ifconfig does? Commented Apr 21, 2015 at 8:44
  • I want for instance to be able to change the local IP address (for example from 192.168.1.10/24 to 192.168.1.11/24) Commented Apr 21, 2015 at 8:48

1 Answer 1

2

You should try to create a complete list of actions your program will have to execute. I found that in a similar setting, in response to user interaction we had to:

  • modify config files (interfaces, host, resolv.conf, ...)
  • echo to sysfs to change some settings
  • start/stop certain network services
  • switch firewall configuration (we did that via init script too)

We ended up creating a Bash script with a well-defined interface that a certain non-privileged user could call with sudo from any other program.

However our dialog-based frontend was written in Bash already so we did not spend much time in looking for existing libraries which surely is worth the effort in your case.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for the examples, and yes if I don't find any library doing what I want, I'll end up writing my own bash or python script, but that would be unfortunate
You are definitely doing it in the right order :-) Good Luck.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.