Lab介绍:
宿主机:rhel6.5 eth0一块网卡
客户机:guest1 192.168.18.10/25 gw:192.168.18.1 vlan10
guest2 192.168.18.199/25 gw:192.168.18.192 vlan20
Lab思路:
实验需要两个vlan[vlan10,vlan20],所以需要基于eth0需要虚拟两个逻辑网卡,逻辑网卡命名方式是:物理网卡.vlan_ID,这样设置的目的是自动将网卡加入不同vlan.
eth0.10 默认该网卡属于 vlan10
eth0.20 默认该网卡属于 vlan20
编辑逻辑网卡,开启vlan功能。
创建两个桥br10 br20.将逻辑网卡和桥接网卡建立链接。
eth0.10 <======> br10
eth0.20 <======> br20
Lab步骤:
1.进入网卡配置文件的保存目录
[root@baism network-scripts]# cd /etc/sysconfig/network-scripts/
2.新建逻辑网卡及桥接网卡文件
[root@baism network-scripts]# ls
ifcfg-br10 ifcfg-eth0.10 ifcfg-wlan0 ifdown-eth ifdown-isdn ifdown-routes ifup ifup-eth ifup-isdn ifup-post ifup-sit init.ipv6-global network-functions-ipv6
ifcfg-br20 ifcfg-eth0.20 ifdown ifdown-ippp ifdown-post ifdown-sit ifup-aliases ifup-ippp ifup-plip ifup-ppp ifup-tunnel net.hotplug
ifcfg-eth0 ifcfg-lo ifdown-bnep ifdown-ipv6 ifdown-ppp ifdown-tunnel ifup-bnep ifup-ipv6 ifup-plusb ifup-routes ifup-wireless network-functions
3.物理网卡配置信息
[root@baism network-scripts]# more ifcfg-eth0
DEVICE=eth0
HWADDR=F0:DE:F1:76:80:F7
TYPE=Ethernet
UUID=761f4340-1168-47d7-9cf9-357f51a2ac5e
ONBOOT=yes
NM_CONTROLLED=no
BOOTPROTO=static
4. eth0.10 逻辑网卡配置信息
[root@baism network-scripts]# more ifcfg-eth0.10
DEVICE=eth0.10
HWADDR=F0:DE:F1:76:80:F7
TYPE=Ethernet
UUID=761f4340-1168-47d7-9cf9-357f51a2ac5e
ONBOOT=yes
NM_CONTROLLED=no
BOOTPROTO=static
BRIDGE=br10
VLAN=yes
5. eth0.20 逻辑网卡配置信息
[root@baism network-scripts]# more ifcfg-eth0.20
DEVICE=eth0.20
HWADDR=F0:DE:F1:76:80:F7
TYPE=Ethernet
UUID=761f4340-1168-47d7-9cf9-357f51a2ac5e
ONBOOT=yes
NM_CONTROLLED=no
BOOTPROTO=static
BRIDGE=br20
VLAN=yes
6. 桥接网卡br10配置信息
[root@baism network-scripts]# more ifcfg-br10
DEVICE=br10
TYPE=Bridge
ONBOOT=yes
NM_CONTROLLED=no
BOOTPROTO=static
IPADDR=192.168.18.1
NETMASK=255.255.255.128
GATEWAY=192.168.18.1
7.桥接网卡br20配置信息
[root@baism network-scripts]# more ifcfg-br20
DEVICE=br20
TYPE=Bridge
ONBOOT=yes
NM_CONTROLLED=no
BOOTPROTO=static
IPADDR=192.168.18.192
NETMASK=255.255.255.128
GATEWAY=192.168.18.192
8.重启网络服务后查看vlan信息
[root@baism network-scripts]# cat /proc/net/vlan/
config eth0.10 eth0.20
[root@baism network-scripts]# cat /proc/net/vlan/config
VLAN Dev name | VLAN ID
Name-Type: VLAN_NAME_TYPE_RAW_PLUS_VID_NO_PAD
eth0.10 | 10 | eth0
eth0.20 | 20 | eth0
9.查看桥接是否建立
[root@baism network-scripts]# brctl show
bridge name bridge id STP enabled interfaces
br0 8000.f0def17680f7 no eth0
br10 8000.f0def17680f7 no eth0.10
br20 8000.f0def17680f7 no eth0.20
pan0 8000.000000000000 no
virbr0 8000.525400f9b02a yes virbr0-nic
10.启动客户机并设置IP
为 guest1 设置IP 192.168.18.10/25/192.168.18.1
为 guest2 设置IP 192.168.18.199/25/192.168.18.192
11.ping测试
guest1 ----> 192.168.18.10 OK
guest1 ----> 192.168.18.1 OK
guest1 ----> 192.168.18.192 OK
guest1 ----> 192.168.18.199 FAIL
guest2 ----> 192.168.18.199 OK
guest1 ----> 192.168.18.192 OK
guest1 ----> 192.168.18.1 OK
guest1 ----> 192.168.18.10 FAIL
从上述测试结果可以看出vlan内的机器可以互通,不同vlan不能通信
12.vlan间互通,开启宿主机路由,并清空防火墙,因为默认防火墙拒绝转发。
[root@baism network-scripts]#echo 1 > /proc/sys/net/ipv4/ip_forward
[root@baism network-scripts]#iptables -F
guest1 ----> 192.168.18.199 OK
guest1 ----> 192.168.18.10 OK
ping test OK