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]# lsifcfg-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-ipv6ifcfg-br20 ifcfg-eth0.20 ifdown ifdown-ippp ifdown-post ifdown-sit ifup-aliases ifup-ippp ifup-plip ifup-ppp ifup-tunnel net.hotplugifcfg-eth0 ifcfg-lo ifdown-bnep ifdown-ipv6 ifdown-ppp ifdown-tunnel ifup-bnep ifup-ipv6 ifup-plusb ifup-routes ifup-wireless network-functions3.物理网卡配置信息[root@baism network-scripts]# more ifcfg-eth0DEVICE=eth0HWADDR=F0:DE:F1:76:80:F7TYPE=EthernetUUID=761f4340-1168-47d7-9cf9-357f51a2ac5eONBOOT=yesNM_CONTROLLED=noBOOTPROTO=static4. eth0.10 逻辑网卡配置信息[root@baism network-scripts]# more ifcfg-eth0.10DEVICE=eth0.10HWADDR=F0:DE:F1:76:80:F7TYPE=EthernetUUID=761f4340-1168-47d7-9cf9-357f51a2ac5eONBOOT=yesNM_CONTROLLED=noBOOTPROTO=staticBRIDGE=br10VLAN=yes5. eth0.20 逻辑网卡配置信息
[root@baism network-scripts]# more ifcfg-eth0.20DEVICE=eth0.20HWADDR=F0:DE:F1:76:80:F7TYPE=EthernetUUID=761f4340-1168-47d7-9cf9-357f51a2ac5eONBOOT=yesNM_CONTROLLED=noBOOTPROTO=staticBRIDGE=br20VLAN=yes6. 桥接网卡br10配置信息[root@baism network-scripts]# more ifcfg-br10 DEVICE=br10TYPE=BridgeONBOOT=yesNM_CONTROLLED=noBOOTPROTO=staticIPADDR=192.168.18.1NETMASK=255.255.255.128GATEWAY=192.168.18.17.桥接网卡br20配置信息[root@baism network-scripts]# more ifcfg-br20 DEVICE=br20TYPE=BridgeONBOOT=yesNM_CONTROLLED=noBOOTPROTO=staticIPADDR=192.168.18.192NETMASK=255.255.255.128GATEWAY=192.168.18.1928.重启网络服务后查看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 IDName-Type: VLAN_NAME_TYPE_RAW_PLUS_VID_NO_PADeth0.10 | 10 | eth0eth0.20 | 20 | eth09.查看桥接是否建立[root@baism network-scripts]# brctl showbridge name bridge id STP enabled interfacesbr0 8000.f0def17680f7 no eth0br10 8000.f0def17680f7 no eth0.10br20 8000.f0def17680f7 no eth0.20pan0 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