When you need a Linux system to have a static IP address rather than one that is set dynamically by DHCP, all that's required is some configuration changes and a restart. Follow these steps to make the switch. Credit: Uqbar is back IP addresses on Linux systems are often assigned automatically by Dynamic Host Configuration Protocol (DHCP) servers. These are referred to as “dynamic addresses” and may change any time the system is rebooted. When a system is a server or will be remotely administered, however, it is generally more convenient for these systems to have static addresses, providing stable and consistent connections with users and applications. Fortunately, the steps required to change a Linux system’s IP address from dynamic to static are fairly easy, though they will be a little different depending on the distribution you are using. In this post, we’ll look at how this task is managed on both Red Hat (RHEL) and Ubuntu systems. There’s no simple command that you can run to determine whether the IP address on a Linux system is assigned by DHCP or static. If it changes when the system restarts, it’s clearly dynamically assigned, but even a dynamic address has some resistance to change. The best way is to look at the configuration file. More on this in the sections below. RHEL 8 To configure a static IP address on a Red Hat system, let’s start by listing NetworkManager’s connection. The nmcli command shown below will list network connections and devices on the system. Note that the device names and the connection names are not the same. $ nmcli dev status DEVICE TYPE STATE CONNECTION wlo1 wifi connected Comtrend7FB9 virbr0 bridge connected virbr0 enp3s0 ethernet unavailable -- lo loopback unmanaged -- virbr0-nic tun unmanaged -- To change the network interface from dynamic to static, you need to edit the file in the /etc/sysconfig/network-scripts directory that represents the public interface. In this example, it’s called ifcfg-Comtrend7BF9 (ifcfg- followed by the name of the connection). The boot protocol “BOOTPROTO=dhcp” line needs to be changed to “BOOTPROTO=static”. In addition, the IP address to be used has to be added to the file. The end result will look something like this (NOTE: Don’t add the “arrows” inserted below to highlight the lines you need to focus on): HWADDR=7C:67:2A:CF:EF:9F ESSID=Comtrend7FB9 MODE=Managed KEY_MGMT=WPA-PSK SECURITYMODE=open MAC_ADDRESS_RANDOMIZATION=default TYPE=Wireless IPADDR=192.168.0.22 static Run the command systemctl restart NetworkManager after the changes have been made to make the changes effective. Ubuntu 18.10 The nmcli (network manager command line interface) command can be used to list the network interfaces on an Ubuntu system. In the output below, we see both a loopback and a public network interface listed. The device on your system may have a different name. This one that reflects the location of the hardware. Ubuntu> nmcli d DEVICE TYPE STATE CONNECTION enp0s25 ethernet unmanaged -- lo loopback unmanaged -- To examine the network interface configuration settings on an Ubuntu system, you would use a command like this: Ubuntu> cat /etc/network/interfaces # interfaces(5) file used by ifup(8) and ifdown(8) auto lo iface lo inet loopback auto enp0s25 iface enp0s25 inet dhcp You can see from the last line in this output that the eth0 interface is currently assigned by DHCP. To change the setting to dynamic, you would change "dhcp" to "static" and add some other lines as well. For example, in the file as shown below, we have changed dhcp to static and specified the IP address we want to use along with other settings: # interfaces(5) file used by ifup(8) and ifdown(8) auto lo iface lo inet loopback auto enp0s25 iface enp0s25 inet static address 192.168.0.11 netmask 255.255.255.0 network 192.168.0.0 broadcast 192.168.0.255 Restart the networking service or reboot the system to make the changes effective. Wrap-up Changing network settings should be done only when the changes will not affect current connections and you can back out the changes if needed. It's always a good idea to make a copy of any configuration file before you make changes. Giving your backup copy a predictable name such as interfaces.prev, interfaces.orig or interfaces- will make it a little easier to identify. Related content how-to How to find files on Linux There are many options you can use to find files on Linux, including searching by file name (or partial name), age, owner, group, size, type and inode number. By Sandra Henry Stocker Jun 24, 2024 8 mins Linux opinion Linux in your car: Red Hat’s milestone collaboration with exida With contributions from Red Hat and critical collaborators, the safety and security of automotive vehicles has reached a new level of reliability. By Sandra Henry Stocker Jun 17, 2024 5 mins Linux how-to How to print from the Linux command line: double-sided, landscape and more There's a lot more to printing from the Linux command line than the lp command. Check out some of the many available options. By Sandra Henry Stocker Jun 11, 2024 6 mins Linux how-to Converting between uppercase and lowercase on the Linux command line Converting text between uppercase and lowercase can be very tedious, especially when you want to avoid inadvertent misspellings. Fortunately, Linux provides a handful of commands that can make the job very easy. By Sandra Henry Stocker Jun 07, 2024 5 mins Linux PODCASTS VIDEOS RESOURCES EVENTS NEWSLETTERS Newsletter Promo Module Test Description for newsletter promo module. Please enter a valid email address Subscribe