Home Linux Networking How to Check if Your IP Address is Static or DHCP in Linux (2024)

How to Check if Your IP Address is Static or DHCP in Linux (2024)

Linux IP Address Static or DHCP: How to Find Out.

By sk
Published: Updated: 9.3K views

Knowing whether your Linux system uses a Static or DHCP-assigned IP can be helpful for a variety of reasons. For example, if you are hosting a web server or running a game server, you will need to use a static IP address. You may also need to know your IP address if you are trying to troubleshoot a network problem. This article explains how to check if your IP address is static or assigned from DHCP in Linux.

It covers both manual and command-line methods, and includes a clear explanation of the difference between static and dynamic IP addresses.

Introduction

An IP address is a unique identifier for a device on a network. It is used to route traffic between devices and allows them to communicate with each other.

There are two types of IP addresses: static and dynamic.

  • Static IP addresses are assigned manually and remain the same until they are changed.
  • Dynamic IP addresses are assigned automatically by a DHCP server and can change over time.

Most home and office networks use DHCP to assign IP addresses to devices. This is because it is easier to manage and helps to prevent IP address conflicts.

However, there are some cases where it is necessary to use a static IP address, such as for hosting a web server or running a game server.

If you are unsure whether your IP address is static or assigned from DHCP in Linux, you can use any one of the following methods.

In Linux, you can determine if an IP address is assigned statically or via DHCP by examining the system's network configuration files or using command line tools like nmcli or by checking the lease information.

1. Determine if IP Address is Static or DHCP by Checking Network Configuration Files

For Linux systems that uses NetworkManager, you can use this method to find if an IP address is static or dynamic.

The configuration might be stored in /etc/NetworkManager/system-connections/. You can check individual connection files here.

$ sudo ls /etc/NetworkManager/system-connections/
Auto Ostechnix_jio_5g.nmconnection  Auto Sk vivo V21e 5G.nmconnection   Wired connection 1                  
Auto Ostechnix.nmconnection         Ostechnix_jio_4g.nmconnection   

For instance, to check if the 'Wired Connection 1' uses whether static IP or dynamic IP by viewing the contents of its configuration file using command:

$ sudo cat /etc/NetworkManager/system-connections/Wired\ connection\ 1

Look for a line starting with method= under [ipv4] and [ipv6] sections. If it says auto, it's DHCP. If it says manual, it's static.

[connection]
id=Wired connection 1
uuid=5cfE09f2EG-20a6-3089-8577-5269e5cf08gh
type=ethernet
permissions=
timestamp=1650630622

[ethernet]
mac-address-blacklist=

[ipv4]
address1=192.168.29.55/24,192.168.29.1
dns=8.8.8.8;
dns-search=
method=manual

[ipv6]
addr-gen-mode=eui64
dns-search=
ip6-privacy=2
method=auto

[proxy]

As you can see in the output, I have assigned static IP address to my wired Ethernet connection.

If you want to view the details of all available network connections, run:

$ sudo cat /etc/NetworkManager/system-connections/*

For Debian/Ubuntu systems or derivatives that do not use NetworkManager:

Check the /etc/network/interfaces file.

$ cat /etc/network/interfaces

If you see iface <nic-name> inet dhcp, it's using DHCP. If you see iface <nic-name> inet static, it's static.

[...]
source /etc/network/interfaces.d/*

auto lo
iface lo inet loopback

iface enp89s0 inet manual

auto vmbr0
iface vmbr0 inet static
	address 192.168.1.101/24
	bridge-ports none
	bridge-stp off
	bridge-fd 0
[...]

For older Red Hat/Fedora systems or derivatives that do not use NetworkManager:

Check the files in /etc/sysconfig/network-scripts/.

$ cat /etc/sysconfig/network-scripts/ifcfg-*

Look for a line starting with BOOTPROTO=. If it says dhcp, it's DHCP. If not, it's static.

2. Check if IP Address is Static or DHCP using nmcli Command

You can also use this method on Linux systems with NetworkManager.

The nmcli tool is a command-line client for NetworkManager. You can use it to quickly determine the source of your IP address.

$ nmcli con show [connection-name]

Replace [connection-name] with the name of your connection.

For example, to view the source of the 'Auto Ostechnix_jio_5g' connection, you would run:

$ nmcli con show 'Auto Ostechnix_jio_5g'

In the output, look for the ipv4.method or ip6.method line. If it says auto, it's DHCP. If it says manual, it's static.

The output will be usually long. So you can use grep command like below to filter the exact details you want.

$ nmcli con show 'Auto Ostechnix_jio_5g' | grep ipv4.method
ipv4.method:                            auto

As you can see in the above output, the IP address is dynamically assigned using a DHCP server in my network.

If you want to view the source of the IP version 6, replace ipv4.method with ipv6.method in the above command.

3. Find if IP Address is Static or Dynamic by Checking DHCP Lease Information

The DHCP client on Linux typically logs its activity, and you can inspect these logs to find if an IP address was obtained via DHCP. Additionally, the DHCP client usually stores its lease information in a lease file.

For the dhclient:

The lease file is often located at /var/lib/dhcp/dhclient.leases or /var/lib/dhclient/dhclient.leases.

$ cat /var/lib/dhcp/dhclient.leases

If you see recent leases in this file, then the system has been obtaining its IP via DHCP.

Remember, the method to check can vary based on the Linux distribution and the version, as well as which networking tools are in use (NetworkManager, traditional ifup/ifdown, systemd-networkd, etc.). The methods provided above cover many common scenarios, but not every potential configuration.

Conclusion

In this brief guide, we discussed a few ways to check if your IP address is static or dynamically allocated from a DHCP server. Understanding whether your system uses a Static or DHCP-assigned IP can be beneficial for troubleshooting a network issue in Linux. Pick a method that suits you and determine your IP's origin in a matter of seconds.

Related Read: How To Configure Static IP Address In Linux And Unix

You May Also Like

Leave a Comment

* By using this form you agree with the storage and handling of your data by this website.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

This website uses cookies to improve your experience. By using this site, we will assume that you're OK with it. Accept Read More