修改ubuntu IP

编辑配置文件:

basj 复制代码
sudo nano /etc/netplan/01-network-manager-all.yaml

修改内容(注意缩进,YAML 对空格敏感):

yml 复制代码
# Let NetworkManager manage all devices on this system
network:
  version: 2
 # renderer: NetworkManager
  ethernets:
    ens33:
      dhcp4: false
      addresses:
        - 192.168.1.11/24
      routes:
        - to: default
          via: 192.168.1.2
      nameservers:
        addresses: [8.8.8.8, 8.8.4.4]

应用配置:

bash 复制代码
sudo netplan apply

如果配置有误,apply 会报错,你可以先测试:

bash 复制代码
sudo netplan try

该命令会应用配置并等待确认,如果网络连接中断,超时后会自动回滚,避免你被锁在 SSH 外。

如果报

bash 复制代码
** (process:5206): WARNING **: 00:04:45.678: Permissions for /etc/netplan/01-network-manager-all.yaml are too open. Netplan configuration should NOT be accessible by others.

** (generate:5208): WARNING **: 00:04:45.685: Permissions for /etc/netplan/01-network-manager-all.yaml are too open. Netplan configuration should NOT be accessible by others.

** (process:5206): WARNING **: 00:04:46.072: Permissions for /etc/netplan/01-network-manager-all.yaml are too open. Netplan configuration should NOT be accessible by others.

** (process:5206): WARNING **: 00:04:46.159: Permissions for /etc/netplan/01-network-manager-all.yaml are too open. Netplan configuration should NOT be accessible by others.
Do you want to keep these settings?


Press ENTER before the timeout to accept the new configuration


Changes will revert in  85 seconds
Reverting.

** (process:5206): WARNING **: 00:05:23.045: Permissions for /etc/netplan/01-network-manager-all.yaml are too open. Netplan configuration should NOT be accessible by others.

** (process:5206): WARNING **: 00:05:23.045: Permissions for /tmp/tmplfzk4vli/etc/netplan/01-network-manager-all.yaml are too open. Netplan configuration should NOT be accessible by others.

** (process:5206): WARNING **: 00:05:23.139: Permissions for /etc/netplan/01-network-manager-all.yaml are too open. Netplan configuration should NOT be accessible by others.

执行以下命令,将配置文件权限改为 600(仅 root 可读写)或 644(root 可读写,其他人只读),并确保所有者为 root:

bash 复制代码
sudo chmod 600 /etc/netplan/01-network-manager-all.yaml
sudo chown root:root /etc/netplan/01-network-manager-all.yaml

如果希望保留组可读(比如允许特定组查看配置),也可以使用 640,但 600 是最严格的。

重新应用配置

修复权限后,再次尝试应用配置:

bash 复制代码
sudo netplan apply

或者如果你想先测试配置(try 会自动回滚以防断网):

bash 复制代码
sudo netplan try
相关推荐
Waay4 小时前
Linux Shell 知识点考评(一):grep 文本搜索(附答案)
linux·运维·服务器
jamon_tan4 小时前
Linux下串口RAW模式设置
linux
碧海银沙音频科技研究院5 小时前
基于VMware虚拟机ubuntu开发博通BK7258方法
linux·运维·ubuntu
云边有个稻草人7 小时前
【Linux系统】进程地址空间
linux·虚拟地址空间·进程地址空间·虚拟地址空间是怎么实现的?·为什么要有虚拟地址空间?·怎么理解虚拟地址空间?
想唱rap12 小时前
传输层协议TCP
linux·运维·服务器·网络·c++·tcp/ip
曦夜日长12 小时前
Linux系统篇,权限(二):缺省权限、最终权限的计算、文件隔离的两种方式
linux·运维·服务器
云水一下12 小时前
黑客的“猜密码”游戏:SSH暴力破解实战与Linux安全加固
linux·渗透测试·ssh·暴力破解
kebidaixu13 小时前
OK3568开发板更新Ubuntu22.04方法总结
linux·运维·服务器
晚风予卿云月13 小时前
【Linux】Linux2.6 O(1)调度器超详解 | 进程切换+内核链表 | 面试必背
linux·运维·面试
www.0214 小时前
Linux 终端守护神 Tmux :如何优雅地管理后台实验与恢复会话
linux·运维·服务器·人工智能·tmux