Vcenter虚拟标准交换机VLAN配置 vlan 虚拟机_linux

Vcenter虚拟标准交换机VLAN配置 vlan 虚拟机_Ethernet_02

linux虚拟网络:vlan设备
个人总结:其实应该把物理网卡eth0看成交换机,同时对外的接口是trunk模式;新创建的vlan设备eth0.30则是access模式;而bridge则是一台可以配置ip的傻瓜交换机(或者说是一台不支持vlan的二层交换机),这台傻瓜交换机是挂在access口下面的。
======================================================================================================
 先安装EPEL(Extra Packages for Enterprise Linux),再安装vconfig的命令如下:
    yum -y install epel-release
    yum -y install vconfig 

查看vlan设备
    lsmod |grep 8021q
    modprobe 8021q
    cat /proc/net/vlan/eth1.100
    cat /proc/net/vlan/config 

创建、删除vlan设备
    vconfig add eth1 40         #方式1;vconfig不是必须的,若没有vconfig则使用方式2
    vconfig rem eth1.40
    ip link add link eth1 name eth1.40 type vlan id 40      #方式2;linux开源网络全栈详解P46

网桥加入or移除vlan设备
    brctl addif brvlan40 eth1.40
    brctl delif brvlan40 eth1.40

linux虚拟网络:vlan设备

 

Vcenter虚拟标准交换机VLAN配置 vlan 虚拟机_linux

Vcenter虚拟标准交换机VLAN配置 vlan 虚拟机_Ethernet_02

linux虚拟网络-vlan实验:2台虚拟机做vlan30和vlan40互通(虚拟机模拟物理机,network namespace充当虚拟机)
====================================================================
创建vlan设备
    vconfig add eth1 30             #物理网卡相当于trunk模式,创建了vlan设备后,相当于trunk允许该vlan通过。
    ip link add link eth1 name eth1.40 type vlan id 40
创建bridge并与vlan设备绑定
    brctl addbr brvlan30
    brctl addif brvlan30 eth1.30    #该bridge允许通过vlan30
    vlan40略……
创建veth pair并绑定到bride
    ip link add type veth           #方式1
    ip link add vlan40_veth type veth peer  name ns40   #方式2
    brctl addif brvlan30 veth1      #绑定后,veth1就是brvlan30的access口(其实我觉得eth1.30这个虚拟子接口相对于eth1来说是access子接口,这种说法更贴切一些。)
    #bridge特性:当一个设备绑定到bridge后,那么该设备配置的IP将失效。linux开源网络全栈详解P33
    vlan40略……
创建network namespace并绑定另一端veth pair
    ip netns add ns30               #创建network namespace
    ip link set veth2 netns ns30    #将veth绑定到network namespace
    ip netns exec ns30 ip add add 30.0.0.111/24 dev veth2       #配置IP
    vlan40略……
使能各种设备
    ip link set brvlan30 up
    ip link set eth1.30 up
    ip link set veth1 up
    ip netns exec ns30 ip link set lo up
    ip netns exec ns30 ip link set veth2 up
    vlan40略……

另一台虚拟机执行类似操作……
---------------------------------------
现象1:两台虚拟机执行相同的操作,虚拟机1的arp报文是携带vlan id;虚拟机2的arp报文不携带vlan id。!!!!!失败!!!!
现象2:重新创建一台虚拟机,执行相同的操作,ping包通了,查看icmp报文,都是携带vlan id的!windows抓包,报文是携带vlan id的。
现象3:在brvlan30上配置ip,也客户抓到两台虚拟机互ping的icmp报文
现象4:将eth1.30、eth1.40同时接入到brvlan30,且在brvlan30上同时配置30段和40段的ip,可以同时和另一台虚拟机的2个network namespace ping通的。
现象5:将eth1.30从bridge取下,然后独立配置ip;可以抓到对端发来的arp报文,但是无响应?看来vlan设备是不能配置ip的?

抓包现象:
宿主机抓包
[root@yefeng ~]# tcpdump -ennvv  host 30.0.0.111 -i eth1
tcpdump: listening on eth1, link-type EN10MB (Ethernet), capture size 262144 bytes
19:00:05.378690 e6:7b:57:c9:aa:23 > de:59:86:b6:65:c8, ethertype 802.1Q (0x8100), length 102: vlan 30, p 0, ethertype IPv4, (tos 0x0, ttl 64, id 23177, offset 0, flags [DF], proto ICMP (1), length 84)
    30.0.0.112 > 30.0.0.111: ICMP echo request, id 4429, seq 1, length 64
19:00:05.378711 e6:7b:57:c9:aa:23 > de:59:86:b6:65:c8, ethertype 802.1Q (0x8100), length 102: vlan 40, p 0, ethertype IPv4, (tos 0x0, ttl 64, id 23177, offset 0, flags [DF], proto ICMP (1), length 84)
    30.0.0.112 > 30.0.0.111: ICMP echo request, id 4429, seq 1, length 64
19:00:05.378821 de:59:86:b6:65:c8 > e6:7b:57:c9:aa:23, ethertype 802.1Q (0x8100), length 102: vlan 30, p 0, ethertype IPv4, (tos 0x0, ttl 64, id 53573, offset 0, flags [none], proto ICMP (1), length 84)
    30.0.0.111 > 30.0.0.112: ICMP echo reply, id 4429, seq 1, length 64
19:00:10.387111 e6:7b:57:c9:aa:23 > de:59:86:b6:65:c8, ethertype 802.1Q (0x8100), length 64: vlan 30, p 0, ethertype ARP, Ethernet (len 6), IPv4 (len 4), Request who-has 30.0.0.111 tell 30.0.0.112, length 46
19:00:10.387152 de:59:86:b6:65:c8 > e6:7b:57:c9:aa:23, ethertype 802.1Q (0x8100), length 46: vlan 30, p 0, ethertype ARP, Ethernet (len 6), IPv4 (len 4), Reply 30.0.0.111 is-at de:59:86:b6:65:c8, length 28

network namespace抓包
[root@yefeng ~]# ip netns exec ns30 tcpdump -ennvv  host 30.0.0.111 -i veth1
tcpdump: listening on veth1, link-type EN10MB (Ethernet), capture size 262144 bytes
19:00:56.709770 e6:7b:57:c9:aa:23 > de:59:86:b6:65:c8, ethertype IPv4 (0x0800), length 98: (tos 0x0, ttl 64, id 42055, offset 0, flags [DF], proto ICMP (1), length 84)
    30.0.0.112 > 30.0.0.111: ICMP echo request, id 4440, seq 1, length 64
19:00:56.709796 de:59:86:b6:65:c8 > e6:7b:57:c9:aa:23, ethertype IPv4 (0x0800), length 98: (tos 0x0, ttl 64, id 2866, offset 0, flags [none], proto ICMP (1), length 84)
    30.0.0.111 > 30.0.0.112: ICMP echo reply, id 4440, seq 1, length 64
19:01:01.714393 e6:7b:57:c9:aa:23 > de:59:86:b6:65:c8, ethertype ARP (0x0806), length 60: Ethernet (len 6), IPv4 (len 4), Request who-has 30.0.0.111 tell 30.0.0.112, length 46
19:01:01.714403 de:59:86:b6:65:c8 > e6:7b:57:c9:aa:23, ethertype ARP (0x0806), length 42: Ethernet (len 6), IPv4 (len 4), Reply 30.0.0.111 is-at de:59:86:b6:65:c8, length 28

linux虚拟网络-vlan实验:2台虚拟机做vlan30和vlan40互通(虚拟机模拟物理机,network namespace充当虚拟机)