免责声明:直到今天,我一直是一个潜水员,仍在学习,这是两年来我第一次没有找到我的问题的答案,非常感谢你的阅读,我希望你能花点时间帮助我
我正在尝试在现有的 LAN 卡上设置两个 VLAN,此设置的目的是先使第一个 VLAN 工作,然后再让所有内容通过不同的 VLAN 用于不同的目的
这是我的配置:
網卡:
cat /etc/netplan/10-enp1s0.yaml network: version: 2 renderer: networkd ethernets:
#LAN CARD config
enp1s0:
optional: true
dhcp4: false
dhcp6: false
addresses: [192.168.1.91/24, ]
gateway4: 192.168.1.254
nameservers:
addresses: [192.168.1.91, ] //I have a DNS on the server
search: [domain.net]
虚拟局域网(VLAN):
cat /etc/netplan/11-vlan.11.yaml
vlans:
vlan.11:
id: 11
link: enp1s0
optional: true
dhcp4: false
dhcp6: false
addresses: [192.168.1.92/24, ]
nameservers:
addresses: [192.168.1.91, ]
使用此配置,结果如下:
- 当我尝试从 enp1s0 ping vlan.11 或反之时,我没有得到回复。
- 当我尝试从 enp1s0 ping 任何互联网时,它可以工作,但是当我尝试使用 vlan.11 时,它不起作用。
8.8.8.8 与 enp1s0:
ping -I enp1s0 8.8.8.8
PING 8.8.8.8 (8.8.8.8) from 192.168.1.91 enp1s0: 56(84) bytes of data.
64 bytes from 8.8.8.8: icmp_seq=1 ttl=57 time=9.24 ms
8.8.8.8 与 vlan.11:
ping -I vlan.11 8.8.8.8
PING 8.8.8.8 (8.8.8.8) from 192.168.1.92 vlan.11: 56(84) bytes of data.
3 packets transmitted, 0 received, 100% packet loss, time 2039ms
- 最后也是最奇怪的是,我能够使用同一网络上的另一台 PC ping 这两个地址
Pinging 192.168.1.91 with 32 bytes of data: Reply from 192.168.1.91:
bytes=32 time<1ms TTL=64
Pinging 192.168.1.92 with 32 bytes of data: Reply from 192.168.1.92:
bytes=32 time<1ms TTL=64 Reply from 192.168.1.92: bytes=32 time<1ms
TTL=64
那么,您能解释一下为什么我的 VLAN 无法正常工作吗?我缺少什么才能让 VLAN.11 像网卡一样运行。
非常感谢您的阅读,我们非常感谢您的帮助。
当我输入 sudo netplan --debug generate 时,我看到了这个(不要担心 enp2s0,目前尚未配置也未连接):
sudo netplan --debug generate
DEBUG:command generate: running ['/lib/netplan/generate']
** (generate:9423): DEBUG: 11:30:08.752: Processing input file /etc/netplan/10-enp1s0.yaml..
** (generate:9423): DEBUG: 11:30:08.752: starting new processing pass
** (generate:9423): DEBUG: 11:30:08.752: Processing input file /etc/netplan/11-vlan.11.yaml..
** (generate:9423): DEBUG: 11:30:08.752: starting new processing pass
** (generate:9423): DEBUG: 11:30:08.752: Processing input file /etc/netplan/20-enp2s0.yaml..
** (generate:9423): DEBUG: 11:30:08.752: starting new processing pass
** (generate:9423): DEBUG: 11:30:08.752: vlan.11: setting default backend to 1
** (generate:9423): DEBUG: 11:30:08.752: Configuration is valid
** (generate:9423): DEBUG: 11:30:08.752: enp2s0: setting default backend to 1
** (generate:9423): DEBUG: 11:30:08.752: Configuration is valid
** (generate:9423): DEBUG: 11:30:08.752: enp1s0: setting default backend to 1
** (generate:9423): DEBUG: 11:30:08.752: Configuration is valid
** (generate:9423): DEBUG: 11:30:08.752: Generating output files..
** (generate:9423): DEBUG: 11:30:08.752: NetworkManager: definition enp1s0 is not for us (backend 1)
** (generate:9423): DEBUG: 11:30:08.752: NetworkManager: definition vlan.11 is not for us (backend 1)
** (generate:9423): DEBUG: 11:30:08.752: NetworkManager: definition enp2s0 is not for us (backend 1)
答案1
您的.yaml 文件不完整。
你不能”删除我的 LAN 卡配置“。
删除两个 .yaml 文件并尝试此操作...保持相同的间距和缩进,并且没有制表符...
network:
version: 2
renderer: networkd
ethernets:
enp1s0:
addresses: [192.168.1.91/24]
gateway4: 192.168.1.254
nameservers:
addresses: 192.168.1.91
search: [domain.net]
optional: true
vlans:
vlan.11:
id: 11
link: enp1s0
addresses: [192.168.1.92/24]
sudo netplan --debug generate
# 生成配置文件
sudo netplan apply
# 应用新配置
reboot
# 重启计算机
答案2
@heynnema:
这是 sudo netplan --debug generate 的输出,我刚刚将 vlan.11 添加到了可选项,因此服务器不会等待 cloud-init
sudo netplan--debug 生成
DEBUG:command generate: running ['/lib/netplan/generate']
** (generate:4851): DEBUG: 23:05:16.984: Processing input file /etc/netplan/10-enp1s0.yaml..
** (generate:4851): DEBUG: 23:05:16.984: starting new processing pass
** (generate:4851): DEBUG: 23:05:16.984: vlan.11: setting default backend to 1
** (generate:4851): DEBUG: 23:05:16.984: Configuration is valid
** (generate:4851): DEBUG: 23:05:16.984: enp1s0: setting default backend to 1
** (generate:4851): DEBUG: 23:05:16.984: Configuration is valid
** (generate:4851): DEBUG: 23:05:16.984: Generating output files..
** (generate:4851): DEBUG: 23:05:16.984: NetworkManager: definition enp1s0 is not for us (backend 1)
** (generate:4851): DEBUG: 23:05:16.984: NetworkManager: definition vlan.11 is not for us (backend 1)
uname -r
4.19.0-041900-generic
dpkg-l 命令网络计划
dpkg -l *netplan*
Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend
|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
||/ Name Version Architecture Description
+++-=====================================================-===============================-===============================-===============================================================================================================
un netplan <none> <none> (no description available)
ii netplan.io 0.98-0ubuntu1~18.04.1 amd64 YAML network configuration abstraction for various backends
我真的希望这能帮助您帮助我解决这个问题,再次感谢您的时间。
答案3
问题解决了 !
而不是 ping 并使用 vlan.11(这是..第 2 层名称?有点像?)
无论如何,直接使用 IP 地址非常有效,简而言之:
ping -I vlan.11 不起作用 ping -I 工作正常!
谢谢你的帮助,希望这对别人有帮助