Networking

如何在具有和不具有 VLAN 橋接設備的網路上同時配置 NIC

  • October 20, 2017

我正在使用具有單個物理乙太網埠的 CentOS 7 系統,該埠將其連接到網路。該網路主要位於一個子網(“管理網路”)上,但也使用一個標記的 VLAN (VLAN 137),該 VLAN 為 VM 提供了一個單獨的子網。

當配置“正常”時 - 它出現並在管理子網上工作。

但是,我想創建一個連接到同一個物理適配器的網橋設備,但要讓網橋使用 137 VLAN。

我不知道該怎麼做。我可以在普通(無標記)LAN 上擁有 NIC,也可以在(主)LAN 或 VLAN 上創建一個橋接設備。但我無法弄清楚如何同時讓主機進入“主”網路和 VLAN 上的網橋。

看起來好像一個 NIC 一次只能分配給一個“網橋”,而一個網橋可以分配給一個 VLAN,或者沒有 VLAN。

我顯然錯過了一些東西。有任何想法嗎?

(PS 最好在沒有網路管理器的情況下這樣做——我認為這是必須的)。

以下配置採用一個 NIC - 為其創建一個 VLAN 介面 - 然後將橋接設備添加到原始 NIC 和 VLAN 介面

ifcfg-br0

BOOTPROTO="static"
DEFROUTE="yes"
NAME="br0"
DEVICE="br0"
ONBOOT="yes"
DNS1="10.244.53.108"
DNS2="10.245.177.15"
DOMAIN="dssdhop.lab.emc.com"
NM_CONTROLLED="no"
TYPE="Bridge"
IPADDR=10.244.141.171
PREFIX=24
GATEWAY=10.244.141.1
DNS1="10.244.53.108"

ifcfg-br0.137

BOOTPROTO="static"
DEFROUTE="yes"
NAME="br0.137"
DEVICE="br0.137"
ONBOOT="no"
DNS1="10.244.53.108"
DNS2="10.245.177.15"
DOMAIN="dssdhop.lab.emc.com"
NM_CONTROLLED="no"
TYPE="Bridge"
# Enable the following 3 IF you want to assign a local address to the host on this network
#IPADDR=10.244.137.54 
#PREFIX=24
#GATEWAY=10.244.137.1  – Generally don't want to specify a gatway - or it'll try using this as a default route!

ifcfg-eno1

TYPE=Ethernet
BOOTPROTO=none
NAME=eno1
UUID=8378a1f0-0330-45c8-bba6-7b77190cfb08
DEVICE=eno1
ONBOOT=yes
NM_CONTROLLED="no"
BRIDGE="br0"

ifcfg-eno1.137

DEVICE=eno1.137
VLAN=yes
ONBOOT=no
BRIDGE=br0.137
NM_CONTROLLED=NO

在沒有使用網橋的情況下,我在虛擬伺服器上進行了以下測試,伺服器具有 eth0 配置。

ip link add link eth0 name eth0.100 type vlan id 100
ip addr add 10.0.0.10/24 dev eth0.100
ip link set eth0.100 up

如果我嘗試ping google.it

[root@localhost ~]# tcpdump -i any not port 22 -nne
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on any, link-type LINUX_SLL (Linux cooked), capture size 262144 bytes
17:49:34.880834 Out 52:54:00:c5:83:ad ethertype IPv4 (0x0800), length 71: 10.0.2.15.57014 > 10.0.2.3.53: 53728+ A? google.it. (27)
17:49:34.928806  In 52:54:00:12:35:02 ethertype IPv4 (0x0800), length 87: 10.0.2.3.53 > 10.0.2.15.57014: 53728 1/0/0 A 216.58.205.99 (43)
17:49:34.929356 Out 52:54:00:c5:83:ad ethertype IPv4 (0x0800), length 100: 10.0.2.15 > 216.58.205.99: ICMP echo request, id 28643, seq 1, length 64
17:49:34.946459  In 52:54:00:12:35:02 ethertype IPv4 (0x0800), length 100: 216.58.205.99 > 10.0.2.15: ICMP echo reply, id 28643, seq 1, length 64
17:49:34.947340 Out 52:54:00:c5:83:ad ethertype IPv4 (0x0800), length 88: 10.0.2.15.35452 > 10.0.2.3.53: 7858+ PTR? 99.205.58.216.in-addr.arpa. (44)
17:49:34.997721  In 52:54:00:12:35:02 ethertype IPv4 (0x0800), length 156: 10.0.2.3.53 > 10.0.2.15.35452: 7858 2/0/0 PTR mil04s26-in-f99.1e100.net., PTR mil04s26-in-f3.1e100.net. (112)

如果嘗試 ping vlan 子網中的主機,您可以看到 vlan 標記:

[root@localhost ~]# tcpdump -i any not port 22 -nne
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on any, link-type LINUX_SLL (Linux cooked), capture size 262144 bytes
17:51:12.237624 Out 52:54:00:c5:83:ad ethertype ARP (0x0806), length 44: Request who-has 10.0.0.11 tell 10.0.0.10, length 28
17:51:12.237628 Out 52:54:00:c5:83:ad ethertype 802.1Q (0x8100), length 48: vlan 100, p 0, ethertype ARP, Request who-has 10.0.0.11 tell 10.0.0.10, length 28
17:51:13.238115 Out 52:54:00:c5:83:ad ethertype ARP (0x0806), length 44: Request who-has 10.0.0.11 tell 10.0.0.10, length 28
17:51:13.238123 Out 52:54:00:c5:83:ad ethertype 802.1Q (0x8100), length 48: vlan 100, p 0, ethertype ARP, Request who-has 10.0.0.11 tell 10.0.0.10, length 28
17:51:14.239809 Out 52:54:00:c5:83:ad ethertype ARP (0x0806), length 44: Request who-has 10.0.0.11 tell 10.0.0.10, length 28

對我來說,您可以在物理介面上擁有管理 ip,而在 vlan 介面上擁有其他 ip

引用自:https://serverfault.com/questions/879327