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?

link|improve this question

50% accept rate
feedback

migrated from stackoverflow.com Jun 9 '11 at 16:10

This question came from our site for professional and enthusiast programmers.

2 Answers

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

link|improve this answer
feedback

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

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

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