1

I'm trying to determine whether my IP has been statically or dynamically assigned in Ubuntu 11.04 from within C. The closest I've come is examining /var/lib/dhcp/dhclient.leases, but that doesn't change if a static IP is assigned (as it caches DHCP leases for future connection attempts).

So... is there a command line utility (for Ubuntu) that will allow me to check if DHCP is enabled or disabled?

Alternatively: the machine is a server dedicated to one application; would it be easier just to maintain an environment variable that keeps track of DHCP status?

1

In theory if you dhcp is enabled, you should have dhclient running. So one (albeit kludgey) way to do it would be simply:

ps ax | grep dhclient | grep eth0 (or whichever interface you want).

But you may also want to try "nmcli con" which will tell you "Auto eth0" (I think) if it's a dhcp interface.

Also take a look at nm-tool

HTH

1
  • Note: You may also examine /var/run/dhclient.eth0.pid (or whichever interface you want...) – anishsane Jun 16 '14 at 5:47
0

It may be possible through NetworkManager's DBUS API but source of IP address doesn't pop out in the list of interfaces, try discussing with the developers of said application.

http://projects.gnome.org/NetworkManager/developers/spec.html

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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