How to Set Up a Static IP Address on Linux, Windows, and macOS

4 min read
Beginner Networking Linux Windows IP Address How To

Quick Answer: Ubuntu: edit /etc/netplan/*.yaml, set dhcp4: false, add your IP under addresses, run sudo netplan apply. Windows: Settings → Network → Ethernet → IP assignment → Manual. macOS: System Settings → Network → Details → TCP/IP → Manual.


Need a VPS? Vultr (free credit), DigitalOcean ($200 free credit), or RackNerd (cheap annual deals).

Why Use a Static IP?

DHCP assigns a new IP each time your device connects. This is fine for laptops and phones, but servers and network services need a consistent address:

  • Servers — SSH, web server, database always at the same address
  • Port forwarding — router rules point to a fixed IP
  • DNS — A records point to a specific IP
  • Printers/NAS — devices you want to always reach at the same address

Linux: Ubuntu/Debian (Netplan)

Ubuntu 18.04+ uses Netplan for network configuration.

Find Your Current Settings

# Current IP and interface name
ip addr show

# Current gateway
ip route | grep default

# Current DNS
resolvectl status | grep "DNS Servers"
# or
cat /etc/resolv.conf

Note your: interface name (e.g., eth0, ens3, enp0s3), current IP, gateway, and DNS.

Configure Static IP

# Find the config file
ls /etc/netplan/
# Usually: 00-installer-config.yaml or 01-netcfg.yaml

sudo nano /etc/netplan/00-installer-config.yaml

Replace the contents with:

network:
  version: 2
  ethernets:
    eth0:                      # Your interface name
      dhcp4: false
      addresses:
        - 192.168.1.100/24     # Your desired static IP
      routes:
        - to: default
          via: 192.168.1.1     # Your gateway
      nameservers:
        addresses:
          - 1.1.1.1            # Primary DNS
          - 8.8.8.8            # Secondary DNS

Apply

# Test first (reverts after 120 seconds if something breaks)
sudo netplan try

# Apply permanently
sudo netplan apply

# Verify
ip addr show eth0
ping -c 3 google.com

Linux: CentOS/RHEL/Fedora (NetworkManager)

Using nmcli

# Show connections
nmcli con show

# Set static IP on connection "eth0"
sudo nmcli con mod eth0 ipv4.addresses 192.168.1.100/24
sudo nmcli con mod eth0 ipv4.gateway 192.168.1.1
sudo nmcli con mod eth0 ipv4.dns "1.1.1.1 8.8.8.8"
sudo nmcli con mod eth0 ipv4.method manual

# Apply
sudo nmcli con up eth0

# Verify
ip addr show eth0

Using Config File (RHEL 8 and older)

On RHEL 9+ and Fedora 36+, use nmcli above — the ifcfg format has been removed.

sudo nano /etc/sysconfig/network-scripts/ifcfg-eth0
TYPE=Ethernet
BOOTPROTO=static
NAME=eth0
DEVICE=eth0
ONBOOT=yes
IPADDR=192.168.1.100
NETMASK=255.255.255.0
GATEWAY=192.168.1.1
DNS1=1.1.1.1
DNS2=8.8.8.8
sudo systemctl restart NetworkManager

Linux: Any Distro (ip command — temporary)

# Set IP (lost on reboot)
sudo ip addr add 192.168.1.100/24 dev eth0
sudo ip route add default via 192.168.1.1

# Remove old DHCP IP if needed
sudo ip addr del 192.168.1.50/24 dev eth0

This is temporary and resets on reboot. Use Netplan or NetworkManager for persistent configuration.


VPS / Cloud Servers

Most VPS providers (DigitalOcean, Vultr, Hetzner) assign static IPs automatically. Do not change the IP configuration on a VPS unless you know what you're doing — you could lose access.

If you need additional IPs:

  • Add them through your provider's control panel
  • Then configure them as secondary addresses:
# Add secondary IP
sudo ip addr add 203.0.113.51/24 dev eth0

Windows 11/10

Via Settings

  1. Open SettingsNetwork & Internet
  2. Click Ethernet (or Wi-Fi)
  3. Click IP assignmentEdit
  4. Change to Manual
  5. Toggle IPv4 on
  6. Enter:
  • IP address: 192.168.1.100
  • Subnet mask: 255.255.255.0
  • Gateway: 192.168.1.1
  • Preferred DNS: 1.1.1.1
  • Alternate DNS: 8.8.8.8
  1. Click Save

Via Command Line (PowerShell)

# Find interface index
Get-NetAdapter

# Set static IP
New-NetIPAddress -InterfaceIndex 12 -IPAddress 192.168.1.100 -PrefixLength 24 -DefaultGateway 192.168.1.1

# Set DNS
Set-DnsClientServerAddress -InterfaceIndex 12 -ServerAddresses ("1.1.1.1", "8.8.8.8")

# Switch back to DHCP
Set-NetIPInterface -InterfaceIndex 12 -Dhcp Enabled

macOS

  1. Open System SettingsNetwork
  2. Select your connection (Ethernet or Wi-Fi)
  3. Click Details
  4. Go to TCP/IP
  5. Change Configure IPv4 to Manually
  6. Enter:
  • IP Address: 192.168.1.100
  • Subnet Mask: 255.255.255.0
  • Router: 192.168.1.1
  1. Go to DNS tab
  2. Add 1.1.1.1 and 8.8.8.8
  3. Click OKApply

Via Terminal

# Set static IP
sudo networksetup -setmanual "Ethernet" 192.168.1.100 255.255.255.0 192.168.1.1

# Set DNS
sudo networksetup -setdnsservers "Ethernet" 1.1.1.1 8.8.8.8

# Switch back to DHCP
sudo networksetup -setdhcp "Ethernet"

How to Choose an IP

Setting How to Find It
Subnet Usually 192.168.1.x/24 or 10.0.0.x/24 — check your router
Available IP Pick something above your router's DHCP range (e.g., if DHCP gives .2-.200, use .201+)
Gateway Your router's IP (usually .1)
DNS 1.1.1.1 (Cloudflare) or 8.8.8.8 (Google)

Troubleshooting

Problem Fix
Lost connection after change Connect via console/monitor. Check config for typos
Can't reach internet Check gateway is correct (ip route)
Can reach IPs but not domains DNS misconfigured. Try ping 1.1.1.1 vs ping google.com
IP conflict Another device has the same IP. Pick a different one
Netplan won't apply Check YAML indentation (spaces, not tabs). Validate: sudo netplan --debug apply
# Test connectivity step by step
ping -c 3 192.168.1.1       # Can reach gateway?
ping -c 3 1.1.1.1            # Can reach internet?
ping -c 3 google.com         # DNS working?

Related Guides

Related Tools