![如何在 Ubuntu 20+ 上使用 NetPlan 添加黑洞路由](https://linux22.com/image/200640/%E5%A6%82%E4%BD%95%E5%9C%A8%20Ubuntu%2020%2B%20%E4%B8%8A%E4%BD%BF%E7%94%A8%20NetPlan%20%E6%B7%BB%E5%8A%A0%E9%BB%91%E6%B4%9E%E8%B7%AF%E7%94%B1.png)
我需要有关通过 Netplan.io 管理的本地主机接口添加黑洞路由的建议。
我的配置不起作用:
network:
version: 2
ethernet:
lo:
match:
name: lo
routes:
- to: 2001:db8:1::/48
type: blackhole
metric: 254
enp1s0:
accept-ra: true
dhcp4: false
dhcp6: false
match:
macaddress: aa:bb:cc:dd:ee:ff
set-name: enp1s0
addresses:
- 1.1.1.2/24
- 2001:db8:1::2/64
routes:
- to: default
via: 1.1.1.1
- to: default
via: 2001:db8:1::1
但与此同时,如果我尝试使用物理以太网适配器定义黑洞路由,它会神奇地起作用:
network:
version: 2
ethernet:
enp1s0:
accept-ra: true
dhcp4: false
dhcp6: false
match:
macaddress: aa:bb:cc:dd:ee:ff
set-name: enp1s0
addresses:
- 1.1.1.2/24
- 2001:db8:1::2/64
routes:
- to: 2001:db8:1::/48
type: blackhole
metric: 254
- to: default
via: 1.1.1.1
- to: default
via: 2001:db8:1::1
我做错了什么或建议如何以其他方式添加黑洞路由?
答案1
你必须设置通过参数,因为 netplan 忽略没有它的规则