Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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?

share|improve this question

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

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

2 Answers 2

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

share|improve this answer
    
Note: You may also examine /var/run/dhclient.eth0.pid (or whichever interface you want...) –  anishsane Jun 16 '14 at 5:47

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

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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