How To Set Static Ip Linux – Steam Startup Optimization

If you need to assign a fixed address to your machine, learning how to set static ip linux is essential. This guide walks you through the process using simple commands and configuration files.

Dynamic IPs change over time, which can break server connections or remote access. A static IP stays the same, making it ideal for servers, printers, or any device that needs consistent network identification.

We will cover both modern and traditional methods. You will learn how to configure static IPs on Ubuntu, Debian, CentOS, and other major distributions.

Understanding Static IP In Linux

A static IP address is manually assigned to your network interface. Unlike DHCP, which automatically assigns addresses, a static IP remains constant.

This is useful for services like SSH, web servers, or file sharing. It also prevents connection issues when your router reboots.

Before you start, gather the following information:

  • Your desired static IP address
  • Subnet mask (usually 255.255.255.0)
  • Default gateway (router IP)
  • DNS server addresses (like 8.8.8.8)

You can find your current network details using the ip addr or ifconfig command. Note the interface name, typically eth0, ens33, or wlan0.

How To Set Static Ip Linux Using Netplan (Ubuntu 18.04+)

Netplan is the default network configuration tool on modern Ubuntu versions. It uses YAML files for configuration.

First, locate the Netplan configuration file. It is usually in /etc/netplan/ and ends with .yaml.

  1. Open the file with sudo: sudo nano /etc/netplan/01-netcfg.yaml
  2. Replace the contents with the following example:
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]

Adjust the interface name, IP address, gateway, and DNS as needed. The /24 indicates the subnet mask.

Apply the changes with sudo netplan apply. Verify the new IP using ip addr show eth0.

If you encounter errors, check the YAML syntax carefully. Indentation matters in YAML files.

Netplan Configuration For Wireless Interfaces

For WiFi, the configuration is similar but uses the wifis section. Here is an example:

network:
  version: 2
  wifis:
    wlan0:
      dhcp4: no
      addresses:
        - 192.168.1.101/24
      gateway4: 192.168.1.1
      nameservers:
        addresses: [8.8.8.8]
      access-points:
        "YourSSID":
          password: "YourPassword"

Replace wlan0 with your wireless interface name. The SSID and password must be in quotes.

Setting Static IP On Debian And Older Ubuntu Versions

Older distributions use the /etc/network/interfaces file. This method is still common on Debian-based systems.

Open the file with sudo: sudo nano /etc/network/interfaces

Find the section for your interface. It might look like this:

auto eth0
iface eth0 inet dhcp

Change it to:

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

Save the file and restart the networking service: sudo systemctl restart networking

Check the new IP with ip addr. If the service fails, reboot the system.

Configuring Static IP On CentOS, RHEL, And Fedora

Red Hat-based systems use network scripts in /etc/sysconfig/network-scripts/. The file is named ifcfg-eth0 or similar.

Open the file: sudo nano /etc/sysconfig/network-scripts/ifcfg-eth0

Edit it to look like this:

TYPE=Ethernet
BOOTPROTO=static
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
ONBOOT=yes

Save the file and restart the network service: sudo systemctl restart network

On newer Fedora versions, NetworkManager is used. You can also set a static IP via the nmcli command-line tool.

Using Nmcli For Static IP

First, list your connections: nmcli con show

Then modify the connection:

sudo nmcli con mod "System eth0" ipv4.addresses 192.168.1.100/24
sudo nmcli con mod "System eth0" ipv4.gateway 192.168.1.1
sudo nmcli con mod "System eth0" ipv4.dns "8.8.8.8 8.8.4.4"
sudo nmcli con mod "System eth0" ipv4.method manual
sudo nmcli con up "System eth0"

This method works on most modern distributions that use NetworkManager.

Setting Static IP Using The Command Line (Ip Command)

You can temporarily set a static IP using the ip command. This change is lost after a reboot.

sudo ip addr add 192.168.1.100/24 dev eth0
sudo ip route add default via 192.168.1.1

Add DNS servers by editing /etc/resolv.conf:

nameserver 8.8.8.8
nameserver 8.8.4.4

This method is useful for testing or temporary configurations.

How To Set Static Ip Linux On Arch Linux

Arch Linux uses systemd-networkd by default. Create a network file in /etc/systemd/network/.

Create a file like 20-wired.network:

[Match]
Name=eth0

[Network]
Address=192.168.1.100/24
Gateway=192.168.1.1
DNS=8.8.8.8

Enable and start the service: sudo systemctl enable --now systemd-networkd

Alternatively, you can use Netctl or NetworkManager on Arch.

Verifying Your Static IP Configuration

After applying changes, always verify the configuration. Use these commands:

  • ip addr show – Check the IP address on your interface
  • ip route show – Verify the default gateway
  • ping 8.8.8.8 – Test internet connectivity
  • ping your-router-ip – Test local network

If ping fails, double-check the gateway and DNS settings. Also ensure no IP conflicts on your network.

Troubleshooting Common Static IP Issues

Here are common problems and solutions:

  • No network after reboot: Check if the configuration file is correct and the service is enabled.
  • IP conflict: Ensure the static IP is outside the DHCP range of your router.
  • DNS not working: Verify the DNS servers in the configuration file.
  • Interface name wrong: Use ip link show to find the correct interface name.

If you are using a graphical desktop, network managers like NetworkManager might override your settings. Disable them if needed.

