Lodaer Img

Configure Static IP Address in CentOS

A static IP keeps a server reachable at the same address after every reboot. On a VPS the address is assigned to you, but CentOS still has to be told to use it — and how you do that changed between CentOS 7 and CentOS 8/9. This guide covers both, and how to recover if you lock yourself out.

Before you start: changing network settings over SSH can disconnect you. Check that your provider’s control panel gives you console access first, and note the address, subnet mask, gateway and DNS servers you were assigned.

1. Which method applies to your version

VersionConfigure withNotes
CentOS 7network-scripts, or nmcliReached end of life in June 2024; no further security updates.
CentOS 8nmcli (NetworkManager)network-scripts deprecated.
CentOS 9 / Streamnmcli or keyfilenetwork-scripts removed entirely.

2. Find your interface and current settings

Interface names vary — eth0, ens3 and enp1s0 are all common on VPS instances:

ip addr show ip route show nmcli device status

The interface holding your current address is the one to edit, and the default route line shows your gateway.

3. CentOS 7: network-scripts

Edit the file for your interface, for example /etc/sysconfig/network-scripts/ifcfg-eth0:

TYPE=Ethernet BOOTPROTO=none NAME=eth0 DEVICE=eth0 ONBOOT=yes IPADDR=203.0.113.25 PREFIX=24 GATEWAY=203.0.113.1 DNS1=1.1.1.1 DNS2=8.8.8.8

BOOTPROTO=none turns DHCP off, and ONBOOT=yes brings the interface up at boot — the setting most often behind a server that loses its address after a reboot. Then apply it:

systemctl restart network

4. CentOS 8, 9 and Stream: nmcli

List the connection first, then set each property on it:

nmcli connection show nmcli connection modify “System eth0” ipv4.addresses 203.0.113.25/24 nmcli connection modify “System eth0” ipv4.gateway 203.0.113.1 nmcli connection modify “System eth0” ipv4.dns “1.1.1.1 8.8.8.8” nmcli connection modify “System eth0” ipv4.method manual nmcli connection modify “System eth0” connection.autoconnect yes nmcli connection up “System eth0”

Use the connection name exactly as nmcli connection show prints it — it is not always the device name. ipv4.method manual is the part that disables DHCP.

5. Editing the NetworkManager keyfile

On CentOS 9 and Stream, connections live in /etc/NetworkManager/system-connections/ as .nmconnection files:

[connection] id=eth0 type=ethernet interface-name=eth0 autoconnect=true [ipv4] method=manual address1=203.0.113.25/24,203.0.113.1 dns=1.1.1.1;8.8.8.8;

The file must be owned by root with mode 600 or NetworkManager ignores it. Reload afterwards:

chmod 600 /etc/NetworkManager/system-connections/eth0.nmconnection nmcli connection reload nmcli connection up eth0

6. Verify the configuration

ip addr show ip route show cat /etc/resolv.conf ping -c 3 1.1.1.1 ping -c 3 google.com

If pinging an IP works but a hostname does not, the address and gateway are correct and the remaining problem is DNS.

7. Troubleshooting

  • Address disappears after rebootONBOOT=yes missing on CentOS 7, or connection.autoconnect off under NetworkManager.
  • No connectivity at all — usually a wrong gateway, or one outside the subnet you configured.
  • Changes appear to be ignored — on CentOS 8 and 9, editing network-scripts does nothing because NetworkManager owns the interface. Use nmcli.
  • Locked out over SSH — reconnect on the old address if it still answers, otherwise use the provider console and check ip addr.
  • Duplicate address — if another machine already uses the IP, both behave erratically. Confirm the address is yours before assigning it.
  • Firewall blocks the port — the address can be right while firewalld drops traffic. Check with firewall-cmd –list-all.

8. Keeping SSH access while you work

Keep your existing session open and test the new address from a second terminal before closing the first. If the server becomes unreachable, the provider console is the fallback — which is why it is worth confirming you have one before you start.

Running this on a VPS? Everything above applies to KwikServer Linux VPS instances, where the assigned address, gateway and DNS servers are listed in your control panel.

Leave a Reply

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