Nov 11, 2010

讓你的封包,送出時自動加上 VLAN ID

在 Linux 下,使用 VLAN 的方法

1. insert 802.1q kernel module
sudo modprobe 8021q 


2. create a vlan id on NIC by vconfig

sudo vconfig add eth0 111
Added VLAN with VID == 111 to IF -:eth0:-
3. start up eth0.111
sudo ifconfig eth0.111 192.168.1.2 up

4. 測試前的準備:
sudo ifconfig eth0.111 192.168.1.2

eth0.111  Link encap:Ethernet  HWaddr 00:21:70:ff:d7:88  
          inet addr:192.168.1.2  Bcast:192.168.1.255  Mask:255.255.255.0
          inet6 addr: fe80::221:70ff:feff:d788/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:3 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:0 (0.0 B)  TX bytes:238 (238.0 B)
5. 利用 wireshark 抓出來的封包


此例中,在eth0上加上 vlanid 111,成功之後,會多出一個 eth0.111 的network device,只要是從這個 device 出去的封包,會自動加上 802.1Q 的 header

No comments: