关于ubuntu:Ubuntu-通过-Netplan-配置网络教程

2次阅读

共计 3398 个字符,预计需要花费 9 分钟才能阅读完成。

Ubuntu 通过 Netplan 配置网络教程

Ubuntu through Netplan configuration network tutorial

一、Netplan 配置流程

1. Netplan configuration process

1、Netplan 默认配置文件在 /etc/netplan 目录下。您能够应用以下命令找到:

1. The default configuration file of Netplan is in the /etc/netplan directory. You can find it with the following command:

ls /etc/netplan/

就能够看到配置文件名称。

You can see the configuration file name.

2、查看 Netplan 网络配置文件的内容,执行以下命令:

2. View the contents of the Netplan network configuration file and execute the following command:

cat /etc/netplan/*.yaml

3、当初你须要在任何编辑器中关上配置文件:因为我应用 vim 编辑器来编辑配置文件,所以我将运行:

3. Now you need to open the configuration file in any editor: Since I use the vim editor to edit the configuration file, I will run:

vim /etc/netplan/*.yaml

依据您的网络须要更新配置文件。对于动态 IP 寻址,增加 IP 地址、网关、DNS 信息,而对于动静 IP 寻址,无需增加此信息,因为它将从 DHCP 服务器获取此信息。应用以下语法编辑配置文件。

Update the configuration file according to your network needs. For static IP addressing, add IP address, gateway, DNS information, and for dynamic IP addressing, there is no need to add this information because it will get this information from the DHCP server. Use the following syntax to edit the configuration file.

4、在利用任何更改之前,咱们将测试配置文件。

4. We will test the configuration file before applying any changes.

sudo netplan try

如果没有问题,它将返回配置承受音讯。如果配置文件未通过测试,它将复原为以前的工作配置。

If there is no problem, it will return a configuration acceptance message. If the configuration file fails the test, it will revert to the previous working configuration.

5、运行以下命令来利用新配置:

5. Run the following command to apply the new configuration:

sudo netplan apply

6、胜利利用所有配置后,通过运行以下命令重新启动 Network-Manager 服务:

6. After successfully applying all the configurations, restart the Network-Manager service by running the following command:

如果是桌面版:

If it is the desktop version:

sudo systemctl restart system-networkd

如果您应用的是 Ubuntu 服务器,请改用以下命令:

If you are using an Ubuntu server, use the following command instead:

sudo systemctl restart network-manager

7、验证 IP 地址

7. Verify the IP address

ip a

二、Netplan 配置文件详解

2. Detailed explanation of Netplan configuration file

1、应用 DHCP:

1. Use DHCP:

network:
  version: 2
  renderer: networkd
  ethernets:
    enp3s0:
      dhcp4: true

2、应用动态 IP:

2. Use static IP:

network:
  version: 2
  renderer: networkd
  ethernets:
    enp3s0:
      addresses:
        - 10.0.0.10/8
      gateway4: 10.0.0.1
      nameservers:
          search: [mydomain, otherdomain]
          addresses: [10.0.0.5, 1.1.1.1]

3、多个网口 DHCP:

3. Multiple network ports DHCP:

network:
  version: 2
  ethernets:
    enred:
      dhcp4: yes
      dhcp4-overrides:
        route-metric: 100
    engreen:
      dhcp4: yes
      dhcp4-overrides:
        route-metric: 200

4、连贯凋谢的 WiFi(无明码):

4. Connect to open WiFi (without password):

network:
  version: 2
  wifis:
    wl0:
      access-points:
        opennetwork: {}
      dhcp4: yes

5、连贯 WPA 加密的 WiFi:

5. Connect to WPA encrypted WiFi:

network:
  version: 2
  renderer: networkd
  wifis:
    wlp2s0b1:
      dhcp4: no
      dhcp6: no
      addresses: [10.0.0.10/8]
      gateway4: 10.0.0.1
      nameservers:
        addresses: [10.0.0.5, 8.8.8.8]
      access-points:
        "network_ssid_name":
          password: "**********"

6、在单网卡上应用多个 IP 地址(同一网段):

6. Use multiple IP addresses on a single network card (same network segment):

network:
  version: 2
  renderer: networkd
  ethernets:
    enp3s0:
     addresses:
       - 10.0.0.10/8
       - 10.0.0.10/8
     gateway4: 10.0.0.1

7、在单网卡应用多个不同网段的 IP 地址:

7. Use multiple IP addresses of different network segments on a single network card:

network:
  version: 2
  renderer: networkd
  ethernets:
    enp3s0:
     addresses:
       - 9.0.0.9/24
       - 10.0.0.10/24
       - 11.0.0.11/24
     #gateway4:    # unset, since we configure routes below
     routes:
       - to: 0.0.0.0/0
         via: 9.0.0.1
         metric: 100
       - to: 0.0.0.0/0
         via: 10.0.0.1
         metric: 100
       - to: 0.0.0.0/0
         via: 11.0.0.1
         metric: 100

Linux 运维交换社区

Linux 运维交换社区,互联网新闻以及技术交换。

35 篇原创内容

公众号

正文完
 0