[EP.33] Configuring VLANs on MikroTik RouterBoard (RB) Product without using Switch Chip

Krittin Srithong
techblogclub
Published in
7 min readMar 10, 2022

--

Scenario

ใน Episode นี้ เราจะมาลงมือการ Config VLANs บน MikroTik RouterBoard Product โดยไม่ใช้ Switch Chip (บน RouterOS) กัน ผู้ศึกษาสามารถนำขั้นตอนตามด้านล่างไปลงมือทำบน hAP ac² ได้เลย

หากจะศึกษาทำ LAB เกี่ยวกับ MikroTik แนะนำ Product ตัว hAP ac² จำนวน 2 ตัว เพื่อจำลอง MainRouter 1 ตัว และเป็น Switch 1 ตัว สาเหตุที่เลือก hAP ac² เพราะ Performance มีความคุ้มค่าต่อราคา และมี Switch Chip ที่เป็น Atheros8327 มาให้อีก

เนื่องจาก Lab นี้ผมใช้ GNS3 CHR ในการจำลองทำ Lab ไม่ได้ใช้ hAP ac² ดังนั้น CHR จึงไม่สามารถทำงานในระดับของ Bridge Hardware Offloading ได้อยู่แล้ว Mikrotik จะปรับการทำงานทั้งหมดกลับมาที่ CPU ทั้งหมด

# ฝั่ง MainRouter (MikroTik) Version 6.49.2

  1. Connect To MainRouter
  2. Go to System → Identity → Change name to “MainRouter” → Press OK
  3. Enable DHCP client บน Eth1 ของ MainRouter และตรวจสอบการเชื่อมต่อกับอินเทอร์เน็ต
  • Go to IP → DHCP Client
  • กด +
  • Interface: ether1
  • Use Peer DNS: ติ๊กเครื่องหมายถูก
  • Use Peer NTP: ติ๊กเครื่องหมายถูก
  • Add Default Route: yes
  • Comment: Connected To Internet
  • กด OK
  • ทดสอบ Ping ว่า MainRouter สามารถออกอินเตอร์ได้หรือไม่?
  • Go to Tools → Ping
  • Ping To: www.google.com หรือ 8.8.8.8
  • กด Start

4. สร้าง VLAN10 ให้ PC1 และ VLAN20 ให้ PC2 บน Eth5 (Trunk Port) บน MainRouter

## VLAN10 ให้ PC1 ##

  • Go to Interfaces → VLAN
  • กด +
  • Name: vlan10
  • VLAN ID: 10 (ตาม Scenario ใช้ VLAN ID 10)
  • Interface: ether5 (จาก Scenario, vlan10 เกาะ Eth5 เพื่อบ่งบอกว่าเป็น Trunk Port)
  • กด Apply และ OK

## VLAN20 ให้ PC2 ##

  • Go to Interfaces → VLAN
  • กด +
  • Name: vlan20
  • VLAN ID: 20(ตาม Scenario ใช้ VLAN ID 20)
  • Interface: ether5 (จาก Scenario, vlan20 เกาะ Eth5 เพื่อบ่งบอกว่าเป็น Trunk Port)
  • กด Apply และ OK

5. กำหนดค่า IP Address 10.10.10.1/24 บน VLAN10 และ 10.20.20.1/24 บน VLAN20

## กำหนดค่า IP Address 10.10.10.1/24 บน VLAN10 ##

  • Go to IP → Addresses
  • กด +
  • Address: 10.10.10.1/24
  • Network: 10.10.10.0
  • Interface: เลือก vlan10

## กำหนดค่า IP Address 10.20.20.1/24 บน VLAN20 ##

  • Go to IP → Addresses
  • กด +
  • Address: 10.20.20.1/24
  • Network: 10.20.20.0
  • Interface: เลือก vlan20

6. สร้าง DHCP Server บน VLAN10 และ บน VLAN20

## สร้าง DHCP Server บน VLAN10 ##

  • Go to IP → DHCP Server
  • กด “DHCP Setup”
  • DHCP Server Interface: vlan10
  • กด Next
  • DHCP Address Space: 10.10.10.0/24
  • กด Next
  • Gateway for DHCP Network: 10.10.10.1
  • กด Next
  • Addresses to Give Out: 10.10.10.2-10.10.10.254 (วง vlan10 แจก IP ตั้งแต่หมายเลข 2-254 ให้กับ Client)
  • กด Next
  • กำหนด DNS Servers เป็น: 8.8.8.8 และ 8.8.4.4
  • กด Next
  • ตั้ง Lease Time: 1d 00:00:00 (ปรับตามความต้องการ)
  • กด Next
  • กด OK

## สร้าง DHCP Server บน VLAN20 ##

  • Go to IP → DHCP Server
  • กด “DHCP Setup”
  • DHCP Server Interface: vlan20
  • กด Next
  • DHCP Address Space: 10.20.20.0/24
  • กด Next
  • Gateway for DHCP Network: 10.20.20.1
  • กด Next
  • Addresses to Give Out: 10.20.20.2-10.20.20.254 (วง vlan20 แจก IP ตั้งแต่หมายเลข 2-254 ให้กับ Client)
  • กด Next
  • กำหนด DNS Servers เป็น: 8.8.8.8 และ 8.8.4.4
  • กด Next
  • ตั้ง Lease Time: 1d 00:00:00 (ปรับตามความต้องการ)
  • กด Next
  • กด OK

7. ทำ Masquerade (NAT)

## ทำ Masquerade ให้กับ วง vlan10 ##

  • Go to IP → Firewall → NAT
  • กด +
  • chain: srcnat
  • Src. Address: 10.10.10.0/24 (วง vlan10)
  • action: masquerade

