在Ubuntu 22.04版本中,网络配置文件位于/etc/netplan/目录下。打开终端,使用文本编辑器(如nanovi)编辑00-installer-config.yaml文件。

  1. 配置静态IP地址: 找到network部分,添加以下内容来配置静态IP地址:
network:
  ethernets:
    <interface_name>:
      addresses: [<ip_address>/<subnet_mask>]
      gateway4: <gateway_address>
      nameservers:
        addresses: [<dns_server1>, <dns_server2>]
  version: 2

<interface_name>替换为你的网络接口名称(如eth0ens33)。 将<ip_address>替换为你的静态IP地址。 将<subnet_mask>替换为你的子网掩码。 将<gateway_address>替换为你的网关地址。 将<dns_server1><dns_server2>替换为你的DNS服务器地址。

示例配置如下:

network:
  ethernets:
    eth0:
      addresses: [192.168.1.100/24]
      gateway4: 192.168.1.1
      nameservers:
        addresses: [8.8.8.8, 8.8.4.4]
  version: 2
  1. 保存并关闭文件。

  2. 应用配置更改: 运行以下命令应用新的网络配置:

sudo netplan apply

这将使新的网络配置生效。

请注意,以上示例假设你正在使用以太网接口(eth0)。根据你的系统和网络配置,可能需要做一些调整。确保在修改配置文件之前备份原始文件,以防万一出现问题

ubuntu22 etcnetplan00-installer-configyaml 里面配置静态IP和DNS

原文地址: https://www.cveoy.top/t/topic/itHp 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录