Ubuntu 网络配置

Netplan

Netplan 是 Ubuntu 的网络配置工具。其配置文件存储在 /etc/netplan 目录下。以下是一个示例配置 01-netcfg.yaml

network:
  ethernets:
    enp1s0f0:
      dhcp4: false
      addressed: [192.168.1.2/24]
      optional: true
      routes:
        - to: default
          via: 192.168.1.1
      nameservers:
        addresses: [8.8.8.8]
    enp1s0f1:
      dhcp4: true
  version: 2
  renderer: networkd

renderer:指定使用哪个后端来管理网络接口,常见的值有 networkd(常用于服务器环境)和 NetworkManager(常用于桌面环境)。

参见:Netplan tutorial | Netplan documentation

修改配置文件后,需要应用配置:

sudo netplan try    # 检查配置并应用
sudo netplan apply  # 直接应用

检查配置结果:

ip addr show enp1s0f0  # 查看 enp1s0f0 接口的配置

ip 命令

ip 是一个强大的网络管理工具,属于 iproute2 软件包,取代了一些旧有的网络管理工具如 ifconfigroute

ip link show           # 列出所有网络接口
ip addr show           # 列出所有网络接口的 IP 地址
ip addr show enp1s0f0  # 列出指定网络接口的 IP 地址
posted @ 2025-02-28 15:04  Undefined443  阅读(21)  评论(0)    收藏  举报