Marcio Cunha

How to set static IP on Linux using NetworkManager

Learn how to fix the IP address on headless Linux servers using the nmcli command-line tool from NetworkManager.

Marcio Cunha•3 min
Also available in:PortuguêsEspañol
Summary
  • NetworkManager automates network connections across modern Linux distributions seamlessly.
  • The nmcli utility enables changing network parameters directly via the terminal without graphical software.
  • Identifying the exact network interface name prevents errors when applying new IP rules.
  • Setting static addresses avoids unwanted changes caused by automatic router lease renewals.
  • Validating the new configuration ensures stable connectivity before touching production environments.

Why use a static IP on Linux servers?

When setting up a local or cloud server, we must ensure it can always be found at the exact same network address. In practice, this means the router cannot change the computer's number every time it reboots. If you host internal services or databases, a dynamic address causes constant connection failures. Knowing how to use advanced tools like monitoring TCP connections on Linux helps understand the traffic reaching this fixed machine.

In modern Linux distributions, NetworkManager has become the industry standard for controlling network cards, cables, and Wi-Fi connections. Although famous on laptops with graphical screens, it runs flawlessly on servers operating purely via text (headless mode). The big secret to mastering this manager without a mouse is the command-line tool named nmcli.

How to find your network interface name

Before changing any settings, we need to find the technical name of the network card we want to modify. In the past, they were all called eth0, but today systems use names based on physical hardware location, like enp3s0 or wlan0. To list all active cards and check current status, we use a simple terminal command.

Run the command below to list available connections on the system:

nmcli device status

In the command output, you will see a column indicating the device type and the connection name associated with it. Note down this exact name, as it is mandatory for the next steps. If you want to investigate general network performance before tweaking settings, you can learn how to check switch latency via SNMP to isolate physical issues.

Step-by-step to set a static IP with nmcli

Now that we know our interface name, let's create or modify the connection profile to use a fixed IP address, subnet mask, default gateway, and DNS servers. The nmcli utility alters these parameters and applies them immediately without requiring complex operating system reboots.

Follow this sequence of commands in the terminal to configure the static IP definitively:

  1. Identify the active profile by running
    nmcli connection show
  2. Modify the IP address and network mask with the command
    nmcli connection modify "ConnectionName" ipv4.addresses 192.168.1.50/24
  3. Define the default gateway providing internet access
    nmcli connection modify "ConnectionName" ipv4.gateway 192.168.1.1
  4. Insert primary and secondary DNS server addresses
    nmcli connection modify "ConnectionName" ipv4.dns "8.8.8.8, 1.1.1.1"
  5. Change the configuration method from automatic to manual
    nmcli connection modify "ConnectionName" ipv4.method manual

How to apply and validate network changes

After altering connection properties, changes are not yet active on the physical network card. We need to restart the profile so NetworkManager applies the new IP values. If you make a typo, the connection might drop immediately, so executing these steps via physical console or redundant access is recommended.

To reload and activate the modified connection, use the following command:

nmcli connection up "ConnectionName"

With the connection active, verify if the new address was applied correctly using the ip addr command. If any connectivity issues arise, diagnostic tools such as using netstat for active connections assist in identifying lost routes or closed ports on the machine.

Final considerations on Linux network administration

Configuring static IP addresses via command line with nmcli ensures autonomy and agility when administering servers without a graphical interface. Mastering this tool prevents dependence on legacy configuration files that change across different Linux distribution versions. Keeping the network organized and predictable is the first step toward building a robust, secure infrastructure ready to scale smoothly.