This article explains how to configure a network and set a static IP address in Linux.
This means manually assigning a fixed IP address to a Linux system instead of letting it automatically receive one from a DHCP server (like a router). This is usually useful for servers, printers, or systems needing access remotely.
Why Set a Static IP in Linux?
- For remote access (SSH)
- For running a server (e.g., web server, FTP server)
- To avoid IP conflicts
- For consistent network configurations
To Set Static IP in Linux
The steps to set static IP in Linux depend on your Linux distribution and whether you are using nmcli, netplan, ifconfig, or editing config files directly.
For Ubuntu 18.04+ (uses Netplan)
-
- Edit the Netplan config file (usually located in /etc/netplan/):
sudo nano /etc/netplan/01-netcfg.yaml
- Example static IP configuration:
network: version: 2 ethernets: eth0: dhcp4: no addresses: - 192.168.1.100/24 gateway4: 192.168.1.1 nameservers: addresses: - 8.8.8.8 - 8.8.4.4
- Apply the changes:
sudo netplan apply
- Edit the Netplan config file (usually located in /etc/netplan/):
For CentOS/RHEL (uses ifcfg files)
- Edit the interface config file:
sudo nano /etc/sysconfig/network-scripts/ifcfg-eth0
- Set the static IP like this:
BOOTPROTO=none ONBOOT=yes IPADDR=192.168.1.100 NETMASK=255.255.255.0 GATEWAY=192.168.1.1 DNS1=8.8.8.8 DNS2=8.8.4.4
- Restart the network service:
sudo systemctl restart network
Using nmcli (Network Manager CLI tool)
nmcli con mod “Wired connection 1” ipv4.addresses 192.168.1.100/24 nmcli con mod “Wired connection 1” ipv4.gateway 192.168.1.1 nmcli con mod “Wired connection 1” ipv4.dns “8.8.8.8 8.8.4.4” nmcli con mod “Wired connection 1” ipv4.method manual nmcli con up “Wired connection 1”
In this manner, you can configure a network and set a static IP address in Linux. If you require help, feel free to contact our support staff.
Complete your Linux network setup! Check out How to set up a Linux static and persistent hostname