How to set up a static IP address on Linux

· Category: Linux

Short answer

Configure a static IP via your distribution's network configuration files or tools like Netplan or NetworkManager.

Steps

  1. Netplan (/etc/netplan/01-netcfg.yaml):
network:
  version: 2
  ethernets:
    eth0:
      dhcp4: no
      addresses: [192.168.1.100/24]
      routes:
        - to: default
          via: 192.168.1.1
      nameservers:
        addresses: [8.8.8.8, 1.1.1.1]
  1. Apply:
sudo netplan apply

Tips

  • Use ip addr to confirm the interface name.
  • Keep a console session open when changing network settings remotely.
  • DNS can also be configured via systemd-resolved.

Common issues

  • YAML indentation errors break Netplan.
  • Duplicate IPs cause network conflicts and dropped connections.