我刚刚将一台机器迁移到 Ubuntu 22.04。网络配置仍然通过 /etc/network/interfaces 进行:
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).
# The loopback network interface
auto lo
iface lo inet loopback
# The primary network interface
auto eth0
# iface eth0 inet dhcp
iface eth0 inet static
address 192.168.1.105
netmask 255.255.255.0
network 192.168.1.0
broadcast 192.168.1.255
gateway 192.168.1.1
dns-nameservers 192.168.1.100 192.168.1.104
dns-search example.com
dns-domain example.com
问题是,从 20.04 升级到 22.04 后,DNS 解析不再起作用。没有解析 DNS 名称。
/etc/resolv.conf:
# cat /etc/resolv.conf
# Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8)
# DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN
# 127.0.0.53 is the systemd-resolved stub resolver.
# run "systemd-resolve --status" to see details about the actual nameservers.
nameserver 127.0.0.53
search DOMAINS
resolvectl 的输出:
# resolvectl
Global
Protocols: -LLMNR -mDNS -DNSOverTLS DNSSEC=no/unsupported
resolv.conf mode: foreign
DNS Domain: DOMAINS
Link 2 (eth0)
Current Scopes: none
Protocols: -DefaultRoute +LLMNR -mDNS -DNSOverTLS DNSSEC=no/unsupported
DNS Domain: DOMAINS
我尝试通过在 /etc/netplan 中创建新的 netplan 配置并删除 /etc/network/interfaces 来解决这个问题,但是这让我根本没有有效的网络配置(即使安装了 netplan)。
那么请问我该如何启用 netplan 和 /etc/network/interfaces?(希望这可以修复当前网络配置出现的所有问题 - 但我想,无论如何,转移到当前首选的软件包应该不是什么大问题。)
仅供参考,我为 netplan 创建了 yaml,但这对名称解析没有帮助:
network:
ethernets:
ens18:
dhcp4: no
addresses: [192.168.1.117/24]
routes:
- to: default
via: 192.168.1.1
nameservers:
search: [example.com]
addresses: [192.168.1.100,192.168.1.104]
version: 2
编辑:如果我将 netplan 配置更改为 dhcp,网络就可以正常工作。我仍然想知道如何让这个更新的系统进入 netplan 使用静态地址的状态。在全新安装的 Ubuntu 22.04 中,我对 netplan 静态地址没有任何问题。
答案1
您缺少网关。您必须有类似的东西:
network:
ethernets:
ens18:
dhcp4: no
addresses: [192.168.1.117/24]
gateway4: 192.168.1.1
nameservers:
search: [example.com]
addresses: [192.168.1.100,192.168.1.104]
version: 2