(linux) 網卡設定vlan(802.1q)

  1. 安裝VLAN(802.1Q)

    apt-get install vlan
    
  2. Load the 8021q kernel module

    sudo modprobe 8021q
    
  3. Ensure that this module gets loaded after a reboot by adding to /etc/modules:

    sudo  sh -c 'grep -q 8021q /etc/modules || echo 8021q >> /etc/modules'
    
  4. 替網卡加入VLAN

    sudo vconfig add eth0 100
    sudo vconfig add <Ether Card> <VID>
    sudo vconfig delete <Ether Card> <VID>
    
  5. 設定每個網卡對應VLAN的IP, netmask

    sudo ifconfig eth0.100 192.168.100.1 netmask 255.255.255.0
    sudo ifconfig eth0.<VID> <IP> netmask 255.255.255.0
    
  1. 測試VLAN是否作用,Ping 192.168.100.1/24,使用wireshark錄eth0封包

  2. 永久設定每個網卡對應VLAN的IP, netmask

    sudo vim /etc/network/interfaces
    
    auto eth0.100
    iface eth0.100 inet static
    address 192.168.100.1
    netmask 255.255.255.0