Ubuntu Desktop 17.10使用WiFi适配器无法设置静态IP求助
Hey there! Let's break down the key places to check when your Netplan static IP config isn't sticking—even though your WiFi is working fine. Here's what to investigate step by step:
1. Validate your Netplan YAML syntax and static configuration
First, make sure your /etc/netplan/01-network-manager-all.yaml actually defines a static IP setup (not just DHCP). You need to explicitly disable DHCP and set your static details. A correct snippet should look like this:
network: version: 2 renderer: NetworkManager wifis: wlan0: # Replace with your actual WiFi interface name dhcp4: no addresses: [192.168.1.100/24] # Your static IP + subnet mask gateway4: 192.168.1.1 # Your router's IP nameservers: addresses: [8.8.8.8, 8.8.4.4] # DNS servers access-points: "YourWiFiSSID": password: "YourWiFiPassword"
Critical note: YAML relies entirely on 2-space indentation (no tabs). A single misplaced space will cause the config to fail silently, so double-check your indentation levels.
2. Confirm NetworkManager isn't overriding Netplan
Since your config uses renderer: NetworkManager, it's possible NetworkManager has a separate profile for your WiFi that's set to DHCP. Here's how to check:
- Run
nmcli con showto list all NetworkManager connections. Look for your WiFi SSID's profile. - If the profile shows
ipv4.method: auto, that means it's using DHCP. To fix this:- Force Netplan to apply the config:
sudo netplan generate && sudo netplan apply - Restart NetworkManager to pick up the changes:
sudo systemctl restart NetworkManager - Alternatively, edit the NetworkManager profile directly via GUI or
nmcli con edit <profile-name>to set static IP matching your Netplan settings.
- Force Netplan to apply the config:
3. Double-check your WiFi interface name
It's easy to typo the interface name (like wlan0 vs wlp2s0). Run ip link show to get the exact name of your WiFi interface, then make sure it matches the one in your Netplan YAML. If the interface name is wrong, Netplan will ignore the static config and fall back to DHCP.
4. Look for conflicting config files
Netplan processes all .yaml files in /etc/netplan/—if there's another file (like 00-installer-config.yaml) that sets DHCP for your WiFi interface, it might take precedence. Run ls /etc/netplan/ to list all files and check each one for conflicting settings.
Also, if you have an old /etc/network/interfaces file (from the ifupdown era), it could interfere. Comment out any entries for your WiFi interface or remove the file entirely.
5. Ensure your static IP isn't already in use
If the static IP you're trying to assign is already taken by another device on your network, your system might automatically fall back to DHCP. Test this by pinging the IP from another device (e.g., ping 192.168.1.100). If it responds, pick a different IP in your subnet range.
6. Check system logs for error clues
Logs will often tell you exactly what's going wrong. Run these commands to look for issues:
sudo journalctl -u NetworkManager: Check for errors related to IP configuration or profile loadingsudo journalctl -u netplan-wpa: Look for Netplan-specific issues with your WiFi setup
内容的提问来源于stack exchange,提问作者Zohar Navneet

