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

ps:

同时 知乎、CSDN、开源中国、思否、掘金、哔哩哔哩 有文章同步

https://blog.csdn.net/qq_33921750

https://my.oschina.net/u/3981543

https://www.zhihu.com/people/chen-bu-yun-2

https://segmentfault.com/u/hppyvyv6/articles

https://juejin.cn/user/3315782802482007

https://space.bilibili.com/352476552/article

并在小站上更新部分文章

https://www.chenby.cn/index.php/blog/

首页:https://www.chenby.cn/

Ubuntu 通过 Netplan 配置网络教程的更多相关文章

  1. ubuntu server 1604 配置网络信息

    对于新安装的linux 服务器(ubuntu server 1604)   一,配置网络 连接网线与路由器 查看系统的网卡信息 ifconfig -a //列出所有的网卡信息,不管启用还是没有启用的 ...

  2. Ubuntu 16.04配置OpenGL教程

    sudo apt-get install build-essential sudo apt-get install libgl1-mesa-dev sudo apt-get install libgl ...

  3. (实用)Ubuntu Linux静态IP网络配置

    记录备忘. 基于Ubuntu 14.04 LTS Server. 首先查看一下当前系统的网卡: $ sudo iconfig 比如这里我除了回环网路lo外,网络接口名为em1,下面就去给它配置网络. ...

  4. Ubuntu 18.04 的网络配置

    netplan简介 目前,ubuntu18.04上使用了netplan 作为网络配置工具:在终端上配置网络参数跟之前的版本有比较大的差别 Netplan工作流程如下图所示:通过读取  /etc/net ...

  5. ubuntu server 18.04的安装 以及配置网络还有ssh服务

    ubuntu server 18.04的安装 以及配置网络还有ssh服务   服务器是 dell T420 安装过程中规中矩,其中最关键的是分区部分,由于是服务器,如果磁盘比较大的话,一定要用 uef ...

  6. Ubuntu配置网络遇到的一些问题

    Ubuntu配置网络遇到的一些问题 在配置Ubuntu网络时,曾遇到了一些问题.查找了一些博客,所幸都解决了.记录一下,以便日后查阅. 设置DNS sudo vim /etc/resolv.conf ...

  7. Ubuntu 16.04通过网络配置工具NetworkManager设置IP、网关、DNS和查看IP、网关、DNS

    说明: 1.NetworkManager工具是Ubuntu桌面版的GUI设置工具. 2.这个工具推荐直接在GUI上操作,不建议用命令行进行管理,比如Wifi这些配置等. 3.当然,这个工具能带有命令行 ...

  8. Ubuntu下Maven配置与Maven项目创建教程

    一. Ubuntu下Maven配置 windows下Maven配置参考http://www.cnblogs.com/LexMoon/p/JavaMaven.html ubuntu下Maven地址htt ...

  9. ubuntu配置网络和静态路由(界面配置形式)

    目录 网卡配置 静态ip配置 静态路由 外网ip配置(动态获取DHCP) 内网ip和静态路由配置 本文主要针对ubuntu18.0系统进行界面形式配置网络.并配置静态路由. 网卡配置 静态ip配置 打 ...

  10. ubuntu 18.04配置静态ip,解决无法上网问题,解决resolv.conf配置文件被覆盖

    Netplan 是 Ubuntu 17.10 中引入的一种新的命令行网络配置实用程序,用于在 Ubuntu 系统中轻松管理和配置网络设置. 它允许您使用 YAML 格式的描述文件来抽像化定义网络接口的 ...

随机推荐

  1. Element UI 父组件el-tabel选择某行跳转子组件,在子组件的el-table中选择数组,添加到父组件操作行中

    解决思路: 1.在父组件选择操作某行数据时,将父组件的行号暂存(index). 2.跳转子组件页面,选择某行数据,点击提交将该行数据传递个父组件 3.父组件取到第一步暂存行号(index),将子组件传 ...

  2. CSS vw与vh动态设置元素的高度宽度

    做为一个前端开发者,总有一天我们要设置页面某一部分内容自适应浏览器窗口大小,下面分享下使用vw和vh的设置方式, 一波解释: v(即viewport):可视窗口,也就是浏览器窗口大小.vw Viewp ...

  3. 关于VScode里TS文件内引入插件没有提示内置属性和方法这件事

    前几天使用VScode + Vue + Vite + Ts开发项目 由于自己手残 把VScode设置文件的代码做了一些修改 导致TS文件引入的插件没有提示了!! 几经折腾下 终于靠自己解决了! 不多说 ...

  4. new一个实例的原理及过程

    前提,要明白new出来的实例是什么,包含了哪些内容? 请看一下举例代码↓↓↓↓ function Person(name,age){ this.name = name; this.age = age; ...

  5. Q:带宽检测 iperf工具

    一.下载 iperf的下载地址为:https://iperf.fr/iperf-download.php,选择相应的版本 linux安装 rpm -qa|grep -i rperf rpm -ivh ...

  6. 11、jmeter配置元件--计数器

    前面学过csv和变量 csv里面的数据是固定的  如果里面的数据不够  线程要么就停止要么就需要重头再来 不太灵活 用到固定化的数据,比如说多少个用户等等 如果有一些是变动的 随着线程数增加   数据 ...

  7. bitmap_find_next_zero_area_off函数

    备注:

  8. 静态类型和动态类型VS强类型和弱类型

    强类型语言和静态类型语言有什么区别? 静态类型的语言具有类型系统,该类型系统在实现时由实现(编译器或解释器)检查.类型检查拒绝某些程序,并且通过检查的程序通常带有一些保证.例如,编译器保证不对浮点数使 ...

  9. webpack 3/4踩坑,我太难了,从安装、卸载、到使用,各相应的版本号,sass-loader报错-版本的原因,webpack -v 不识别,没卸载干净

     -先说卸载: wabpack@4对应的每个插件的版本号都在最后 1 全局安装的话,npm uninstall webpack -g 有时候并不能卸载干净, 2 webpack -v 可判断是否安装成 ...

  10. C/C++ 异常处理机制(例:文件拷贝)

    异常是一种程序控制机制,与函数机制互补. 函数是一种以栈结构展开的上下函数衔接的程序控制系统,异常是另一种控制结构,它可以在出现"意外"时中断当前函数,并以某种机制(类型匹配)回馈 ...