文章目录

  • ​​一、修改01-network-manager-all.yaml文件​​
  • ​​二、修改resolved.conf文件​​
  • ​​三、网络IP相关知识​​

一、修改01-network-manager-all.yaml文件

先备份​​01-network-manager-all.yaml​​文件:

cp /etc/netplan/01-network-manager-all.yaml /etc/netplan/01-network-manager-all.yaml.bak

打开​​01-network-manager-all.yaml​​文件:

sudo vi /etc/netplan/01-network-manager-all.yaml

修改成以下内容:

#Let NetworkManager manage all devices on this system
network:
version: 2
# renderer: NetworkManager
ethernets:
eth0:
addresses: [168.168.100.111/16]
gateway4: 168.168.0.1
dhcp4: no
dhcp6: no
nameservers:
addresses: [127.0.0.53, 114.114.114.114, 114.114.115.115, 8.8.8.8, 8.8.4.4]

注意:

  • ​eth0​​​为网络设备接口名称,​​addressed​​​为需要配置的ip地址信息,后面的​​16​​​为子网掩码,代表​​255.255.0.0​​​,需要用命令​​ifconfig -a​​查看自己的网络信息进行配置
  • ​gateway4​​​为​​ip4​​​网关,不清楚网关可执行命令​​route -n​​进行查看
  • ​nameservers​​​下​​addresses​​​为​​DNS​​​地址,国内一般选择​​114.114.114.114​​​或者​​114.114.115.115​

二、修改resolved.conf文件

先备份​​resolved.conf​​文件:

cp /etc/systemd/resolved.conf /etc/systemd/resolved.conf.bak

打开​​resolved.conf​​文件:

sudo vi /etc/systemd/resolved.conf

修改成以下内容:

#  This file is part of systemd.
#
# systemd is free software; you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation; either version 2.1 of the License, or
# (at your option) any later version.
#
# Entries in this file show the compile time defaults.
# You can change settings by editing this file.
# Defaults can be restored by simply deleting this file.
#
# See resolved.conf(5) for details

[Resolve]
DNS=127.0.0.53 114.114.114.114 114.114.115.115 8.8.8.8 8.8.4.4
#FallbackDNS=
#Domains=
#LLMNR=no
#MulticastDNS=no
#DNSSEC=no
#Cache=yes
#DNSStubListener=yes

三、网络IP相关知识

如果想了解网络IP相关知识,推荐参考文章: