woshikid / blog

Apache License 2.0
8 stars 1 forks source link

systemd-resolved学习笔记 #195

Open woshikid opened 1 year ago

woshikid commented 1 year ago

查看状态

resolvectl status

配置resolved vi /etc/systemd/resolved.conf(Global)

[Resolve]
DNS=8.8.8.8 # 手动设置上游dns
Cache=yes # 启用缓存(默认值)
DNSStubListenerExtra=192.168.1.100 # 设置额外监听地址
ReadEtcHosts=yes # 读取/etc/hosts(默认值)
ResolveUnicastSingleLabel=no # 递归查找不带点的本地域名,默认为no

vi /etc/netplan/00-installer-config.yaml

network:
  version: 2
  ethernets:
    ens160:
      dhcp4: no # 不自动获取IP
      addresses:
        - 192.168.1.100/24 # 手动设置IP
      routes:
        - to: default
          via: 192.168.1.1 # 设置默认网关
      dhcp4-overrides:
        use-dns: no # 不使用默认上游dns
        use-domains: no # 不使用默认搜索域
      nameservers:
        addresses: [8.8.8.8] # 手动设置上游dns
        search: ["example.com"] # 手动设置搜索域

配置生效

sudo systemctl restart systemd-resolved
sudo netplan apply