Set a Static IP Address on Linux
nmcli connection show # find the connection name, e.g. "Wired connection 1"
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 "192.168.1.1 9.9.9.9"
sudo nmcli connection up "Wired connection 1"
ip -4 addr show
On Ubuntu Server use Netplan instead (see below). Pick an address outside your router's DHCP range so nothing else gets it.
Before you start: collect the values
You need four things: the interface name, the address with prefix length, the gateway and DNS servers. Read the current DHCP values and reuse the gateway and DNS:
ip -br addr # interface names and current addresses
ip route show default # current gateway
resolvectl status # current DNS (systemd-resolved)
cat /etc/resolv.conf # fallback if resolvectl isn't available
Example output:
lo UNKNOWN 127.0.0.1/8 ::1/128
enp3s0 UP 192.168.1.23/24 fe80::4a2f:...
default via 192.168.1.1 dev enp3s0 proto dhcp metric 100
Here the interface is enp3s0, the network is 192.168.1.0/24 and the gateway is 192.168.1.1. /24 means netmask 255.255.255.0; the subnet calculator converts other masks. For the underlying commands (ip, ss, DNS) see the Linux networking basics guide.
Then find out which tool is in charge, because editing the wrong one does nothing:
nmcli general status 2>/dev/null && echo "NetworkManager"
networkctl list 2>/dev/null
ls /etc/netplan/ 2>/dev/null
systemctl is-active networking 2>/dev/null # Debian ifupdown
A typo can cut you off. Use a console if you can, use netplan try (it rolls back automatically), or, with NetworkManager, create a separate static profile (shown below) and schedule a switch back to the untouched DHCP profile first: sudo systemd-run --on-active=5min nmcli connection up "Wired connection 1". Cancel it with systemctl list-timers and sudo systemctl stop on that run unit once you've confirmed the new address works.
NetworkManager with nmcli (most desktops and Fedora)
NetworkManager is the default on Ubuntu Desktop, Linux Mint, Fedora (Workstation and Server), openSUSE Leap 16 and Tumbleweed, and most Arch desktops. The short-answer commands above edit the existing profile. The GUI does the same thing: Settings → Network → gear icon → IPv4 → Manual.
To create a separate static profile instead of changing the DHCP one:
sudo nmcli connection add type ethernet con-name static-lan ifname enp3s0 \
ipv4.method manual ipv4.addresses 192.168.1.50/24 \
ipv4.gateway 192.168.1.1 ipv4.dns "192.168.1.1 9.9.9.9" \
connection.autoconnect yes
sudo nmcli connection up static-lan
For Wi-Fi, modify the profile named after your network (SSID) the same way. To go back to DHCP:
sudo nmcli connection modify "Wired connection 1" ipv4.method auto ipv4.addresses "" ipv4.gateway "" ipv4.dns ""
sudo nmcli connection up "Wired connection 1"
NetworkManager stores profiles as keyfiles in /etc/NetworkManager/system-connections/. On Ubuntu Desktop 23.10 and later it stores them through Netplan instead, as /etc/netplan/90-NM-*.yaml; keep using nmcli or the GUI and let it manage those files. The nmcli cheat sheet has more commands.
Ubuntu Server: Netplan
Ubuntu Server writes its config to a YAML file in /etc/netplan/ (often 50-cloud-init.yaml or 00-installer-config.yaml) and renders it for systemd-networkd. Edit that file or replace it:
sudo nano /etc/netplan/50-cloud-init.yaml
network:
version: 2
ethernets:
enp3s0:
dhcp4: false
addresses:
- 192.168.1.50/24
routes:
- to: default
via: 192.168.1.1
nameservers:
addresses: [192.168.1.1, 9.9.9.9]
search: [lan]
Apply it safely:
sudo chmod 600 /etc/netplan/*.yaml
sudo netplan generate # syntax check
sudo netplan try # applies, reverts after 120 s unless you press Enter
sudo netplan apply
YAML uses spaces, never tabs, and indentation matters. Use routes: - to: default; the old gateway4: key still works but prints a deprecation warning.
On cloud and some server images, cloud-init regenerates this file at boot. Disable its network handling with echo 'network: {config: disabled}' | sudo tee /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg, then put your config in a new file such as /etc/netplan/01-static.yaml.
Debian: /etc/network/interfaces (ifupdown)
A Debian server or minimal install without a desktop uses ifupdown. Edit /etc/network/interfaces:
auto enp3s0
iface enp3s0 inet static
address 192.168.1.50/24
gateway 192.168.1.1
dns-nameservers 192.168.1.1 9.9.9.9
Change the existing iface enp3s0 inet dhcp line rather than adding a second stanza. dns-nameservers only works when the resolvconf package is installed; otherwise set DNS in /etc/resolv.conf. Apply:
sudo ifdown enp3s0 && sudo ifup enp3s0
# or
sudo systemctl restart networking
If nmcli shows the interface as "unmanaged", that's expected: NetworkManager ignores interfaces listed in /etc/network/interfaces. Debian desktops (GNOME, KDE) use NetworkManager, so use nmcli there instead.
systemd-networkd (Arch, minimal servers)
A minimal Arch install often uses systemd-networkd. Create /etc/systemd/network/20-wired.network:
[Match]
Name=enp3s0
[Network]
Address=192.168.1.50/24
Gateway=192.168.1.1
DNS=192.168.1.1
DNS=9.9.9.9
sudo systemctl enable --now systemd-networkd systemd-resolved
sudo ln -sf /run/systemd/resolve/stub-resolv.conf /etc/resolv.conf
sudo networkctl reload
networkctl status enp3s0
Run only one network manager per interface: if NetworkManager is also enabled, disable one of them. Files are processed in lexical order, and the first one that matches an interface wins, so remove or rename any DHCP .network file that matches the same name. See the Arch Wiki on systemd-networkd.
Add IPv6 or a second address
Static IPv6 works the same way in each tool. Most home networks hand out IPv6 automatically (SLAAC), so you can leave IPv6 on auto while making IPv4 static.
# NetworkManager: add a static IPv6 address and keep router advertisements
sudo nmcli connection modify "Wired connection 1" \
ipv6.method manual ipv6.addresses 2001:db8:10::50/64 ipv6.gateway 2001:db8:10::1
# a second IPv4 address on the same interface
sudo nmcli connection modify "Wired connection 1" +ipv4.addresses 192.168.1.51/24
sudo nmcli connection up "Wired connection 1"
In Netplan, list extra addresses under addresses: (IPv4 and IPv6 mixed are fine) and add a - to: default via: <ipv6-gateway> route for IPv6. In systemd-networkd, add more Address= lines. For a quick test that disappears at reboot, sudo ip addr add 192.168.1.51/24 dev enp3s0 is enough.
Fedora and openSUSE notes
- Fedora uses NetworkManager keyfiles; the old
/etc/sysconfig/network-scripts/ifcfg-*files are no longer used for new connections. Use nmcli ornmtui(a text UI that works well over SSH). - openSUSE Leap 16 uses NetworkManager only; wicked is gone. Older Leap 15 and Tumbleweed servers may still run wicked (
/etc/sysconfig/network/ifcfg-*, configured in YaST). Check withsystemctl is-active wicked NetworkManager. - Linux Mint is NetworkManager; use the network applet or nmcli.
Verify the static IP
ip -4 addr show enp3s0 # shows 192.168.1.50/24, no "dynamic"
ip route show default # default via 192.168.1.1
ping -c 3 192.168.1.1 # gateway reachable
ping -c 3 9.9.9.9 # internet by IP
resolvectl query example.org # DNS works
A DHCP address shows dynamic and a lease time in ip addr; a static one doesn't. Reboot once to confirm the configuration persists. If other machines reach it by name, also update DNS or /etc/hosts, and check that your hostname resolves locally.
Common problems
| Symptom | Cause and fix |
|---|---|
| IP is set but no internet: Network is unreachable | Missing or wrong gateway. Check ip route; the gateway must be inside your subnet. |
| Ping by IP works, names don't | No DNS configured. Add DNS servers; see Temporary failure in name resolution. |
| Machine keeps the old DHCP address too | Two managers on one interface, or a second netplan file still has dhcp4: true. Use grep -r dhcp /etc/netplan and keep one manager. |
| Network drops randomly, "duplicate address" in logs | Another device uses the same IP. Choose an address outside the router's DHCP pool or reserve it on the router. |
netplan apply: "Permissions ... are too open" | sudo chmod 600 /etc/netplan/*.yaml. |
| Config reset after reboot on a cloud VM | cloud-init regenerated it. Disable cloud-init network config as shown above. |
Frequently asked questions
How do I know which tool manages my network?
Run nmcli general status (NetworkManager), networkctl (systemd-networkd) and ls /etc/netplan/. Desktops almost always use NetworkManager; Ubuntu Server uses Netplan with systemd-networkd.
Why does Netplan say gateway4 is deprecated?
Netplan replaced gateway4 with a route entry. Use routes: [{to: default, via: 192.168.1.1}] instead.
Should I set a static IP on the machine or in the router?
A DHCP reservation in the router is often easier and avoids address conflicts. Set it on the machine when there is no DHCP server, or for servers that must keep working if DHCP fails.
Will a static IP survive a reboot?
Yes, all methods on this page write persistent configuration. Commands like ip addr add alone are temporary and are lost on reboot.
Spotted a mistake or a command that no longer works? Send a correction — pages are re-checked when reports come in.