我看过其他几篇关于“gateway4 已被弃用”的帖子,警告有些人在进入sudo netplan apply
.我的问题略有不同:即使我的 .yaml 配置文件中没有“gateway4”行,我也会收到该警告。
在无头服务器上运行 Ubuntu 22.04.1。
这是 .yaml 文件:
network:
version: 2
renderer: networkd
ethernets:
enp0s31f6:
addresses:
- [ipv4 address]/32
- [ipv6 address]/64
routes:
- to: default
via: [gateway ipv4 address here]
metric: 100
on-link: true
- to: ::/0
via: fe80::1
nameservers:
addresses:
- 1.1.1.1
- 2606:4700:4700::1111
- 1.0.0.1
- 2606:4700:4700::1001
为什么我会收到有关 gateway4 已被弃用的警告?
答案1
问题:
在与人互动的同时网络计划一个人的 CLI 输出可能会抱怨:已弃用的“gateway4”语句、路由冲突,甚至是敦促配置“路由策略”的消息。消息例如:
** (generate:13032): WARNING **: 14:00:00.100: 'gateway4' has been deprecated, use default routes instead. See the 'Default routes' section of the documentation for more details.
。
** (process:4389): WARNING **: 14:00:00.200: gateway4 has been deprecated, use default routes instead. **
。
** (process:13030): WARNING **: 14:00:00.300: Problem encountered while validating default route consistency. Please set up multiple routing tables and use `routing-policy` instead.
Error: Conflicting default route declarations for IPv4 (table: main, metric: default), first declared in eno1 but also in eno1
使固定:让 netplan 按预期工作二脚步。
首先,遍历/etc/netplan/00-installer-config.yaml
(或类似),如果尚未更改,请将“地址”字段的语法从两行格式更改为单行格式 - 如下所示:
地址字段;两行格式
[...]
addresses:
- i.p.v.4/24
[...]
地址字段;单线格式-更改为这个
[...]
addresses: [ "i.p.v.4/24" ]
[...]
以前的 /etc/netplan/00-installer-config.yaml
两行“地址”字段
network:
version: 2
renderer: networkd
ethernets:
eno1:
addresses:
- i.p.v.4/24
nameservers:
search: [sub.domain.tld, domain.tld]
addresses: [d.n.s.a, d.n.s.b, d.n.s.c]
routes:
- to: 0.0.0.0/0
via: i.p.v.4
on-link: true
更新 /etc/netplan/00-installer-config.yaml
单行“地址”字段
network:
version: 2
renderer: networkd
ethernets:
eno1:
addresses: [ "i.p.v.4/24" ]
nameservers:
search: [sub.domain.tld, domain.tld]
addresses: [d.n.s.a, d.n.s.b, d.n.s.c]
routes:
- to: 0.0.0.0/0
via: i.p.v.4
on-link: true
下一个,遍历/run/netplan/eno1.yaml
(或类似),其中还必须将“地址”字段的格式从两行更改为单行,如上所述。此外,人们可能会发现一个实例'网关4'在这个位置。请务必删除或注释掉它。
以前的 /run/netplan/eno1.yaml
两行“地址”字段+网关4
network:
version: 2
ethernets:
eno1:
addresses:
- i.p.v.4/24
gateway4: "i.p.v.4"
更新 /run/netplan/eno1.yaml
单行“地址”字段 + 无网关4
network:
version: 2
ethernets:
eno1:
addresses: [ "i.p.v.4/24" ]
现在发出:须藤网络计划申请并且不应该有任何错误。
可以通过查看运行配置来确认操作:(/run/systemd/network/10-netplan-eno1.network
或类似)。
[Match]
Name=eno1
[Network]
LinkLocalAddressing=ipv6
Address=i.p.v.4/24
DNS=d.n.s.a
DNS=d.n.s.b
DNS=d.n.s.c
Domains=sub.domain.tld domain.tld
[Route]
Destination=0.0.0.0/0
Gateway=i.p.v.4
GatewayOnLink=true