我需要向我的 ubnutu 20.04 服务器(使用 netplan)添加第二个网络和第二个网关。设置如下:
Ubuntu 服务器:
interface: ens18
IP: 192.168.20.2
gateway: 192.168.20.1
netmask: 255.255.255.0
我需要添加第二个网络 (192.168.30.2/24) 和第二个路由器 (192.168.30.1) 作为服务器网关。此路由器与外部网络有不同的 VPN 连接。
我还需要向 ubuntu 服务器添加静态路由以便使用第二个路由器的 vpn 连接,如下所示:
route XXX.YYY.0.0 MASK 255.255.0.0 via gateway 192.168.30.1
route XXX.ZZZ.0.0 MASK 255.255.0.0 via gateway 192.168.30.1
route XXX.XXX.0.0 MASK 255.255.0.0 via gateway 192.168.30.1
route WWW.XYZ.0.0 MASK 255.254.0.0 via gateway 192.168.30.1
route QQQ.PPP.RRR.0 MASK 255.255.255.0 via gateway 192.168.30.1
在 Windows 中我使用以下命令添加静态路由:
route add XXX.YYY.0.0 MASK 255.255.0.0 192.168.30.1 -p
...
我当前的 netplan YAML 是:
# This is the network config written by 'subiquity'
network:
ethernets:
ens18:
addresses: [192.168.20.2/24]
dhcp4: no
gateway4: 192.168.20.1
nameservers:
addresses: [192.168.20.1, 8.8.8.8]
version: 2
# renderer: networkd
# renderer: NetworkManager
我怎样才能实现这个网络?
答案1
在这种情况下,YAML 文件可能如下所示:
# This is the network config written by 'subiquity'
network:
version: 2
renderer: networkd
ethernets:
ens18:
addresses: [192.168.20.2/24, 192.168.30.2/24]
dhcp4: no
gateway4: 192.168.20.1
nameservers:
addresses: [192.168.20.1, 192.168.30.1]
search: []
routes:
- to: ZZZ.ZZZ.0.0/15
via: 192.168.30.1
- to: XXX.XXX.0.0/16
via: 192.168.30.1
- to: XXX.VVV.0.0/16
via: 192.168.30.1
- to: XXX.HHH.0.0/16
via: 192.168.30.1
- to: YYY.OOO.220.0/24
via: 192.168.30.1