我正在尝试让一台服务器运行 2 个网卡。一个网卡将具有动态 ip(DHCP),另一个网卡将具有静态 ip 192.168.0.24
。我在这个服务器上有 2 个网卡,1GB(enp4s0)和 10GB(enp5s0)
我当前全新安装的操作系统:
oven@oven-f1:~$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 22.04.5 LTS
Release: 22.04
Codename: jammy
此 netplan 是使用默认网络配置全新安装操作系统时附带的默认 netplan:
oven@oven-f1:~$ sudo cat /etc/netplan/50-cloud-init.yaml
# This file is generated from information provided by the datasource. Changes
# to it will not persist across an instance reboot. To disable cloud-init's
# network configuration capabilities, write a file
# /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg with the following:
# network: {config: disabled}
network:
ethernets:
enp4s0:
dhcp4: true
version: 2
wifis: {}
此 netplan 的网卡状态:
oven@oven-f1:~$ ip link show
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
2: enp4s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP mode DEFAULT group default qlen 1000
link/ether d8:43:ae:90:b8:2e brd ff:ff:ff:ff:ff:ff
3: enp5s0: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN mode DEFAULT group default qlen 1000
link/ether 74:fe:ce:ea:db:b5 brd ff:ff:ff:ff:ff:ff
此 netplan 配置的默认路由:
oven@oven-f1:~$ ip route
default via 192.168.0.1 dev enp4s0 proto dhcp src 192.168.0.27 metric 100
192.168.0.0/24 dev enp4s0 proto kernel scope link src 192.168.0.27 metric 100
192.168.0.1 dev enp4s0 proto dhcp scope link src 192.168.0.27 metric 100
以下是我尝试实现的新 netplan 配置:
network:
version: 2
renderer: networkd
ethernets:
enp4s0:
dhcp4: true
enp5s0:
dhcp4: true
addresses:
- 192.168.0.24/24
routes:
- to: 0.0.0.0/0
via: 192.168.0.1
nameservers:
addresses: [8.8.8.8, 8.8.4.4]
问题是,一旦我sudo netplan --debug apply
使用新配置运行:
oven@oven-f1:~$ sudo netplan --debug apply
** (generate:1778): DEBUG: 07:51:08.869: starting new processing pass
** (generate:1778): DEBUG: 07:51:08.869: enp5s0: adding new route
** (generate:1778): DEBUG: 07:51:08.869: starting new processing pass
** (generate:1778): DEBUG: 07:51:08.869: We have some netdefs, pass them through a final round of validation
** (generate:1778): DEBUG: 07:51:08.869: enp4s0: setting default backend to 1
** (generate:1778): DEBUG: 07:51:08.869: Configuration is valid
** (generate:1778): DEBUG: 07:51:08.869: enp5s0: setting default backend to 1
** (generate:1778): DEBUG: 07:51:08.869: Configuration is valid
** (generate:1778): DEBUG: 07:51:08.869: Generating output files..
** (generate:1778): DEBUG: 07:51:08.869: Open vSwitch: definition enp4s0 is not for us (backend 1)
** (generate:1778): DEBUG: 07:51:08.869: NetworkManager: definition enp4s0 is not for us (backend 1)
** (generate:1778): DEBUG: 07:51:08.869: Open vSwitch: definition enp5s0 is not for us (backend 1)
** (generate:1778): DEBUG: 07:51:08.869: NetworkManager: definition enp5s0 is not for us (backend 1)
** (process:1776): DEBUG: 07:51:09.042: starting new processing pass
** (process:1776): DEBUG: 07:51:09.042: enp5s0: adding new route
** (process:1776): DEBUG: 07:51:09.042: starting new processing pass
** (process:1776): DEBUG: 07:51:09.042: We have some netdefs, pass them through a final round of validation
** (process:1776): DEBUG: 07:51:09.042: enp4s0: setting default backend to 1
** (process:1776): DEBUG: 07:51:09.042: Configuration is valid
** (process:1776): DEBUG: 07:51:09.042: enp5s0: setting default backend to 1
** (process:1776): DEBUG: 07:51:09.042: Configuration is valid
** (process:1776): DEBUG: 07:51:09.128: starting new processing pass
** (process:1776): DEBUG: 07:51:09.128: enp5s0: adding new route
** (process:1776): DEBUG: 07:51:09.128: starting new processing pass
** (process:1776): DEBUG: 07:51:09.128: We have some netdefs, pass them through a final round of validation
** (process:1776): DEBUG: 07:51:09.128: enp4s0: setting default backend to 1
** (process:1776): DEBUG: 07:51:09.128: Configuration is valid
** (process:1776): DEBUG: 07:51:09.128: enp5s0: setting default backend to 1
** (process:1776): DEBUG: 07:51:09.128: Configuration is valid
** (process:1776): DEBUG: 07:51:09.128: starting new processing pass
** (process:1776): DEBUG: 07:51:09.128: enp5s0: adding new route
** (process:1776): DEBUG: 07:51:09.128: starting new processing pass
** (process:1776): DEBUG: 07:51:09.128: We have some netdefs, pass them through a final round of validation
** (process:1776): DEBUG: 07:51:09.128: enp4s0: setting default backend to 1
** (process:1776): DEBUG: 07:51:09.128: Configuration is valid
** (process:1776): DEBUG: 07:51:09.128: enp5s0: setting default backend to 1
** (process:1776): DEBUG: 07:51:09.128: Configuration is valid
此新 netplan 的网卡状态:
oven@oven-f1:~$ ip link show
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
2: enp4s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP mode DEFAULT group default qlen 1000
link/ether d8:43:ae:90:b8:2e brd ff:ff:ff:ff:ff:ff
3: enp5s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP mode DEFAULT group default qlen 1000
link/ether 74:fe:ce:ea:db:b5 brd ff:ff:ff:ff:ff:ff
使用此新 netplan 配置的默认路由:
oven@oven-f1:~$ ip route
default via 192.168.0.1 dev enp5s0 proto static
default via 192.168.0.1 dev enp4s0 proto dhcp src 192.168.0.27 metric 100
192.168.0.0/24 dev enp5s0 proto kernel scope link src 192.168.0.24
192.168.0.0/24 dev enp4s0 proto kernel scope link src 192.168.0.27 metric 100
192.168.0.1 dev enp4s0 proto dhcp scope link src 192.168.0.27 metric 100
我的配置没有错误,但我失去了对服务器的 ssh 访问权限。我仍然可以从服务器访问互联网并 ssh 到其他机器,但我无法从我的笔记本电脑 ssh 到服务器。
我无法 ping 通服务器,但仍然可以看到它的地址:
s@M1 ~ % nslookup oven-f1
Server: 2001:8003:d44e:7600::1
Address: 2001:8003:d44e:7600::1#53
Name: oven-f1.modem
Address: 192.168.0.27
s@M1 ~ % ping oven-f1
PING oven-f1.modem (192.168.0.27): 56 data bytes
Request timeout for icmp_seq 0
Request timeout for icmp_seq 1
Request timeout for icmp_seq 2
Request timeout for icmp_seq 3
^C
--- oven-f1.modem ping statistics ---
5 packets transmitted, 0 packets received, 100.0% packet loss
我不确定为什么在启用 2 个网卡后无法通过 ssh 进入服务器,任何帮助都将不胜感激,因为我陷入了困境
编辑答案更新
以下是有效的 netplan 配置。我只是将 10GB 卡和 10GB 交换机分成不同的子网192.168.1.0/24
,并保持 1GB 卡和交换机处于开启状态192.168.0.0/24
。
network:
version: 2
renderer: networkd
ethernets:
enp4s0:
dhcp4: true
enp5s0:
dhcp4: false
addresses:
- 192.168.1.24/24
还更新了服务器上的 hosts 文件以映射子网上的192.168.1.0/24
主机