Ashari Abidin's Developer Docs

Setting Fix IP on Ubuntu

📡 Setting Static IP on Ubuntu: Complete Guide

Configure Static IP Address on Ubuntu WiFi Using NetworkManager
🎯 Ubuntu 24.04 📶 SSID: Zhihab123 🌐 wlp1s0b1 🔒 Static: 192.168.0.7/24

⚡ 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.

1 Check Current Network Interface

Run the following command to identify your wireless interface:

ip addr
📌 Example output snippet:
3: wlp1s0b1: <BROADCAST,MULTICAST,UP> ...

✅ Confirms active WiFi interface: wlp1s0b1

2 Verify NetworkManager Is Running
systemctl status NetworkManager
Expected: active (running) 🟢

If not running: sudo systemctl restart NetworkManager

3-4 Enable WiFi & Unblock Adapter
nmcli radio wifi on
sudo rfkill unblock wifi

Verify blocking status:

rfkill list
✅ Soft blocked: no  |  Hard blocked: no
5 Bring Up WiFi Interface
sudo ip link set wlp1s0b1 up
6 Scan Available Networks
nmcli dev wifi list
🔍 Look for SSID: Zhihab123
7 Connect to WiFi (Zhihab123)
nmcli dev wifi connect "Zhihab123" password "YOUR_WIFI_PASSWORD"

Or explicitly specify interface:

nmcli dev wifi connect "Zhihab123" password "YOUR_WIFI_PASSWORD" ifname wlp1s0b1
⚠️ Replace YOUR_WIFI_PASSWORD with actual credentials.
8 Verify Internet Connectivity
ip addr
ping 8.8.8.8

Check that you receive an IP (DHCP for now) and ping succeeds.

9 Check Existing NetworkManager Profiles
nmcli connection show
Profile example: Zhihab123 (the connection name)
10 Configure Static IP Address (nmcli)

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"
📌 These changes persist after reboot.
11 Restart WiFi Connection
sudo nmcli connection down "Zhihab123"
sudo nmcli connection up "Zhihab123"
12 Verify Static IP Configuration
ip addr show wlp1s0b1
✅ Expected: inet 192.168.0.7/24 valid_lft forever preferred_lft forever

The keyword forever indicates static assignment (no DHCP lease).

13 Verify Routing Table
ip route
default via 192.168.0.1 dev wlp1s0b1 proto static

If you still see proto dhcp → static method may not be applied. Re-run step 10 & restart connection.

14-15 Netplan Adjustments & Permissions

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
⚠️ Do NOT delete /etc/netplan/90-NM-*.yaml – those are autogenerated by NetworkManager. Keep them intact.
16 Important Best Practices
  • 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-*).
17 Full Recovery + Static IP Automation Script

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
⚙️ Before using the script, replace 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)

✅ nmcli connection show "Zhihab123" → ipv4.method: manual
✅ 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)
🧠 Important netplan & NetworkManager harmony: On Ubuntu 24.04 Desktop (default), WiFi is managed by NetworkManager. The configuration described using nmcli is the correct approach. Ensure /etc/netplan/ only declares renderer: NetworkManager. Do not add static IP for WiFi inside netplan YAML.
💡 Troubleshooting Tips
  • 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.method is manual. Run nmcli connection show "Zhihab123" | grep ipv4.method.
  • WiFi blocked after suspend: Use sudo rfkill unblock wifi and nmcli radio wifi on — the automation script covers this.
  • Wrong interface name? Confirm with ip link or iwconfig and replace wlp1s0b1 accordingly.
🔴 Static IP on Ubuntu WiFi – using NetworkManager & nmcli | based on Ubuntu 24.04 | Interface: wlp1s0b1 | SSID: Zhihab123
Configuration: 192.168.0.7/24 | gateway 192.168.0.1 | DNS 8.8.8.8 / 1.1.1.1
Back