
{{ $('Map tags to IDs').item.json.title }}
How to Configure Static IP in Linux
Configuring a static IP address on a Linux system is important for many servers and devices that need a consistent network identity. This tutorial will guide you through setting up a static IP on various Linux distributions, including Ubuntu, CentOS, and Debian.
1. Finding Current Network Configuration
Before you configure a static IP, it’s important to know your current network setup. Open a terminal and run:
ip addr
This command will display your current IP addresses and interfaces.
2. Configuring Static IP on Debian/Ubuntu
On Debian-based distributions such as Ubuntu, you will typically modify the /etc/netplan
or /etc/network/interfaces
file.
2.1. Using Netplan (Ubuntu 18.04 and newer)
For systems using Netplan, follow these steps:
sudo nano /etc/netplan/01-netcfg.yaml
In this file, you’ll define your static IP configuration:
network:
version: 2
ethernets:
eth0:
dhcp: no
addresses:
- 192.168.1.100/24
gateway4: 192.168.1.1
nameservers:
addresses:
- 8.8.8.8
- 8.8.4.4
Replace 192.168.1.100
with your desired static IP, and update the gateway and nameservers as necessary.
To apply the changes, run:
sudo netplan apply
2.2. Using /etc/network/interfaces
If your Ubuntu version uses /etc/network/interfaces
, edit the file with:
sudo nano /etc/network/interfaces
Add the following lines:
auto eth0
iface eth0 inet static
address 192.168.1.100
netmask 255.255.255.0
gateway 192.168.1.1
dns-nameservers 8.8.8.8 8.8.4.4
After saving the changes, restart networking:
sudo systemctl restart networking
3. Configuring Static IP on CentOS/RHEL
On CentOS and Red Hat-based systems, static IP configuration is done through network scripts located in /etc/sysconfig/network-scripts/
.
3.1. Editing the Configuration File
Locate the appropriate configuration file for your interface, usually named ifcfg-eth0
or similar:
sudo nano /etc/sysconfig/network-scripts/ifcfg-eth0
Edit or add the following lines:
DEVICE=eth0
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
Replace values as per your network settings.
3.2. Restarting the Network Service
To apply the changes, restart the network service:
sudo systemctl restart network
4. Verifying the Configuration
To verify that the static IP is correctly configured:
ip addr show eth0
This command should display your new static IP address along with other network interface details.
5. Conclusion
You have successfully configured a static IP address on your Linux system. Static IPs are essential for servers and services that need a fixed address for connectivity. Continue to explore networking tools in Linux to enhance your understanding and management of network configurations!