Setting a static IP address in Linux ensures your machine always uses the same network identifier on the local network. If you’re wondering how to configure ip address in linux, you’ve come to the right place. This guide covers both command-line and GUI methods for major distributions like Ubuntu, Debian, Fedora, and CentOS. Whether you’re a sysadmin or a home user, you’ll find step-by-step instructions that work.
Network configuration can seem tricky at first, but it’s actually quite straightforward once you know the tools. We’ll walk through the most common approaches, from the classic ifconfig to modern ip commands and configuration files. By the end, you’ll be able to set a static IP on any Linux system.
Why Set A Static IP Address In Linux
Most networks use DHCP to assign IP addresses automatically. This works fine for laptops and phones, but servers and network devices often need a fixed address. A static IP ensures services like SSH, web servers, or file shares are always reachable at the same location.
Static IPs also help with port forwarding, DNS settings, and network troubleshooting. If you’re running a home lab or a production server, knowing how to configure ip address in linux is an essential skill.
Prerequisites For Configuring IP In Linux
Before you start, make sure you have:
- Root or sudo access to your Linux machine
- Your network interface name (like eth0, ens33, or wlp2s0)
- The desired IP address, subnet mask, gateway, and DNS servers
- Backup of existing network configuration files
You can find your interface name with the command ip link show or nmcli device status. Write it down before proceeding.
How To Configure Ip Address In Linux Using Command Line
This is the most common method for servers and headless systems. We’ll cover both temporary and permanent changes.
Temporary IP Configuration With Ip Command
The ip command is the modern replacement for ifconfig. It changes the IP address immediately but doesn’t survive a reboot.
- Open a terminal and become root:
sudo -i - Bring the interface down:
ip link set eth0 down - Assign a new IP:
ip addr add 192.168.1.100/24 dev eth0 - Bring the interface up:
ip link set eth0 up - Add a default gateway:
ip route add default via 192.168.1.1
Verify with ip addr show eth0. This method is great for testing but not for permanent setups.
Permanent Configuration Using Netplan (Ubuntu 18.04+)
Modern Ubuntu uses Netplan for network configuration. YAML files in /etc/netplan/ control the settings.
- List Netplan files:
ls /etc/netplan/ - Edit the file (usually
01-netcfg.yaml):sudo nano /etc/netplan/01-netcfg.yaml - Add or modify the configuration:
network:
version: 2
renderer: networkd
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 - Check with
ip addr show eth0
Netplan is clean and easy to read. Make sure YAML indentation is correct—two spaces, no tabs.
Permanent Configuration Using /Etc/network/interfaces (Debian/Ubuntu Old Style)
Older Debian-based systems use the /etc/network/interfaces file. This method still works on many distributions.
- Open the file:
sudo nano /etc/network/interfaces - Add these lines for a static IP:
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
- Restart networking:
sudo systemctl restart networking - Verify with
ifconfigorip addr
This method is reliable but less common on newer systems.
Permanent Configuration Using Nmcli (NetworkManager)
Desktop Linux distributions often use NetworkManager. The nmcli tool lets you configure IP from the command line.
- List connections:
nmcli con show - Modify the connection:
nmcli con mod "Wired connection 1" ipv4.addresses 192.168.1.100/24 - Set method to manual:
nmcli con mod "Wired connection 1" ipv4.method manual - Add gateway:
nmcli con mod "Wired connection 1" ipv4.gateway 192.168.1.1 - Add DNS:
nmcli con mod "Wired connection 1" ipv4.dns "8.8.8.8 8.8.4.4" - Apply changes:
nmcli con up "Wired connection 1"
Nmcli is powerful and works with NetworkManager’s GUI settings.
How To Configure Ip Address In Linux Using GUI
If you’re using a desktop environment like GNOME, KDE, or Xfce, you can set a static IP through the network settings panel.
GNOME (Ubuntu, Fedora Workstation)
- Open Settings > Network
- Click the gear icon next to your wired or wireless connection
- Go to the IPv4 tab
- Change “Automatic (DHCP)” to “Manual”
- Enter your IP, netmask, gateway, and DNS
- Click Apply and toggle the connection off/on
This method is intuitive and doesn’t require terminal commands.
KDE Plasma
- Open System Settings > Connections
- Select your connection and click Configure
- Go to the IPv4 tab
- Choose “Manual” method
- Add your IP address with CIDR notation
- Enter gateway and DNS servers
- Click OK and reconnect
KDE’s interface is slightly different but equally simple.
Configuring IP On Red Hat / CentOS / Fedora (Older Versions)
Enterprise Linux distributions use different configuration files. For CentOS 7 and older Fedora versions, you edit /etc/sysconfig/network-scripts/ifcfg-eth0.
- Open the file:
sudo nano /etc/sysconfig/network-scripts/ifcfg-eth0 - Set these parameters:
DEVICE=eth0
BOOTPROTO=static
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 network service:
sudo systemctl restart network - Verify with
ip addr
For RHEL 8 and later, NetworkManager is the default, so use nmcli instead.
Common Mistakes When Configuring IP In Linux
Even experienced users make errors. Here are the most frequent ones:
- Using the wrong subnet mask (e.g., /24 vs /16)
- Forgetting to set the default gateway
- Typing the wrong interface name
- Not restarting the network service after changes
- Using an IP address already in use on the network
- Incorrect YAML indentation in Netplan files
Always double-check your settings with ip addr and ip route.
Verifying Your Static IP Configuration
After making changes, confirm everything works:
- Check IP address:
ip addr show eth0 - Check routing:
ip route show - Test connectivity:
ping 8.8.8.8 - Test DNS:
nslookup google.com - Check from another device:
ping 192.168.1.100
If ping fails, check your firewall and ensure the gateway is reachable.
How To Configure Ip Address In Linux For Multiple Interfaces
Some systems have multiple network cards. You can assign different static IPs to each interface.
For example, eth0 might be your internal network (192.168.1.x) and eth1 your external (10.0.0.x). Simply repeat the steps above for each interface, using different configuration files or YAML sections.
Make sure each interface has its own gateway if they connect to different networks. You can also set policy routing for more complex setups.
Automating IP Configuration With Scripts
If you manage many Linux machines, scripting saves time. Here’s a simple bash script for Netplan-based systems:
#!/bin/bash
INTERFACE="eth0"
IP="192.168.1.100/24"
GATEWAY="192.168.1.1"
DNS="8.8.8.8,8.8.4.4"
cat > /etc/netplan/01-netcfg.yaml <
Run the script with sudo. Adjust variables for each machine.
How To Configure Ip Address In Linux With Dhcpcd
Some lightweight distributions use dhcpcd instead of NetworkManager. You can still set a static IP by editing /etc/dhcpcd.conf.
- Open the config file:
sudo nano /etc/dhcpcd.conf - Add at the end:
interface eth0
static ip_address=192.168.1.100/24
static routers=192.168.1.1
static domain_name_servers=8.8.8.8 8.8.4.4
- Restart dhcpcd:
sudo systemctl restart dhcpcd
This method is common on Raspberry Pi OS and Arch Linux.
How To Configure Ip Address In Linux For Wifi
Wireless interfaces work the same way as wired ones. The interface name is usually wlan0 or wlp2s0.
For NetworkManager, use nmcli with your WiFi connection name. For Netplan, add the interface under wifis: instead of ethernets:.
network:
version: 2
wifis:
wlan0:
dhcp4: no
addresses: [192.168.1.100/24]
gateway4: 192.168.1.1
nameservers:
addresses: [8.8.8.8]
access-points:
"MyWiFi":
password: "mypassword"
Make sure to include the WiFi SSID and password in the configuration.
Troubleshooting IP Configuration Issues
If your static IP isn't working, try these steps:
- Run
sudo systemctl status networkingornetwork-manager - Check logs:
journalctl -xe | grep network - Verify no other service is overriding your settings
- Use
dhclient -rto release any old DHCP lease - Check for duplicate IPs with
arp-scan - Reboot the machine to ensure persistence
Most issues are caused by typos or misconfigured gateways.
How To Configure Ip Address In Linux Using Systemd-Networkd
Systemd-networkd is another option for network management. It's lightweight and works well on servers.
- Create a .network file:
sudo nano /etc/systemd/network/10-eth0.network - Add:
[Match]
Name=eth0
[Network]
Address=192.168.1.100/24
Gateway=192.168.1.1
DNS=8.8.8.8
- Enable and start systemd-networkd:
sudo systemctl enable --now systemd-networkd - Restart the service:
sudo systemctl restart systemd-networkd
This method is clean and integrates well with systemd.
How To Configure Ip Address In Linux With Ifconfig (Legacy)
While ifconfig is deprecated, it's still available on many systems. Use it for quick temporary changes.
- Bring interface down:
sudo ifconfig eth0 down - Set IP:
sudo ifconfig eth0 192.168.1.100 netmask 255.255.255.0 - Bring interface up:
sudo ifconfig eth0 up - Add gateway:
sudo route add default gw 192.168.1.1
This method is not persistent and should be avoided for production systems.
How To Configure Ip Address In Linux With Ssmtp
Wait, that's a typo—I meant ssmtp is for email, not IP. But if you're configuring a mail server, you'll need a static IP first. The steps above apply.
How To Configure Ip Address In Linux For Containers
Docker and LXC containers often need static IPs for consistent access. You can assign IPs during container creation or edit the container's network config.
For Docker, use the --ip flag with a custom network:
docker network create --subnet=192.168.1.0/24 mynet
docker run --net mynet --ip 192.168.1.100 myimage
For LXC, edit the container's config file in /var/lib/lxc/container/config.
How To Configure Ip Address In Linux With Ansible
If you manage multiple servers, Ansible can automate IP configuration. Here's a simple playbook:
- hosts: all
become: yes
tasks:
- name: Set static IP
nmcli:
conn_name: "eth0"
type: ethernet
ip4: "192.168.1.100/24"
gw4: "192.168.1.1"
state: present
Run it with ansible-playbook set-ip.yml. This ensures consistency across