Convert IP Address from DHCP to Static Using NMCLI

Convert IP address from DHCP to Static Using NMCLI

Learn how to easily convert your IP address from DHCP to static using NMCLI. Follow our step-by-step guide for seamless configuration on Linux systems.

Table of Contents

Introduction

Are you tired of dealing with fluctuating IP addresses assigned by your DHCP server? Maybe you’re setting up a server or a networked device that needs a stable, static IP address. Fear not! In this guide, we’ll walk you through the process of converting your IP address from DHCP to static using NMCLI.

Convert IP address from DHCP to Static Using NMCLI

Understanding DHCP vs. Static IP Addresses

Before we delve into the conversion process, let’s quickly distinguish between DHCP and static IP addresses:

  • Dynamic Host Configuration Protocol (DHCP): This protocol automatically assigns IP addresses to devices within a network. It’s convenient for environments where devices frequently join and leave the network, as it manages IP address allocation dynamically.

  • Static IP Address: In contrast, a static IP address is manually configured for a device and remains constant. It’s beneficial for devices that require a consistent IP address for tasks like hosting servers or accessing networked services reliably.

Why Convert to a Static IP Address?

There are several reasons why you might want to switch from DHCP to a static IP address:

ReasonDescription
Server ConfigurationEnsures consistent accessibility when setting up a server.
Networked DevicesRequired for devices like printers, NAS, or IoT devices for reliable communication.
Port Forwarding

Essential for enabling external access to specific services via port forwarding on your network.

Using NMCLI for IP Address Conversion

NMCLI, or Network Manager Command-Line Interface, is a powerful tool for managing network configurations in Linux-based systems. Here’s how you can use NMCLI to convert your IP address from DHCP to static:

Step 1: Check Current Network Configuration

Before making any changes, it’s essential to know your current network configuration. Open a terminal window and enter the following command:

				
					nmcli connection show
				
			
				
					NAME                UUID                                  TYPE      DEVICE 
Wired connection 1  2193e2e3-933e-30cd-9923-835f65f8788c  ethernet  eno1   
lo                  2c17ece3-8e43-451a-ba10-83a283138dea  loopback  lo     
Verizon_7X8KZK      daadd47b-31fa-494c-b951-d0409be5d620  wifi      --     

				
			

This command will display (see sample output above) a list of network connections along with their settings.

Step 2: Identify the Connection to Modify

Identify the network connection for which you want to switch to a static IP address. Note down its name; it usually follows the format “enoX” or “ethX,” or “enpX”, where X is a number.

Step 3: Convert to Static IP Address

Now, let’s convert the selected connection to use a static IP address. Replace “ConnectionName” with the name of your network connection and adjust the IP address, gateway, and DNS servers according to your network configuration:

				
					sudo nmcli connection modify ConnectionName ipv4.method manual ipv4.address 192.168.1.100/24 ipv4.gateway 192.168.1.1 ipv4.dns 8.8.8.8
				
			

In this command:

  • ipv4.method manual sets the IP address assignment method to manual (static).
  • ipv4.address specifies the desired static IP address and subnet mask.
  • ipv4.gateway defines the default gateway for the network.
  • ipv4.dns sets the DNS server address.

Step 4: Apply Changes

Apply the changes to activate the new network configuration:

				
					sudo nmcli connection up ConnectionName
				
			

Congratulations! You’ve successfully converted your IP address from DHCP to static using NMCLI.

Conclusion

Converting your IP address from DHCP to static provides stability and control over your network configuration. With NMCLI, the process is straightforward and can be accomplished with just a few commands in the terminal. Whether you’re setting up a server or configuring networked devices, switching to a static IP address ensures consistent connectivity and smoother operations.

Did you find this article useful? Your feedback is invaluable to us! Please feel free to share your thoughts in the comments section below.

Related Posts

Leave a Reply

Your email address will not be published. Required fields are marked *