I have a number of systems each with two Ethernet interfaces on machines running Ubuntu 16.04.

One interface will always be setup as static and the other interface will always be setup as DHCP. I have no way of guaranteeing the names of the interfaces will be constant from one deployed system to another.

Is there a command I can issue from the command line to figure out which one is static and which one is dynamic without having to know what the IP address would have to be specifically for one or the other?

I'm trying to automate detection of a dropped static IP connection. I've gotten as far as using the command ip link show to find names of all the interfaces and once I know the name of the static interface I can use ethtool interface_name to determine whether or not the connection has link detected. But I just can't figure out a good way to go and figure out which one is the static link

I don't want to have to go look at /etc/network/interfaces btw. Don't want to tie myself to that method as I may not always use that file to set the static IP.

I also can't go issue a command to see which interface has an active dhcp address using a command like more /var/lib/dhcp/dhclient.leases because I can't guarantee that both interfaces won't be down at the same time.

Thanks for any help you can give me

Did find these after posting, looks like it may not be possible to do what I'm wanting, I may have to resort to parsing /etc/network/interfaces after all or having to use the scripting services of ifup or NetworkManager. . .

Check if IP is static or dynamic programmatically https://unix.stackexchange.com/questions/44376/how-to-find-out-if-ubuntu-is-using-dhcp-ubuntu-12-04-lts-gui

  • Just curious, what other methods would you use to set the static IP? Network Manager? – wjandrea Jul 25 '17 at 15:47
  • Yes exactly, I'm trying to keep it so that network manager use wouldn't make my script not work. Maybe it's not possible, I'm sure banging my head against a wall with what seems like would be an easy thing to do! – Brian Jul 25 '17 at 15:54
  • Hmm... I don't know much about this, but maybe you could scan both /etc/networking/interfaces and the Network Manager config files. – wjandrea Jul 25 '17 at 15:58
  • If the DHCP server is set, for example, to assign addresses from x.10 to x.199 and you set static IPs from x.200 to x.253, does that help because only static addresses and interfaces are x.200 and higher? – chili555 Jul 25 '17 at 20:46

Your Answer

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

Browse other questions tagged or ask your own question.