📡 Setting Static IP on Ubuntu: Complete Guide
⚡ This guide provides a permanent static IP configuration for WiFi interfaces managed by NetworkManager. The setup uses nmcli — modern, reliable, and persistent across reboots. Parameters below are tailored for Zhihab123 SSID, interface wlp1s0b1, IP 192.168.0.7, gateway 192.168.0.1, and DNS 8.8.8.8 / 1.1.1.1.
Run the following command to identify your wireless interface:
ip addr
3: wlp1s0b1: <BROADCAST,MULTICAST,UP> ...
✅ Confirms active WiFi interface: wlp1s0b1
systemctl status NetworkManager
If not running: sudo systemctl restart NetworkManager
nmcli radio wifi on
sudo rfkill unblock wifi
Verify blocking status:
rfkill list
sudo ip link set wlp1s0b1 up
nmcli dev wifi list
nmcli dev wifi connect "Zhihab123" password "YOUR_WIFI_PASSWORD"
Or explicitly specify interface:
nmcli dev wifi connect "Zhihab123" password "YOUR_WIFI_PASSWORD" ifname wlp1s0b1
YOUR_WIFI_PASSWORD with actual credentials.ip addr
ping 8.8.8.8
Check that you receive an IP (DHCP for now) and ping succeeds.
nmcli connection show
Set manual method, static IP, gateway and DNS:
sudo nmcli connection modify "Zhihab123" ipv4.method manual
sudo nmcli connection modify "Zhihab123" ipv4.addresses 192.168.0.7/24
sudo nmcli connection modify "Zhihab123" ipv4.gateway 192.168.0.1
sudo nmcli connection modify "Zhihab123" ipv4.dns "8.8.8.8 1.1.1.1"
sudo nmcli connection down "Zhihab123"
sudo nmcli connection up "Zhihab123"
ip addr show wlp1s0b1
The keyword forever indicates static assignment (no DHCP lease).
ip route
If you still see proto dhcp → static method may not be applied. Re-run step 10 & restart connection.
Fix permissions warning (if any):
sudo chmod 600 /etc/netplan/*.yaml
Restore default Netplan config for Ubuntu Desktop (WiFi managed by NetworkManager)
sudo nano /etc/netplan/01-network-manager-all.yaml
Content:
network:
version: 2
renderer: NetworkManager
sudo netplan apply
/etc/netplan/90-NM-*.yaml – those are autogenerated by NetworkManager. Keep them intact.- ✅ Recommended: Use NetworkManager + nmcli for WiFi static IP
- ✅ Keep WiFi profiles managed automatically
- ❌ Avoid managing WiFi directly via
wifis:in netplan YAML - ❌ Avoid mixing DHCP and manual settings on same connection
- 📁 Never delete autogenerated NM YAML files (90-NM-*).
Create an all-in-one script that reconnects, applies static IP, and restores WiFi settings.
#!/bin/bash
WIFI="Zhihab123"
PASSWORD="YOUR_WIFI_PASSWORD"
IPADDR="192.168.0.7/24"
GATEWAY="192.168.0.1"
DNS="8.8.8.8 1.1.1.1"
echo "=================================="
echo " WIFI RECOVERY + STATIC IP FIX"
echo "=================================="
systemctl restart NetworkManager
sleep 5
nmcli radio wifi on
rfkill unblock wifi
ip link set wlp1s0b1 up
nmcli dev wifi list
nmcli dev wifi connect "$WIFI" password "$PASSWORD" ifname wlp1s0b1 || true
sleep 5
nmcli connection modify "$WIFI" ipv4.method manual
nmcli connection modify "$WIFI" ipv4.addresses "$IPADDR"
nmcli connection modify "$WIFI" ipv4.gateway "$GATEWAY"
nmcli connection modify "$WIFI" ipv4.dns "$DNS"
nmcli connection down "$WIFI" || true
sleep 3
nmcli connection up "$WIFI"
echo ""
nmcli device status
echo ""
ip addr show wlp1s0b1
echo ""
ip route
Save the script:
sudo tee /usr/local/bin/fix-wifi-static.sh > /dev/null << 'EOF'
[ paste content above ]
EOF
Make executable & run:
sudo chmod +x /usr/local/bin/fix-wifi-static.sh
sudo fix-wifi-static.sh
YOUR_WIFI_PASSWORD with your actual WiFi password. After that, this script recovers full static IP configuration even after major network issues.📌 Verification summary (quick checklist)
✅ ip addr shows 192.168.0.7/24 forever
✅ resolvectl status or systemd-resolved shows 8.8.8.8, 1.1.1.1
✅ ping -c 4 192.168.0.1 (gateway reachable)
nmcli is the correct approach. Ensure /etc/netplan/ only declares renderer: NetworkManager. Do not add static IP for WiFi inside netplan YAML.
- Static IP not sticking after reboot? Run
sudo nmcli connection up "Zhihab123"and verify that the connection profile saved correctly. - Still receiving DHCP lease: Make sure
ipv4.methodismanual. Runnmcli connection show "Zhihab123" | grep ipv4.method. - WiFi blocked after suspend: Use
sudo rfkill unblock wifiandnmcli radio wifi on— the automation script covers this. - Wrong interface name? Confirm with
ip linkoriwconfigand replace wlp1s0b1 accordingly.
Comments