linux☞ubuntu20.04纯命令行网卡配置

阅读量: zyh 2020-11-16 15:04:08
Categories: > Tags:

前言

netplan 用于屏蔽各种网络管理器,它可以让你用一份配置,就帮你把网络给配置好,而无需你考虑网络控制器如何使用。

20.04 已经默认安装了 netplan.

记录当前网卡标识名

ip addr show 
# ===
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host
       valid_lft forever preferred_lft forever
2: enp0s31f6: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
    link/ether d8:9e:f3:31:83:c8 brd ff:ff:ff:ff:ff:ff

例如上述中的 enp0s31f6

编辑配置文件

cat /etc/netplan/00-installer-config.yaml
# ===
# This is the network config written by 'subiquity'
network:
  ethernets:
    enp0s31f6:
      addresses: [10.200.10.2/24]
      dhcp4: no
      optional: true
      gateway4: 10.200.10.1
      nameservers:
        addresses: [10.200.10.1]
  version: 2
  renderer: networkd

加载配置

netplan apply
systemctl restart networkd-dispatcher.service

之后如果再修改 ip, 再次执行 netplay apply 即可

参考

https://netplan.io/examples/#configuration