How To Set Static Ip Linux On Raspberry Pi (Raspbian)

Raspberry Pi OS is based on Debian. The configuration depends on the version.

For older versions, edit /etc/network/interfaces. For newer versions (based on Debian 10+), use dhcpcd.conf.

Edit /etc/dhcpcd.conf:

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

Reboot the Pi to apply changes.

Using Graphical Tools To Set Static IP

Most desktop environments offer a network settings GUI. You can set a static IP there.

On GNOME, go to Settings > Network > Wired/WiFi > Gear icon > IPv4 tab. Choose Manual and enter the details.

On KDE, go to System Settings > Connections > Select connection > IPv4 tab.

These tools modify the same configuration files behind the scenes.

How To Set Static Ip Linux For Multiple Interfaces

If your system has multiple network interfaces, configure each one separately. For example, eth0 and wlan0 can both have static IPs.

Ensure each interface uses a different IP address on the same subnet. Otherwise, routing conflicts may occur.

You can also set up policy routing if needed, but that is more advanced.

Automating Static IP Configuration With Scripts

You can create a bash script to apply static IP settings quickly. Here is a simple example:

#!/bin/bash
INTERFACE="eth0"
IP="192.168.1.100/24"
GATEWAY="192.168.1.1"
DNS="8.8.8.8"

sudo ip addr flush dev $INTERFACE
sudo ip addr add $IP dev $INTERFACE
sudo ip route add default via $GATEWAY
echo "nameserver $DNS" | sudo tee /etc/resolv.conf

Make the script executable and run it with sudo. This is useful for testing or temporary setups.

How To Set Static Ip Linux On Cloud Instances

Cloud servers often have their own networking layer. You may need to set a static IP through the cloud provider’s console.

On AWS, you can assign an Elastic IP to your instance. On Google Cloud, you can reserve a static external IP.

Internal IPs can be set manually in the OS, but it is usually managed by the cloud platform.

Security Considerations For Static IPs

A static IP makes your device easier to find on the network. Ensure your firewall is properly configured.

Use ufw or iptables to restrict incoming connections. Only open ports that are necessary.

Also consider using SSH keys instead of passwords for remote access.

How To Set Static Ip Linux On Embedded Systems

Embedded Linux systems like OpenWrt or Yocto have their own configuration methods. Usually, you edit /etc/config/network on OpenWrt.

For BusyBox-based systems, you might use the udhcpc script or edit /etc/network/interfaces.

Check the documentation for your specific embedded distribution.

How To Set Static Ip Linux On Virtual Machines

Virtual machines can have static IPs configured inside the guest OS. The same methods apply as for physical machines.

If you use bridged networking, the VM gets an IP from the same subnet as the host. For NAT networking, you may need port forwarding.

Some hypervisors like VirtualBox allow you to set a static IP in the VM settings.

How To Set Static Ip Linux Using Dhcpcd

The dhcpcd daemon is used on some distributions. Edit /etc/dhcpcd.conf and add:

interface eth0
static ip_address=192.168.1.100/24
static routers=192.168.1.1
static domain_name_servers=8.8.8.8

Then restart the service: sudo systemctl restart dhcpcd

How To Set Static Ip Linux On Alpine Linux

Alpine uses /etc/network/interfaces similar to Debian. Edit the file and set the interface to static.

Then restart networking: sudo rc-service networking restart

Alpine also supports ifupdown and busybox networking tools.

How To Set Static Ip Linux On Slackware

Slackware uses /etc/rc.d/rc.inet1.conf. Edit the file and set the IP, netmask, and gateway for each interface.

Then restart networking: sudo /etc/rc.d/rc.inet1 restart

How To Set Static Ip Linux On Gentoo

Gentoo uses /etc/conf.d/net. Set the configuration like this:

config_eth0="192.168.1.100/24"
routes_eth0="default via 192.168.1.1"
dns_servers_eth0="8.8.8.8 8.8.4.4"

Then restart the service: sudo /etc/init.d/net.eth0 restart

How To Set Static Ip Linux On Void Linux

Void uses runit and dhcpcd by default. You can either configure dhcpcd or use wpa_supplicant for WiFi.

For a static IP, create a file in /etc/runit/sv/ or use the ip command in a startup script.

How To Set Static Ip Linux On Solus

Solus uses NetworkManager by default. Use the GUI or nmcli to set a static IP.

You can also edit /etc/NetworkManager/system-connections/ files directly.

How To Set Static Ip Linux On NixOS

NixOS uses a declarative configuration. Edit /etc/nixos/configuration.nix and add:

networking.interfaces.eth0.ipv4.addresses = [{
  address = "192.168.1.100";
  prefixLength = 24;
}];
networking.defaultGateway = "192.168.1.1";
networking.nameservers = [ "8.8.8.8" ];

Then rebuild: sudo nixos-rebuild switch

How To Set Static Ip Linux On OpenSUSE

OpenSUSE uses YaST for network configuration. Run sudo yast2 and go to Network Settings.

You can also edit /etc/sysconfig/network/ifcfg-eth0 manually.

How To Set Static Ip Linux On Manjaro

Manjaro uses NetworkManager by default. Use the GUI or nmcli to set a static IP.

Alternatively, you can use systemd-networkd if you disable NetworkManager.

How To Set Static Ip Linux On Linux Mint

Linux Mint uses NetworkManager. Go to Network Settings,