前言 : VLAN 就是能夠在乙太網路交換器、第三層交換器(Layer 3 Switch)、路由器或其他支援VLAN 的設備中,區隔區域網路的一種設定. 在IT 業界裡,經常使用專有名詞802.1Q 和VLAN 協定,來代表VLAN 的功能。因此,當有人談到802.1Q 時指的是VLAN ,提到VLAN 就代表802.1Q 。基本上, 802.1Q 最大的作用是,在乙太網路框架(Frame)的表頭上加上一個標記(Tag),藉此分辨來自不同VLAN 的封包. 底下將透過 Linux 的命令 vconfig 與 搭配 vSwitch 完成 vlan 設置. 設置步驟 : 1. 在開始之前, 可能要先確認 802.1Q 模組是否載入, 如果還沒則將之載入.
#modprobe 8021q
#lsmod | grep -i 8021q <確認 8021Q 模組以載入>
8021q 25545 1 cxgb3
2. 接著使用 vconfig 命令設定 vlan, 假設是作用於 eth1 介面上 :
#vconfig add eth1 100
Added VLAN with VID == 100 to IF -:eth1:-
#ifconfig -a | grep eth1.100
eth1.100 Link encap:Ethernet HWaddr 00:0C:29:2A:4F:95 <成功添加 eth1.100 的 vlan>
3. 請以同樣步驟設定好 Server, 應為 Client 與 Server 要能相同 vlan id 要一樣. 但是這要還不夠, 因為我們有使用 VMWare 的 vSwitch, 所以 vSwitch 上面也需要設定, 才能將帶有 vlan tag 的 packets 傳送出去. 請按下面步驟進行, 首先請登入 VMware vSphere Client : Step1. 選擇 Networking 設定
Step2 : 選擇自己的 vSwitch 並編輯 properties
Step3 : 進入編輯
Step4 : 編輯 VLAN ID=4095
Step 5 : 返回前一設定檢視設定生效
4. Server/Client 與 vSwitch vlan 都設定完成後, 接著是設定 Server與 Client vlan 的 IP, 最後請從 Server ping Client 確定設定成功 : 在 Client 端 :
#ifconfig eth1.100 10.1.1.2 netmask 255.255.0.0
#ifconfig -a
...(略)...
eth1.100 Link encap:Ethernet HWaddr 00:0C:29:2A:4F:95
inet addr:10.1.1.2 Bcast:10.1.255.255 Mask:255.255.0.0
在 Server 端 :
#vconfig add eth1 100 <假設剛剛還沒設定 Server vlan...>Added VLAN with VID == 100 to IF -:eth1:-#ifconfig eth1.100 10.1.1.1 netmask 255.255.0.0 <設定 eth1.100 IP...>#ifconfig -a...(略)...
eth1.100 Link encap:Ethernet HWaddr 00:0C:29:FF:FD:B1inet addr:10.1.1.1 Bcast:10.1.255.255 Mask:255.255.0.0...(略)...
#ping 10.1.1.2 PING 10.1.1.2 (10.1.1.2) 56(84) bytes of data.
64 bytes from 10.1.1.2: icmp_seq=1 ttl=64 time=0.970 ms
5. 最後如果設定都成功, 如果是 CentOS 可以考慮如下寫入, 這樣重開機後也能保留設定 : 在 Server 端 :
#vi /etc/sysconfig/network-scripts/ifcfg-eth1.100
# Advanced Micro Devices [AMD] 79c970 [PCnet32 LANCE]
DEVICE=eth1.100
BOOTPROTO=static
ONBOOT=yes
#DHCP_HOSTNAME=localhost.localdomain
IPADDR=10.1.1.1
NETMASK=255.255.0.0
VLAN=yes
補充說明 : * Howto: Configure Linux Virtual Local Area Network (VLAN)
VLAN is an acronym for Virtual Local Area Network. Several VLANs can co-exist on a single physical switch, which are configured via software (Linux commands and configuration files) and not through hardware interface (you still need to configure switch)...
* Linux (Ubuntu)- 網卡設定VLAN(802.1Q) * Linux 设置 多ip,多vlan
沒有留言:
張貼留言