## ทำ Masquerade ให้กับ วง vlan20 ##

  • Go to IP → Firewall → NAT
  • กด +
  • chain: srcnat
  • Src. Address: 10.20.20.0/24 (วง vlan20)
  • action: masquerade

# ฝั่ง Switch (MikroTik) Version 6.49.2

  1. Connect To Switch
  2. Go to System → Identity → Change name to “Switch” → Press OK
  3. สร้าง Bridge ชื่อ “Bridge-VLAN-TRUNKs” และ Assign Eth1, Eth2, Eth3 เข้าไปใน Bridge “Bridge-VLAN-TRUNKs” (Ensure HW offload is un-checked)

## สร้าง Bridge ชื่อ “Bridge-VLAN-TRUNKs” ##

  • Go to Bridge → กด +
  • Name: Bridge-VLAN-TRUNKs
  • กด Apply และ OK

## Assign Eth1, Eth2, Eth3 เข้าไปใน Bridge “Bridge-VLAN-TRUNKs” (Ensure HW offload is un-checked) ##

  • Assign Eth1 To Bridge “Bridge-VLAN-TRUNKs” (Ensure HW offload is un-checked)
  • Go to Bridge → Ports tab,
  • กด +
  • Interface: ether1
  • Bridge: เลือก Bridge-VLAN-TRUNKs
  • เอาเครื่องหมายติ๊กถูกหน้า Hardware Offload ออก
  • กด Apply และ OK
  • Assign Eth2 To Bridge “Bridge-VLAN-TRUNKs” (Ensure HW offload is un-checked)
  • Go to Bridge → Ports tab,
  • กด +
  • Interface: ether2
  • Bridge: เลือก Bridge-VLAN-TRUNKs
  • เอาเครื่องหมายติ๊กถูกหน้า Hardware Offload ออก
  • กด Apply และ OK
  • Assign Eth3 To Bridge “Bridge-VLAN-TRUNKs” (Ensure HW offload is un-checked)
  • Go to Bridge → Ports tab,
  • กด +
  • Interface: ether3
  • Bridge: เลือก Bridge-VLAN-TRUNKs
  • เอาเครื่องหมายติ๊กถูกหน้า Hardware Offload ออก
  • กด Apply และ OK

4. จากเมนู Bridge, ไปที่ Eth2 กำหนด PVID = 10 และ ไปที่ Eth3 กำหนด PVID = 20

## จากเมนู Bridge, ไปที่ Eth2 กำหนด PVID = 10 ##

  • Go to Bridge → Ports tab
  • กดคลิก ether2 → VLAN tab
  • กำหนด PVID = 10
  • กด Apply และ OK

## จากเมนู Bridge, ไปที่ Eth3 กำหนด PVID = 20 ##

  • Go to Bridge → Ports tab
  • กดคลิก ether3 → VLAN tab
  • กำหนด PVID = 20
  • กด Apply และ OK

5. จากเมนู Bridge, ให้สร้าง new Bridge VLAN ด้วย VLAN id = 10, Tagged = Eth1, Untagged=Eth2 และ VLAN id = 20, Tagged = Eth1, Untagged = Eth3

## จากเมนู Bridge, ให้สร้าง new Bridge VLAN ด้วย VLAN id = 10, Tagged = Eth1, Untagged= Eth2 ##

  • Go to Bridge → VLANs tab
  • กด +
  • Bridge: เลือก Bridge-VLAN-TRUNKs
  • VLAN IDs: 10
  • Tagged: เลือก ether1
  • Untagged: เลือก ether2
  • กด Apply และ OK

## จากเมนู Bridge, ให้สร้าง new Bridge VLAN ด้วย VLAN id = 20, Tagged = Eth1, Untagged= Eth3 ##

  • Go to Bridge → VLANs tab
  • กด +
  • Bridge: เลือก Bridge-VLAN-TRUNKs
  • VLAN IDs: 20
  • Tagged: เลือก ether1
  • Untagged: เลือก ether3
  • กด Apply และ OK

6. เปิดใช้งาน VLAN Filtering บน Bridge “Bridge-VLAN-TRUNKs”

  • Go to Bridge → คลิก Bridge-VLAN-TRUNKs → VLAN tab → ติ๊ก VLAN Filtering
  • กด Apply และ OK

ทดสอบ

  1. PC1 เสียบ LAN Cable ไปที่ Ether2 ของ Switch (MikroTik) แล้วตรวจสอบได้รับวง VLAN10 (10.10.10.254) หรือไม่?

2. PC2 เสียบ LAN Cable ไปที่ Ether3 ของ Switch (MikroTik) แล้วตรวจสอบได้รับวง VLAN20 (10.20.20.254) หรือไม่?

## เสริม หากต้องการไม่ให้ VLAN10 และ VLAN20 ติดต่อสื่อสารกันได้ มีวิธีดังนี้ ##

  1. Connect To MainRouter (MikroTik)
  2. Go to IP → Firewall → Firewall Rules
  • กด +
  • Chain: forward
  • In. Interface: เลือก all vlan
  • Out. Interface: เลือก all vlan
  • action: drop
  • กด Apply และ OK

3. ทดสอบ “PC1” ping to “PC2” และ “PC2” ping to “PC1”

  • “PC1” ping to “PC2”
  • “PC2” ping to “PC1”

--

--

Krittin Srithong
techblogclub

Hi, I’m Krittin. I am studying in bachelor of Computer Enginnering. I have MikroTik Certificates as following MTCNA, MTCSE, MTCUME. (medium.com/techblogclub)