Setting a Static IP Address on Linux: A Comprehensive Guide

In the world of networking, having a static IP address can provide numerous benefits, including improved security, easier network management, and better compatibility with certain applications. If you're a Linux user looking to set a static IP address, you've come to the right place. In this guide, we'll walk you through the process step by step, ensuring you understand each step along the way.

Understanding Static IP Addresses
Before we dive into the process, let's briefly discuss what a static IP address is. Unlike dynamic IP addresses, which can change each time you connect to the internet, a static IP address remains the same. This is particularly useful in scenarios where you need to access your device remotely or run a server.

Why Set a Static IP Address?
- Remote Access: A static IP address allows others to connect to your device remotely.
- Server Hosting: Many services require a static IP address to function correctly.
- Network Configuration: Static IP addresses simplify network configuration and troubleshooting.

Preparation: Gather Required Information
Before you begin, you'll need to gather some information about your network and the device you want to configure:
- IP Address: The static IP address you want to set. Ensure this address is within your network's range and not already in use.
- Subnet Mask: The subnet mask for your network. This is usually 255.255.255.0 for home networks.
- Gateway: The IP address of your router. This is typically 192.168.1.1 or 192.168.0.1 for home networks.
- DNS Servers: The IP addresses of your DNS servers. You can usually use your ISP's DNS servers or opt for public ones like Google's (8.8.8.8 and 8.8.4.4).

Setting a Static IP Address on Popular Linux Distributions
While the process of setting a static IP address can vary slightly between Linux distributions, we'll provide guidance for some of the most popular ones.
Ubuntu

In Ubuntu, you can set a static IP address using the netplan utility, which is a modern network configuration tool.
First, create a new configuration file:




















sudo nano /etc/netplan/01-netcfg.yaml
Then, add the following content, replacing the placeholders with your gathered information:
network:
version: 2
renderer: networkd
ethernets:
ens33: # replace with your network interface name
addresses: [192.168.1.100/24] # replace with your IP address and subnet mask
gateway4: 192.168.1.1 # replace with your gateway
nameservers:
addresses: [8.8.8.8,8.8.4.4] # replace with your DNS servers
Finally, apply the new configuration:
sudo netplan apply
CentOS/Fedora
In CentOS and Fedora, you can use the nmcli command-line tool to set a static IP address. Here's how:
sudo nmcli con modify "your_connection_name" ipv4.addresses 192.168.1.100/24 ipv4.gateway 192.168.1.1 ipv4.dns "8.8.8.8 8.8.4.4"
Replace your_connection_name with the name of your network connection. You can find this by running nmcli connection.
Arch Linux
In Arch Linux, you can use the netctl service to manage network profiles. Here's how to create a new profile with a static IP address:
sudo nano /etc/netctl/profile
Add the following content, replacing the placeholders with your gathered information:
Description='My static IP profile'
Interface='eth0' # replace with your network interface name
Connection='wireless' # or 'ethernet' depending on your connection type
IP='static'
Address='('192.168.1.100'/24)' # replace with your IP address and subnet mask
Gateway='192.168.1.1' # replace with your gateway
DNS('8.8.8.8' '8.8.4.4') # replace with your DNS servers
Then, enable and start the new profile:
sudo systemctl enable netctl@profile
sudo systemctl start netctl@profile
Verifying Your Static IP Address
After configuring your static IP address, you can verify it using the ip command:
ip addr
Look for your network interface (e.g., eth0 or wlan0) and ensure the IP address matches the one you set.
Conclusion
Setting a static IP address on Linux can be a straightforward process once you understand the basics. By following this guide, you should now be able to configure a static IP address on your preferred Linux distribution. Happy networking!