Operations 8 min read

How to Configure Static and Dynamic IP Addresses on Ubuntu, CentOS, and openSUSE

This guide explains IP address basics, special and private ranges, and provides step‑by‑step commands to set up static or dynamic networking on Ubuntu (pre‑ and post‑18.04), CentOS/Red Hat (5‑8), and openSUSE, highlighting the use of NetworkManager and legacy tools.

Open Source Linux
Open Source Linux
Open Source Linux
How to Configure Static and Dynamic IP Addresses on Ubuntu, CentOS, and openSUSE

First, understand the concept of IP addresses.

IP Address Overview

Essential components for connecting a computer to the Internet: IP address + subnet mask + gateway + DNS IP address is the unique identifier for network access.

IPv4 address classes:

IPv4 addresses are divided into five classes A‑E; classes A, B, C are basic, while D and E are used for multicast and reserved purposes.

Special addresses:

0.0.0.0 – default route, e.g., ip route-static 0.0.0.0 0.0.0.0 10.10.10.1 255.255.255.255 – all hosts on the local subnet

127.0.0.1 – localhost, loopback address

224.0.0.1 – multicast address for all hosts

169.254.x.x – automatic IP assigned by Windows when DHCP fails

Private addresses: (used within enterprises, not routed on the Internet)

10.x.x.x

172.16.x.x – 172.31.x.x

192.168.x.x

1. Configuring IP on Ubuntu

1) Ubuntu versions before 18.04

# vi /etc/network/interfaces
auto enp10s0
iface enp10s0 inet static
address 192.168.1.2
netmask 255.255.255.0
gateway 192.168.1.1
dns-nameservers 114.114.114.114,8.8.8.8
# /etc/init.d/networking restart   # restart network

2) Ubuntu 18.04 and later

# vi /etc/netplan/50-cloud-init.yaml
network:
  version: 2
  renderer: networkd
  ethernets:
    enp10s0:
      dhcp4: no
      addresses: [192.168.1.3/24]
      gateway4: 192.168.1.1
      nameservers:
        addresses: [114.114.114.114,8.8.8.8]
# netplan try   # validate configuration
# netplan apply # apply without validation

If you prefer the older method, install the ifupdown package:

apt install ifupdown

2. Configuring IP on CentOS / Red Hat

1) CentOS/RedHat 5.x‑7.x

# vi /etc/sysconfig/network-scripits/ifcfg-eth0
DEVICE=eth0
ONBOOT=yes
TYPE=Ethernet
BOOTPROTO=static
IPADDR=192.168.1.4
NETMASK=255.255.255.0
GATEWAY=192.168.1.1
DNS1=114.114.114.114
DNS2=8.8.8.8
# service network restart   # restart network service

2) CentOS/RedHat 8.x

CentOS 8 is newer; use nmcli commands.

# Create static IP configuration for ens33
nmcli connection add type ethernet con-name ens33 ifname ens33 ipv4.addresses 192.168.1.5/24 ipv4.gateway 192.168.1.1 ipv4.method manual
# Create dynamic IP configuration for ens33
nmcli connection add type ethernet con-name ens33 ifname ens33 ipv4.method auto
# Modify IP non‑interactive
nmcli connection modify ens33 ipv4.addresses 192.168.1.6/24
nmcli connection up ens33
# Modify IP interactively
nmcli connection edit ens33
# then use the nmcli prompts to change the address, set method to manual, save and activate
# Show current configuration
nmcli

Note: From CentOS 8/RHEL 8 onward, the traditional network.service is deprecated; network configuration is managed by NetworkManager. To keep using the old service, install it with yum install network-scripts.

3. Configuring IP on openSUSE

# vi /etc/sysconfig/network/ifcfg-eth0
DEVICE=eth0
ONBOOT=yes
BOOTPROTO=static
IPADDR=192.168.1.8
NETMASK=255.255.255.0
GATEWAY=192.168.1.1
# service network restart   # restart network

Conclusion

NetworkManager is a powerful tool for managing network settings across major Linux distributions, offering command‑line, text‑based, graphical, and web interfaces, with extensive parameters and broad compatibility.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

LinuxCentOSUbuntuopenSUSEIP Configuration
Open Source Linux
Written by

Open Source Linux

Focused on sharing Linux/Unix content, covering fundamentals, system development, network programming, automation/operations, cloud computing, and related professional knowledge.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.