我有一台 Hetzner 专用服务器,它有一张网卡和两个公共 IP 地址(两个 IP 都有自己的网关)。目前,它只有一个使用 neplan 配置的地址。以下是我的配置
network:
version: 2
renderer: networkd
ethernets:
enp195s0:
addresses:
- x.x.x.x/32 #Main IPv4 address
- xx.xx.xx.xx::2/64 #IPv6
routes:
- on-link: true
to: 0.0.0.0/0
via: gx.gx.gx.gx #Main IPv4 address Gateway IP
nameservers:
addresses:
- 185.12.64.2
- 185.12.64.1
- 2a01:4ff:ff00::add:1
- 2a01:4ff:ff00::add:2
现在我想将网络配置为具有两个公共 IP 作为桥接,因为我想与 kvm 客户机共享它。这是我的一次尝试:
network:
version: 2
renderer: networkd
ethernets:
enp195s0:
dhcp4: false
dhcp6: false
bridges:
kvmbr0:
interfaces:
- enp195s0
addresses:
- x.x.x.x/32 #Main IPv4 address
- y.y.y.y/32 #Additional IPv4 address
routes:
- to: 0.0.0.0/0
via: gx.gx.gx.gx #Main IPv4 address Gateway IP
table: 1
metric: 100
- to: 0.0.0.0/0
via: gy.gy.gy.gy #Additional IPv4 address Gateway IP
table: 2
metric: 200
mtu: 1500
dhcp4: no
dhcp6: no
nameservers:
addresses:
- 185.12.64.2
- 185.12.64.1
- 2a01:4ff:ff00::add:1
- 2a01:4ff:ff00::add:2
parameters:
stp: false
forward-delay: 4
问题是,在应用 netplan 后,我总是会断开互联网连接 :/ 我有一个脚本,如果我不停止它,它会在几分钟后恢复默认的 netplan 配置,所以我很难检查服务器上发生了什么,但我认为这与路由有关。我是 netplan 配置方面的新手,你能帮我找到合适的解决方案吗?
答案1
我找到了解决方案。它如下
network:
version: 2
renderer: networkd
ethernets:
enp195s0:
dhcp4: false
dhcp6: false
bridges:
kvmbr0:
interfaces:
- enp195s0
addresses:
- x.x.x.x/26 # <- netmask here
- y.y.y.y/29 # <- netmask here
routes:
- to: 0.0.0.0/0
via: gx.gx.gx.gx
metric: 100
- to: nx.nx.nx.nx/26 # <- route to main IP network
via: gx.gx.gx.gx # <- via main IP gateway
metric: 100
table: 1 # <- with routing table assignment
- to: 0.0.0.0/0
via: gy.gy.gy.gy
metric: 200
- to: ny.ny.ny.ny/29 # <- route to additional IP network
via: gy.gy.gy.gy # <- via additional IP gateway
metric: 200
table: 2 # <- with routing table assignment
routing-policy: # <- routing policies for IPs networks
- from: nx.nx.nx.nx/26
table: 1 # <- appropriate routing table
- from: ny.ny.ny.ny/29
table: 2 # <- appropriate routing table
dhcp4: no
dhcp6: no
nameservers:
addresses:
- 185.12.64.2
- 185.12.64.1
- 2a01:4ff:ff00::add:1
- 2a01:4ff:ff00::add:2
parameters:
stp: true
forward-delay: 4
主要问题是网络掩码。它不应该是 32 位,因为它们不包含网关 IP。这就是我丢失网络连接的原因。所以我把 IP 地址网络中的正确网络掩码放在那里。
需要进行其他更改以允许其他 IP 与互联网通信。