[EP.32] Configuring VLANs on MikroTik RouterBoard (RB) Product with DHCP

Krittin Srithong
techblogclub
Published in
7 min readMar 7, 2022

--

Scenario

ใน Episode นี้ เราจะทำความเข้าใจและการ Config VLANs บน MikroTik RouterBoard Product ด้วย DHCP (บน RouterOS) หากจะศึกษาทำ LAB เกี่ยวกับ MikroTik แนะนำ Product ตัว hAP ac² จำนวน 2 ตัว เพื่อจำลอง MainRouter 1 ตัว และเป็น Switch 1 ตัว สาเหตุที่เลือก hAP ac² เพราะ Performance มีความคุ้มค่าต่อราคา และมี Switch Chip ที่เป็น Atheros8327 มาให้อีก ส่วนในการทำ LAB VLAN แบบใช้ Switch Chip เราจะมาพูดใน Episode ข้างหน้าถัดไป (และในอนาคตอาจมีการสอน Config VLAN โดยใช้ SwOS ด้วยเช่นกัน)

เนื่องจาก 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. กำหนดค่า Switch ให้มี Trunk Port บน Eth1 (VLAN10 & VLAN20)

# กำหนดค่า Trunk Port (VLAN10) บน Eth1 #

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

# กำหนดค่า Trunk Port (VLAN20) บน Eth1 #

  • Go to Interfaces → VLAN
  • กด +
  • Name: vlan20
  • VLAN ID: 20 (ตาม Scenario ใช้ VLAN 20, การกำหนด VLAN ID ต้องตรงกับ MainRouter)
  • Interface: ether1 (จาก Scenario, vlan20 เกาะ Eth1 เพื่อบ่งบอกว่าเป็น Trunk Port)
  • กด Apply OK

4. กำหนด VLAN10 ให้กับ Eth2 (เป็น Access Port) และ VLAN20 ให้กับ Eth3 (เป็น Access Port) บน Switch

## กำหนด VLAN10 ให้กับ Eth2 (เป็น Access Port) ##

  • สร้าง Bridge สำหรับ Access VLAN10
  • Go to Bridge → Bridge tab
  • กด +
  • Name: bridge-VLAN10-Access (ตั้งชื่อ Bridge ให้สื่อความหมาย)
  • กด Apply และ OK
  • Assign Eth2 เข้าไปใน Bridge “bridge-VLAN10-Access”
  • Go to Bridge → Ports tab
  • Interface: เลือก ether2
  • Bridge: เลือก bridge-VLAN10-Access
  • กด Apply และ OK
  • Assign vlan10 เข้าไปใน Bridge “bridge-VLAN10-Access”
  • Go to Bridge → Ports tab
  • Interface: เลือก vlan10
  • Bridge: เลือก bridge-VLAN10-Access
  • กด Apply และ OK

## กำหนด VLAN20 ให้กับ Eth3 (เป็น Access Port) ##

  • สร้าง Bridge สำหรับ Access VLAN20
  • Go to Bridge → Bridge tab
  • กด +
  • Name: bridge-VLAN20-Access (ตั้งชื่อ Bridge ให้สื่อความหมาย)
  • กด Apply และ OK
  • Assign Eth3 เข้าไปใน Bridge “bridge-VLAN20-Access”
  • Go to Bridge → Ports tab
  • Interface: เลือก ether3
  • Bridge: เลือก bridge-VLAN20-Access
  • กด Apply และ OK
  • Assign vlan20 เข้าไปใน Bridge “bridge-VLAN20-Access”
  • Go to Bridge → Ports tab
  • Interface: เลือก vlan20
  • Bridge: เลือก bridge-VLAN20-Access
  • กด Apply และ OK

หากต้องการเพิ่ม ether4 ให้ Access VLAN10 ออกมา ก็ทำการ Assign ether4 เข้าไปใน Bridge “bridge-VLAN10-Access” ได้เลย

หากต้องการเพิ่ม ether5 ให้ Access VLAN20 ออกมา ก็ทำการ Assign ether5 เข้าไปใน Bridge “bridge-VLAN20-Access” ได้เลย

ทดสอบ

  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)