1

I have a python application running in Ubuntu and it needs to be able to change a network interface between static and dynamic network configuration (IP, gateway, subnet, and DNS) on the fly. The application is NOT running as root.

I could change the privileges of /etc/network/interfaces to allow modification by non-root users, but this is not preferable.

I could set the interface to use DHCP in /etc/network/interfaces, all the time, and set the static configuration after boot using ifconfig, route, and writing /etc/resolvconf/resolv.conf.d/head for DNS. Two issues with this approach 1) Negotiating with DCHP will give me a DNS server. I know that by writing to /etc/resolvconf/resolv.conf.d/head, it will attempt this first, but I don't want to fall back on the DNS server provided by DHCP, at all (to be able to detect issues with static DNS server that is set). I know I could set /etc/dhcp/dhclient.conf to not ask for DNS server, but then I have to modify that configuration file when the user switches between static/dynamic (which is also root owned). And 2) I don't want to use up a DHCP lease each time at boot and then change to static.

So...if you were writing a non-root application, how would you allow changing between static/dynamic configuration on the fly? A requirement when using static configuration, is that the user can set DNS server, and the OS will not use any DNS server provided by DHCP. Ideally, files owned by root, would not be modified.

1 Answer 1

0

Solution found. I'm going to set auto eth0 in /etc/network/interfaces, with a static config, but no IP/gateway/subnet/DNS. My application starts on boot. When the application starts, if the user has set dynamic, I'll call "dhclient -r eth0" to get DHCP configuration. If the user has set static, I'll use ifconfig, route, and /etc/resolvconf/resolv.conf.d/head to set config.

This allows my application to configure static/dynamic, without having root privileges. There's no need to modify /etc/network/interfaces. There's no need to modify /etc/dhcp/dhclient.conf. I can set static config, with static DNS, and avoid using DNS provided by DHCP in static mode. All without modifying any root owned files.

2
  • How are you configuring network interfaces (via dhclient or ifconfig) without running as root?
    – nobody
    Jun 3, 2014 at 16:10
  • A good question. The answer is, it's just how our project is setup. The user running the application has sudo privileges to those tools already. I should have mentioned that in the original post. Jun 4, 2014 at 14:52

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.