Pages

Tuesday, December 9, 2025

Changing the Gateway IP in Rocky Linux

 

Step 1: Find the Real Connection Name

Before you change anything, ask NetworkManager what the connection is actually called. Do not guess.

Run this command:

Bash
nmcli connection show

What to look for:

Focus on the NAME column on the far left.

NAMEUUIDTYPEDEVICE
enp1s05fb06bd0...ethernetenp1s0
Wired connection 12ad18c...ethernetenp1s0
  • In the first row, the connection name matches the device name (enp1s0).

  • In the second row, the connection is named Wired connection 1.

Copy the text from the NAME column exactly.

Step 2: Set the New Gateway

Now that you have the correct name, use nmcli to modify the configuration.

Syntax:

sudo nmcli connection modify "<CONNECTION_NAME>" ipv4.gateway <NEW_IP>

Example (If your name is "enp1s0"):

Bash
sudo nmcli connection modify "enp1s0" ipv4.gateway 192.168.0.70

Example (If your name is "Wired connection 1"):

Bash
sudo nmcli connection modify "Wired connection 1" ipv4.gateway 192.168.0.70

Step 3: Apply the Changes

Modifying the connection only updates the config file on the disk. To make it live, you must reload the interface.

Bash
sudo nmcli connection up "enp1s0"

(Replace enp1s0 with your actual connection name found in Step 1).

Step 4: Verify

Check the kernel routing table to confirm the default route has updated.

Bash
ip route show

You are looking for the line starting with default:

default via 192.168.0.70 dev enp1s0 proto static metric 100


Common Gotcha: DHCP Overrides

If you followed the steps above but ip route still shows the old gateway, your server is likely getting its IP via DHCP.

By default, DHCP provides an IP address and a gateway. The DHCP gateway will override your manual setting every time the interface comes up.

The Fix:

You need to tell NetworkManager to keep the DHCP IP address but ignore the DHCP gateway.

Bash
# 1. Ignore the automatic gateway from DHCP sudo nmcli connection modify "enp1s0" ipv4.ignore-auto-routes yes # 2. Enforce your manual gateway sudo nmcli connection modify "enp1s0" ipv4.gateway 192.168.0.70 # 3. Apply changes sudo nmcli connection up "enp1s0"

Summary

  • Don't assume the connection name is "System enp1s0".

  • Always check nmcli connection show first.

  • Remember to reload with nmcli connection up after making changes.

No comments:

Post a Comment