Set a static IP address
A static address stops a printer, NAS, server or Raspberry Pi wandering to a new address every few days. There are two ways to get one, and the better one does not involve touching the device at all.
Before you start: the four values you need
Run ipconfig /all, ip addr && ip route or networksetup -getinfo "Wi-Fi" on any working device on the same network and write down:
| Value | Example | Where it comes from |
|---|---|---|
| IP address | 192.168.1.50 | Your choice, within the LAN range, outside the DHCP pool (see below) and not used by anything else |
| Subnet mask / prefix | 255.255.255.0 (/24) | Same as the other devices |
| Default gateway / router | 192.168.1.1 | Same as the other devices |
| DNS servers | 192.168.1.1, or 1.1.1.1 and 1.0.0.1 | The router, or a public resolver. Choosing DNS servers → |
The DHCP pool. Your router hands out addresses from a range, often 192.168.1.100 to 192.168.1.199 or 192.168.1.2 to 192.168.1.254 (the whole subnet). If you give a device a static address inside that range, the router may later give the same address to something else and you get an IP conflict. Look up the pool on the router's DHCP page, and either pick an address outside it or shrink the pool. Low numbers (192.168.1.2 to .20) are a common convention for infrastructure.
Check the address is free before using it: ping 192.168.1.50 should time out, and on Linux sudo arping -D -I eth0 192.168.1.50 should report no reply.
Option 1: a DHCP reservation on the router (recommended)
A reservation (also called a static lease, address reservation, static DHCP or IP/MAC binding) tells the router "always give this MAC address that IP". The device stays on plain DHCP, so it still gets the right gateway and DNS if you ever change them, it still works when you take it to another network, and there is nothing to reconfigure on the device itself. For phones, laptops and anything that moves, it is the only sensible choice.
- Find the device's MAC address:
ipconfig /all(Physical Address),ip link,ifconfig en0 | grep ether, or the router's client list. Finding MAC addresses on every platform → - Log in to the router at its gateway address. Find it and the default logins →
- Find the DHCP page: LAN › DHCP Server › Address Reservation (TP-Link), Advanced › Setup › LAN Setup › Address Reservation (Netgear), LAN › DHCP Server › Manually Assigned IP (ASUS), Advanced Settings › DHCP › Static leases (OpenWrt), Network › DHCP › Static IP (UniFi), Settings › Advanced › DHCP › Static Leases (Fritz!Box), Advanced › Home network › Devices (BT Smart Hub: choose the device, Always use this IP address).
- Add the MAC and the desired IP. Save.
- On the device, renew the lease:
ipconfig /release && ipconfig /renew,sudo nmcli device reapply eth0,sudo ipconfig set en0 DHCP, or toggle Wi-Fi off and on. It should come back with the reserved address.
Note that phones and recent macOS randomise their Wi-Fi MAC per network; reserve against the address the router actually sees for that network, or turn off the private address for your home network in the device's Wi-Fi settings.
Option 2: configure the device
Windows 11 and 10 (Settings)
- Settings › Network & internet › Ethernet (or Wi-Fi › your network's properties).
- Next to IP assignment click Edit, change Automatic (DHCP) to Manual, switch IPv4 on.
- Enter IP address, subnet mask (Windows 11 asks for the mask as 255.255.255.0; some builds ask for prefix length 24), gateway, preferred and alternate DNS. Save.
Classic route: ncpa.cpl › right-click the adapter › Properties › Internet Protocol Version 4 › Properties › Use the following IP address. Both routes edit the same settings.
Windows (command line)
netsh interface ipv4 set address name="Ethernet" static 192.168.1.50 255.255.255.0 192.168.1.1
netsh interface ipv4 set dnsservers name="Ethernet" static 1.1.1.1 primary
netsh interface ipv4 add dnsservers name="Ethernet" 1.0.0.1 index=2
ipconfig /all # confirm
:: back to automatic
netsh interface ipv4 set address name="Ethernet" source=dhcp
netsh interface ipv4 set dnsservers name="Ethernet" source=dhcpNew-NetIPAddress -InterfaceAlias Ethernet -IPAddress 192.168.1.50 -PrefixLength 24 -DefaultGateway 192.168.1.1
Set-DnsClientServerAddress -InterfaceAlias Ethernet -ServerAddresses 1.1.1.1, 1.0.0.1
# if the adapter still had a DHCP address, remove it first:
# Remove-NetIPAddress -InterfaceAlias Ethernet -AddressFamily IPv4 -Confirm:$false
# Remove-NetRoute -InterfaceAlias Ethernet -DestinationPrefix 0.0.0.0/0 -Confirm:$false
# back to automatic
Set-NetIPInterface -InterfaceAlias Ethernet -Dhcp Enabled
Set-DnsClientServerAddress -InterfaceAlias Ethernet -ResetServerAddresses
Restart-NetAdapter EthernetThe adapter name is what netsh interface show interface or Get-NetAdapter prints. Both commands need an administrator prompt. More on netsh and PowerShell →
macOS (System Settings)
- System Settings › Network › select the service (Wi-Fi or Ethernet) › Details… › TCP/IP.
- Change Configure IPv4 from Using DHCP to Manually. Enter IP address, subnet mask and router.
- Open the DNS tab and add servers with the + button. Click OK, then Apply.
The middle option, Using DHCP with manual address, sets a fixed IP while still taking router and DNS from DHCP. It is a reasonable compromise when you cannot make a reservation.
macOS (command line)
sudo networksetup -setmanual "Wi-Fi" 192.168.1.50 255.255.255.0 192.168.1.1
sudo networksetup -setdnsservers "Wi-Fi" 1.1.1.1 1.0.0.1
networksetup -getinfo "Wi-Fi" # confirm
# fixed address, DHCP for the rest
sudo networksetup -setmanualwithdhcprouter "Wi-Fi" 192.168.1.50
# back to automatic
sudo networksetup -setdhcp "Wi-Fi"
sudo networksetup -setdnsservers "Wi-Fi" EmptyService names come from networksetup -listallnetworkservices. More on networksetup →
Linux with NetworkManager (Ubuntu Desktop, Fedora, Mint, Raspberry Pi OS Bookworm and later)
nmcli connection show # find the profile name
sudo nmcli connection modify "Wired connection 1" \
ipv4.method manual \
ipv4.addresses 192.168.1.50/24 \
ipv4.gateway 192.168.1.1 \
ipv4.dns "1.1.1.1 1.0.0.1"
sudo nmcli connection up "Wired connection 1"
ip -br addr && ip route # confirm
# back to automatic
sudo nmcli connection modify "Wired connection 1" ipv4.method auto ipv4.addresses "" ipv4.gateway "" ipv4.dns ""
sudo nmcli connection up "Wired connection 1"Graphically: GNOME Settings › Network › gear icon › IPv4 › Manual; or run nmtui in a terminal for a menu that works over SSH.
Linux with Netplan (Ubuntu Server)
# /etc/netplan/01-static.yaml
network:
version: 2
ethernets:
enp3s0:
dhcp4: false
addresses: [192.168.1.50/24]
routes:
- to: default
via: 192.168.1.1
nameservers:
addresses: [1.1.1.1, 1.0.0.1]sudo netplan try # applies, and reverts after 120 s unless you press Enter
sudo netplan applyIf a cloud-init file (50-cloud-init.yaml) already defines the interface with dhcp4: true, either edit that file or disable cloud-init networking by creating /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg containing network: {config: disabled}.
Linux with systemd-networkd (Arch, servers)
# /etc/systemd/network/20-wired.network
[Match]
Name=enp3s0
[Network]
Address=192.168.1.50/24
Gateway=192.168.1.1
DNS=1.1.1.1
DNS=1.0.0.1sudo networkctl reload && sudo networkctl reconfigure enp3s0Linux with ifupdown (Debian, older Ubuntu)
# /etc/network/interfaces
auto enp3s0
iface enp3s0 inet static
address 192.168.1.50/24
gateway 192.168.1.1
dns-nameservers 1.1.1.1 1.0.0.1sudo ifdown enp3s0 && sudo ifup enp3s0Raspberry Pi OS Bullseye and earlier (dhcpcd)
# append to /etc/dhcpcd.conf
interface eth0
static ip_address=192.168.1.50/24
static routers=192.168.1.1
static domain_name_servers=1.1.1.1 1.0.0.1sudo systemctl restart dhcpcdTemporary, any Linux (lost at reboot)
sudo ip addr flush dev enp3s0
sudo ip addr add 192.168.1.50/24 dev enp3s0
sudo ip route add default via 192.168.1.1
# DNS: edit /etc/resolv.conf or: sudo resolvectl dns enp3s0 1.1.1.1iPhone and iPad
Settings › Wi-Fi › (i) next to the network › Configure IP › Manual › enter IP address, subnet mask and router › Configure DNS › Manual for DNS. The setting is per network. A reservation on the router is far more practical for a phone.
Android
Settings › Network & internet › Internet › gear icon next to the network › pencil/edit › Advanced options › IP settings › Static. Enter IP address, gateway, prefix length (24) and DNS. Menu names vary by manufacturer and version.
Static IPv6
Usually unnecessary: with SLAAC your device already generates a stable address from the router's prefix, and the prefix itself is chosen by your ISP and may change. If you need a fixed IPv6 address inside your network, use a ULA prefix (fd00::/8) that your router advertises, or a DHCPv6 reservation by DUID. Commands: netsh interface ipv6 set address "Ethernet" fd12:3456:789a::50/64, nmcli con mod "X" ipv6.method manual ipv6.addresses fd12:3456:789a::50/64 ipv6.gateway fe80::1, networksetup -setv6manual "Wi-Fi" fd12:3456:789a::50 64 fe80::1.
After you change it
- Confirm with
ipconfig,ip -br addrorifconfig, thenpingthe gateway andping 1.1.1.1, thenping example.com. - No internet after the change almost always means a typo in the gateway or a missing DNS server. Compare against a working device.
- If you set the address on a laptop, remember it will not work on other networks until you switch back to automatic. Windows offers an Alternate Configuration tab (in the classic IPv4 properties) that applies a static address only when DHCP fails, which is a neat way to have both.