Determine if it's a static IP or a DHCP IP

36,864

Solution 1

If its CentOS, you can check /etc/sysconfig/network-scripts/ifcfg-eth0. Check BOOTPROTO entry says. If its dhcp then its DHCP configured. If its Static or none, then its not DHCP

Solution 2

The problem is, if you're using NetworkManager, for example, it's going to be requesting an IP and gateway and DNS server. But beyond that, once it's got the information it needs, it sets addressing information essentially statically. Essentially, the rest of your machine doesn't know or care if an address is static or dynamic, just that it has an address.

You can check /var/log/syslog for DHCPACK entries specifically. I believe dhclient and NetworkManager write there.

Solution 3

You have the command in nmcli.
This should work in all Linux flavors, I believe:

nmcli -f ipv4.method con show eno16780032

If the output is auto, then it is DHCP.
If the output is manual, then it is static.

Solution 4

Type in terminal

cat /etc/network/interfaces

You should find one of this lines

iface eth0 inet dhcp

that means that IP for interface eth0 is from DHCP

iface eth0 inet static

Above line shows that IP is static. You should also find other parameters.

Share:
36,864

Related videos on Youtube

Neetz
Author by

Neetz

Updated on September 18, 2022

Comments

  • Neetz
    Neetz over 1 year

    I'm trying to find a genric solution across all linux distro to find if the IP address attached to the system is a static or a DHCP ?

    On ubuntu , I can find if it's static or DHCP by doing a DHCP grep on /var/log/syslog but it is not generic solution , it might differ on other platforms.

    One of the target board is Cortina and I'm using open wrt as a boot up kernel for that. There is no var/log/syslog on Cortina nothing similar to that also.

    • Kinnectus
      Kinnectus almost 9 years
      If you ifconfig <your_interface> and look at the flags listed, you may be able to find "DHCP" - this may be a little more generic across distros
    • Neetz
      Neetz almost 9 years
      @BigChris ifconfig interface doesn't display anything about the type of connection :/
    • qasdfdsaq
      qasdfdsaq almost 9 years
      In that case there's no method universal across all linux distros. There is a syslog on openwrt though which will tell you this though. It's just not a file.
    • Kinnectus
      Kinnectus almost 9 years
      I only did a quick look up and came across this resource: unix.com/unix-for-dummies-questions-and-answers/…
  • Magick
    Magick over 6 years
    What does it mean if the result is iface lo inet loopback?
  • brainLoop
    brainLoop over 4 years
    cat: /etc/network/interfaces: No such file or directory ON Fedora 29
  • G-Man Says 'Reinstate Monica'
    G-Man Says 'Reinstate Monica' over 4 years
    I get  “Error: ‘con’ command ‘show’ is not valid.”
  • DustWolf
    DustWolf over 2 years
    Use -g instead of -f for batch-friendly.