You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Ubuntu 20.04下NetworkManager忽略eth0静态IP配置、Netplan配置失效问题求助

Ubuntu 20.04下NetworkManager忽略eth0静态IP配置、Netplan配置失效问题求助

Hey Dennis, let's tackle this problem step by step. First off, I notice a couple of key issues with your current setup that are probably causing the static IP not to stick, and we'll also dig into why your original Netplan config stopped working.


方案1:修复并重新应用Netplan配置

Your original Netplan config has incorrect indentation—YAML is super picky about this, and even a missing space can make the whole config unreadable. Here's the corrected version of /etc/netplan/01-network-manager-all.yaml:

# Let NetworkManager manage all devices on this system
network:
  version: 2
  renderer: NetworkManager
  ethernets:
    eth0:
      dhcp4: no
      addresses:
        - 192.168.1.6/24
      gateway4: 192.168.1.254
      nameservers:
        addresses: [192.168.1.2]

Once you've updated the file with proper indentation, run these commands to apply the config:

sudo netplan generate
sudo netplan apply
sudo systemctl restart NetworkManager

Check your IP again with ip a show eth0—it should switch back to 192.168.1.6.


方案2:用nmcli正确配置NetworkManager静态连接

Your mistake here was putting the connection config in /etc/NetworkManager/conf.d/—that directory is for global NetworkManager settings, not individual connection profiles. The correct place for connection configs is /etc/NetworkManager/system-connections/, and using nmcli is the safest way to create these (it handles permissions and formatting automatically).

  1. First, delete the incorrect config file you created:
sudo rm /etc/NetworkManager/conf.d/ethernet.conf
  1. Create a new static Ethernet connection with nmcli:
sudo nmcli con add type ethernet con-name "Wired Static" ifname eth0 ip4 192.168.1.6/24 gw4 192.168.1.254 ipv4.dns 192.168.1.2 ipv6.method ignore
  1. Set this connection to auto-connect on boot:
sudo nmcli con mod "Wired Static" connection.autoconnect yes
  1. Disable the old dynamic connection and activate the new one:
sudo nmcli con down "Wired connection 1"
sudo nmcli con up "Wired Static"

Now run ip a show eth0—your static IP should be active.


Bonus: Why did your Netplan config suddenly stop working?

First, a quick clarification: Your original Netplan config was using renderer: NetworkManager, so you were always using NetworkManager to manage your network—Netplan was just the tool to feed configs to NetworkManager. Here are the most likely reasons it broke:

  • Indentation error in Netplan config: As I mentioned earlier, YAML is strict about spacing. If you (or a system update, though unlikely) accidentally messed up the indentation in /etc/netplan/01-network-manager-all.yaml, Netplan would fail to parse it, and NetworkManager would fall back to DHCP.
  • Conflicting Netplan files: Check if there are other Netplan files in /etc/netplan/ (like 02-*.yaml). Netplan applies files in alphabetical order, so a later file could overwrite your eth0 config.
  • NetworkManager config changes: Your /etc/NetworkManager/NetworkManager.conf has [ifupdown] managed=false, which is default, but if this was changed temporarily (or another config in /etc/NetworkManager/conf.d/ interfered), it could have disrupted the Netplan-NetworkManager integration.
  • Device reinitialization: If your eth0 interface was renumbered (e.g., after a kernel update or hardware change), Netplan's config for eth0 wouldn't apply to the new interface name. You can check this with ip link show to confirm the interface name is still eth0.

To debug exactly what happened, run this command to see Netplan's detailed apply logs:

sudo netplan --debug apply

It will show you if Netplan found any errors in your config or if another file is overriding it.


备注:内容来源于stack exchange,提问作者Dennis

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.23 13:08:18