网卡配置
ubuntu@p006:~$ # 普通用户
ubuntu@p006:~$ sudo su - # 提权root
[sudo] password for ubuntu:
(venv) root@p006:~# vim /etc/netplan/00-installer-config.yaml # 编辑网卡
# This is the network config written by 'subiquity'
network:
ethernets:
eno1:
addresses:
- 10.12.1.6/21
gateway4: 10.12.1.254
nameservers:
addresses:
- 114.114.114.114
search: []
version: 2
(venv) root@p006:~# netplan apply # 将当前网络计划配置应用于运行中的系统
DNS配置
(venv) root@p006:/etc# vim /etc/systemd/resolved.conf
DNS=114.114.114.114
(venv) root@p006:/etc# systemctl restart systemd-resolved
(venv) root@p006:/etc# systemctl enable systemd-resolved
(venv) root@p006:/etc# mv /etc/resolv.conf /etc/resolv.conf.bak
(venv) root@p006:/etc# ln -s /run/systemd/resolve/resolv.conf /etc/
(venv) root@p006:/etc# ping baidu.com
PING baidu.com (220.181.38.251) 56(84) bytes of data.
64 bytes from 220.181.38.251 (220.181.38.251): icmp_seq=1 ttl=47 time=15.0 ms
还有一种方法,结果就是重启之后就失效了,内容也还原了,原因就是 /etc/resolv.conf 文件中的第一行写了 “Do not edit”
(venv) root@p006:~# vim /etc/resolv.conf
# This file is managed by man:systemd-resolved(8). Do not edit.
#
# This is a dynamic resolv.conf file for connecting local clients to the
# internal DNS stub resolver of systemd-resolved. This file lists all
# configured search domains.
#
# Run "resolvectl status" to see details about the uplink DNS servers
# currently in use.
#
# Third party programs must not access this file directly, but only through the
# symlink at /etc/resolv.conf. To manage man:resolv.conf(5) in a different way,
# replace this symlink by a static file or a different symlink.
#
# See man:systemd-resolved.service(8) for details about the supported modes of
# operation for /etc/resolv.conf.
nameserver 127.0.0.53
options edns0 trust-ad
nameserver 114.114.114.114
(venv) root@p006:/etc# systemctl restart systemd-resolved