Files
my-vault/00_Inbox/Clippings/2024/12/How to secure IOT devices with VLANs and firewall rules on an Ubiquiti EdgeRouter-X and a MikroTik switch running SwOS Lite · GeekBitZone.com - Passionate About Tech.md
T

544 lines
29 KiB
Markdown
Raw Normal View History

2026-01-05 13:03:55 +08:00
---
page-title: "How to secure IOT devices with VLANs and firewall rules on an Ubiquiti EdgeRouter-X and a MikroTik switch running SwOS Lite · GeekBitZone.com - Passionate About Tech"
url: https://www.geekbitzone.com/posts/2021/networking/vlans/vlan-edgerouter-mikrotik/edgerouter-mikrotik-swos-vlan/
date: "2024-12-16 17:41:48"
---
**Deprecation Notice:** *This article was written more than a year ago which means that its information might no longer be up-to-date. We cannot therefore guarantee the accuracy of it's contents.*
---
## Table of Contents
- [Firmware versions used](https://www.geekbitzone.com/posts/2021/networking/vlans/vlan-edgerouter-mikrotik/edgerouter-mikrotik-swos-vlan/#firmware-versions-used)
- [Network overview](https://www.geekbitzone.com/posts/2021/networking/vlans/vlan-edgerouter-mikrotik/edgerouter-mikrotik-swos-vlan/#network-overview)
- [Setting up a VLAN on the EdgeRouter](https://www.geekbitzone.com/posts/2021/networking/vlans/vlan-edgerouter-mikrotik/edgerouter-mikrotik-swos-vlan/#setting-up-a-vlan-on-the-edgerouter)
- [Enabling VLAN on the switch0 interface](https://www.geekbitzone.com/posts/2021/networking/vlans/vlan-edgerouter-mikrotik/edgerouter-mikrotik-swos-vlan/#enabling-vlan-on-the-switch0-interface)
- [Creating a DHCP server for the VLAN](https://www.geekbitzone.com/posts/2021/networking/vlans/vlan-edgerouter-mikrotik/edgerouter-mikrotik-swos-vlan/#creating-a-dhcp-server-for-the-vlan)
- [Setting up Firewall NAT Groups on the EdgeRouter](https://www.geekbitzone.com/posts/2021/networking/vlans/vlan-edgerouter-mikrotik/edgerouter-mikrotik-swos-vlan/#setting-up-firewall-nat-groups-on-the-edgerouter)
- [Setting up Firewall Policies on the EdgeRouter](https://www.geekbitzone.com/posts/2021/networking/vlans/vlan-edgerouter-mikrotik/edgerouter-mikrotik-swos-vlan/#setting-up-firewall-policies-on-the-edgerouter)
- [Setting up a VLAN on the CSS610-8G-2S+IN](https://www.geekbitzone.com/posts/2021/networking/vlans/vlan-edgerouter-mikrotik/edgerouter-mikrotik-swos-vlan/#setting-up-a-vlan-on-the-css610-8g-2sin)
- [Verifying the setup](https://www.geekbitzone.com/posts/2021/networking/vlans/vlan-edgerouter-mikrotik/edgerouter-mikrotik-swos-vlan/#verifying-the-setup)
- [Test 1: Can the IOT device reach the Internet?](https://www.geekbitzone.com/posts/2021/networking/vlans/vlan-edgerouter-mikrotik/edgerouter-mikrotik-swos-vlan/#test-1-can-the-iot-device-reach-the-internet)
- [Test 2: Can the IOT device reach other devices outside VLAN 10?](https://www.geekbitzone.com/posts/2021/networking/vlans/vlan-edgerouter-mikrotik/edgerouter-mikrotik-swos-vlan/#test-2-can-the-iot-device-reach-other-devices-outside-vlan-10)
- [Test 3: Can the IOT device reach the router (gateway)?](https://www.geekbitzone.com/posts/2021/networking/vlans/vlan-edgerouter-mikrotik/edgerouter-mikrotik-swos-vlan/#test-3-can-the-iot-device-reach-the-router-gateway)
- [Test 4: Can devices on the main network (outside VLAN 10) reach the IOT device?](https://www.geekbitzone.com/posts/2021/networking/vlans/vlan-edgerouter-mikrotik/edgerouter-mikrotik-swos-vlan/#test-4-can-devices-on-the-main-network-outside-vlan-10-reach-the-iot-device)
- [Summary](https://www.geekbitzone.com/posts/2021/networking/vlans/vlan-edgerouter-mikrotik/edgerouter-mikrotik-swos-vlan/#summary)
- [References](https://www.geekbitzone.com/posts/2021/networking/vlans/vlan-edgerouter-mikrotik/edgerouter-mikrotik-swos-vlan/#references)
---
## How to secure IOT devices with VLANs and firewall rules on an Ubiquiti EdgeRouter-X and a MikroTik switch running SwOS Lite
The Ubiquiti Networks™ EdgeMAX® [EdgeRouter™ X](https://www.ui.com/edgemax/edgerouter-x/) and the MikroTik [CSS610-8G-2S+IN](https://mikrotik.com/product/css610_8g_2s_in) layer 2 switch are very affordable networking devices sold by respective vendors in this price bracket. We will in this tutorial explore how to set up a Virtual Local Area Network (**VLAN**) with firewall rules between an EdgeRouter™ X and a CSS610-8G-2S+IN switch running [SwOS Lite](https://wiki.mikrotik.com/wiki/SwOS/CSS610).
---
## Firmware versions used
The following firmware versions were used in this article:
- [EdgeOS v2.0.9-hotfix.1](https://www.ui.com/download/edgemax/default/default/edgerouter-er-xer-x-sfpep-r6er-10x-firmware-v209-hotfix1)
- [SwOS Lite 2.13](https://www.mikrotik.com/download)
---
## Network overview
In this simple network diagram we have assumed that the Internet (WAN) is connected to port **eth0** on the EdgeRouter. On the LAN side, **eth1** is connected to **port 1** on the MikroTik switch. Finally, on **port 2**, we have connected an insecure Internet of Things (IOT) device which we will isolate into its own VLAN.
![EdgeRouter Mikrotik VLAN - Image 1](https://www.geekbitzone.com/posts/2021/networking/vlans/vlan-edgerouter-mikrotik/img/edgerouter-mikrotik-swos-vlan-1.png)
---
## Setting up a VLAN on the EdgeRouter
We will begin by logging in to the EdgeRouter. Open your routers admin page, which in our case is `192.168.1.1`, and type in your `username` and `password`.
![EdgeRouter Mikrotik VLAN - Image 2](https://www.geekbitzone.com/posts/2021/networking/vlans/vlan-edgerouter-mikrotik/img/edgerouter-mikrotik-swos-vlan-2.png)
On the main **Dashboard**, select **Add Interface > Add VLAN**.
![EdgeRouter Mikrotik VLAN - Image 3](https://www.geekbitzone.com/posts/2021/networking/vlans/vlan-edgerouter-mikrotik/img/edgerouter-mikrotik-swos-vlan-3.png)
Pick a **VLAN ID** number between 0-4094. We have chosen `10`.
![EdgeRouter Mikrotik VLAN - Image 4](https://www.geekbitzone.com/posts/2021/networking/vlans/vlan-edgerouter-mikrotik/img/edgerouter-mikrotik-swos-vlan-4.png)
Set **Interface** to `switch0`.
![EdgeRouter Mikrotik VLAN - Image 5](https://www.geekbitzone.com/posts/2021/networking/vlans/vlan-edgerouter-mikrotik/img/edgerouter-mikrotik-swos-vlan-5.png)
Type in a **Description** for this VLAN (optional). We will name it `IOT`.
![EdgeRouter Mikrotik VLAN - Image 6](https://www.geekbitzone.com/posts/2021/networking/vlans/vlan-edgerouter-mikrotik/img/edgerouter-mikrotik-swos-vlan-6.png)
Set **Address** to `Manually define IP address`. We have chosen: `10.0.10.1/24`, but feel free to use any IP within the reserved [RFC1918](https://tools.ietf.org/html/rfc1918) ranges.
Press **Save** to close the window.
![EdgeRouter Mikrotik VLAN - Image 7](https://www.geekbitzone.com/posts/2021/networking/vlans/vlan-edgerouter-mikrotik/img/edgerouter-mikrotik-swos-vlan-7.png)
We can now see on the main dashboard that a new interface, **switch0.10**, has been created. This is the interface for our IOT VLAN 10.
![EdgeRouter Mikrotik VLAN - Image 8](https://www.geekbitzone.com/posts/2021/networking/vlans/vlan-edgerouter-mikrotik/img/edgerouter-mikrotik-swos-vlan-8.png)
---
## Enabling VLAN on the switch0 interface
We will now make the **switch0** interface VLAN-aware by tagging VLAN ID **10** to port **eth1**.
Place your mouse cursor over the **switch0** row and select **Actions > Config**.
*Note: do not accidentally select the IOT switch0.10 interface!*
![EdgeRouter Mikrotik VLAN - Image 9](https://www.geekbitzone.com/posts/2021/networking/vlans/vlan-edgerouter-mikrotik/img/edgerouter-mikrotik-swos-vlan-9.png)
Navigate to the **Vlan** tab.
![EdgeRouter Mikrotik VLAN - Image 10](https://www.geekbitzone.com/posts/2021/networking/vlans/vlan-edgerouter-mikrotik/img/edgerouter-mikrotik-swos-vlan-10.png)
`Enable` the **VLAN Aware** checkbox.
![EdgeRouter Mikrotik VLAN - Image 11](https://www.geekbitzone.com/posts/2021/networking/vlans/vlan-edgerouter-mikrotik/img/edgerouter-mikrotik-swos-vlan-11.png)
Make sure that **Switch Ports** have been `enabled` on **eth1** and set **vid** to VLAN `10`.
![EdgeRouter Mikrotik VLAN - Image 12](https://www.geekbitzone.com/posts/2021/networking/vlans/vlan-edgerouter-mikrotik/img/edgerouter-mikrotik-swos-vlan-12.png)
Press **Save** to close the window.
*Note: The **vid** value is for tagged traffic leaving the port, while **pvid** is used for untagged traffic arriving at the port.*
---
## Creating a DHCP server for the VLAN
We will now create a DHCP Server so that any devices connected to this VLAN will automatically receive an IP address.
Navigate to the **Services > DHCP Server** tab and select **Add DHCP Server**.
![EdgeRouter Mikrotik VLAN - Image 13](https://www.geekbitzone.com/posts/2021/networking/vlans/vlan-edgerouter-mikrotik/img/edgerouter-mikrotik-swos-vlan-13.png)
Give the server a **DHCP Name**. We will call it `IOT`.
![EdgeRouter Mikrotik VLAN - Image 14](https://www.geekbitzone.com/posts/2021/networking/vlans/vlan-edgerouter-mikrotik/img/edgerouter-mikrotik-swos-vlan-14.png)
For the **Subnet**, type `10.0.10.0/24`.
![EdgeRouter Mikrotik VLAN - Image 15](https://www.geekbitzone.com/posts/2021/networking/vlans/vlan-edgerouter-mikrotik/img/edgerouter-mikrotik-swos-vlan-15.png)
Our DHCP **Range Start** is `10.0.10.100` and **Range Stop** will be `10.0.10.254`. Feel free to use any range, but bear in mind that if you want to assign static IP addresses to your devices, this entire IP range cannot be occupied by DHCP.
![EdgeRouter Mikrotik VLAN - Image 16](https://www.geekbitzone.com/posts/2021/networking/vlans/vlan-edgerouter-mikrotik/img/edgerouter-mikrotik-swos-vlan-16.png)
Set the **Router** address to `10.0.10.1`.
![EdgeRouter Mikrotik VLAN - Image 17](https://www.geekbitzone.com/posts/2021/networking/vlans/vlan-edgerouter-mikrotik/img/edgerouter-mikrotik-swos-vlan-17.png)
Finally, assign a **DNS 1** record to this DHCP server. We will simply use the *routers* address, `10.0.10.1`, since all traffic will flow through here anyway. (Optionally, assign a second DNS record, such as `1.1.1.1` or `8.8.8.8`, under **DNS 2** for added redundancy.)
![EdgeRouter Mikrotik VLAN - Image 18](https://www.geekbitzone.com/posts/2021/networking/vlans/vlan-edgerouter-mikrotik/img/edgerouter-mikrotik-swos-vlan-18.png)
Press **Save** to close the window.
If we look at the page we can now see that **IOT** has been added to the list of DHCP servers.
![EdgeRouter Mikrotik VLAN - Image 19](https://www.geekbitzone.com/posts/2021/networking/vlans/vlan-edgerouter-mikrotik/img/edgerouter-mikrotik-swos-vlan-19.png)
---
## Setting up Firewall NAT Groups on the EdgeRouter
We will now set up a few firewall rules to prevent IOT devices from communicating with other devices on the local area network and to only allow them Internet access.
*Note: This section has deliberately been made as simple as possible and does not cover every possible firewall rule since every users network setup is different.*
Navigate to the **Firewall/NAT > Firewall/NAT Groups** tab and select **Add Group**.
![EdgeRouter Mikrotik VLAN - Image 20](https://www.geekbitzone.com/posts/2021/networking/vlans/vlan-edgerouter-mikrotik/img/edgerouter-mikrotik-swos-vlan-20.png)
We will now define a **Network Group** of *Private Internets* based on the [RFC1918](https://tools.ietf.org/html/rfc1918) standard, which we will later use in our firewall rules.
Under **Name**, type `RFC1918`.
![EdgeRouter Mikrotik VLAN - Image 21](https://www.geekbitzone.com/posts/2021/networking/vlans/vlan-edgerouter-mikrotik/img/edgerouter-mikrotik-swos-vlan-21.png)
Give a **Description** (optional). We will type `RFC1918 ranges`.
![EdgeRouter Mikrotik VLAN - Image 22](https://www.geekbitzone.com/posts/2021/networking/vlans/vlan-edgerouter-mikrotik/img/edgerouter-mikrotik-swos-vlan-22.png)
Set **Group Type** to `Network Group` and press **Save** to close the window.
![EdgeRouter Mikrotik VLAN - Image 23](https://www.geekbitzone.com/posts/2021/networking/vlans/vlan-edgerouter-mikrotik/img/edgerouter-mikrotik-swos-vlan-23.png)
We will now edit our newly created network group. On the **RFC1918** line, select **Actions > Config**.
![EdgeRouter Mikrotik VLAN - Image 24](https://www.geekbitzone.com/posts/2021/networking/vlans/vlan-edgerouter-mikrotik/img/edgerouter-mikrotik-swos-vlan-24.png)
Under **Network**, type the following three RFC1918 ranges:
- 10.0.0.0/8
- 172.16.0.0/12
- 192.168.0.0/16
Press **Add New** to create another entry and **Save** to confirm the changes.
![EdgeRouter Mikrotik VLAN - Image 25](https://www.geekbitzone.com/posts/2021/networking/vlans/vlan-edgerouter-mikrotik/img/edgerouter-mikrotik-swos-vlan-25.png)
This window will not close until you press **X** in the upper right corner.
![EdgeRouter Mikrotik VLAN - Image 26](https://www.geekbitzone.com/posts/2021/networking/vlans/vlan-edgerouter-mikrotik/img/edgerouter-mikrotik-swos-vlan-26.png)
Confirm that the **Number of group members** column shows **3** members.
![EdgeRouter Mikrotik VLAN - Image 27](https://www.geekbitzone.com/posts/2021/networking/vlans/vlan-edgerouter-mikrotik/img/edgerouter-mikrotik-swos-vlan-27.png)
---
## Setting up Firewall Policies on the EdgeRouter
With the Network Group set up out of the way, we will now set up firewall policies. Our plan is to block access to the local area network as well as the router from the IOT network and only allow direct Internet access. Safe devices, *outside* the IOT network, should still be able to communicate with the IOT devices, but not the other way around.
The EdgeRouter defines traffic as such:
- **IN** - Traffic coming from the VLAN into the EdgeRouter.
- **OUT** - Traffic going out of the EdgeRouter and into the VLAN.
- **LOCAL** - Traffic on the VLAN itself (broadcasts and inter-vlan communication).
Navigate to the **Firewall/NAT > Firewall Policies** tab and select **Add Ruleset**.
![EdgeRouter Mikrotik VLAN - Image 28](https://www.geekbitzone.com/posts/2021/networking/vlans/vlan-edgerouter-mikrotik/img/edgerouter-mikrotik-swos-vlan-28.png)
In the **Create New Firewall Ruleset** window, type `IOT_IN` in the **Name** field.
![EdgeRouter Mikrotik VLAN - Image 29](https://www.geekbitzone.com/posts/2021/networking/vlans/vlan-edgerouter-mikrotik/img/edgerouter-mikrotik-swos-vlan-29.png)
Type a **Description** (optional) for this rule. Will type `IOT to Router`.
![EdgeRouter Mikrotik VLAN - Image 30](https://www.geekbitzone.com/posts/2021/networking/vlans/vlan-edgerouter-mikrotik/img/edgerouter-mikrotik-swos-vlan-30.png)
Finally, set the **Default action** to `Accept` and press **Save** to close the window.
![EdgeRouter Mikrotik VLAN - Image 31](https://www.geekbitzone.com/posts/2021/networking/vlans/vlan-edgerouter-mikrotik/img/edgerouter-mikrotik-swos-vlan-31.png)
We will now repeat the previous step by creating another rule, which this time is a *local* rule.
Press the **Add Ruleset** button.
![EdgeRouter Mikrotik VLAN - Image 32](https://www.geekbitzone.com/posts/2021/networking/vlans/vlan-edgerouter-mikrotik/img/edgerouter-mikrotik-swos-vlan-32.png)
In the **Name** field, type `IOT_LOCAL`.
![EdgeRouter Mikrotik VLAN - Image 33](https://www.geekbitzone.com/posts/2021/networking/vlans/vlan-edgerouter-mikrotik/img/edgerouter-mikrotik-swos-vlan-33.png)
Type in a **Description** (optional) for this rule. We will call it `IOT to Local Network`.
![EdgeRouter Mikrotik VLAN - Image 34](https://www.geekbitzone.com/posts/2021/networking/vlans/vlan-edgerouter-mikrotik/img/edgerouter-mikrotik-swos-vlan-34.png)
Make sure that the **Default action** is set to `Drop` and press **Save** to close the window.
![EdgeRouter Mikrotik VLAN - Image 35](https://www.geekbitzone.com/posts/2021/networking/vlans/vlan-edgerouter-mikrotik/img/edgerouter-mikrotik-swos-vlan-35.png)
We will now edit the **IOT\_IN** Ruleset. Place your cursor over this line and select **Actions > Edit Ruleset**.
![EdgeRouter Mikrotik VLAN - Image 36](https://www.geekbitzone.com/posts/2021/networking/vlans/vlan-edgerouter-mikrotik/img/edgerouter-mikrotik-swos-vlan-36.png)
On the **Ruleset Configuration for IOT\_IN** page, select **Add New Rule**.
![EdgeRouter Mikrotik VLAN - Image 37](https://www.geekbitzone.com/posts/2021/networking/vlans/vlan-edgerouter-mikrotik/img/edgerouter-mikrotik-swos-vlan-37.png)
On the **Basic** tab, type in a **Description** for this rule. We will write `Accept Established/Related`.
![EdgeRouter Mikrotik VLAN - Image 38](https://www.geekbitzone.com/posts/2021/networking/vlans/vlan-edgerouter-mikrotik/img/edgerouter-mikrotik-swos-vlan-38.png)
Change the default **Action** to `Accept`.
![EdgeRouter Mikrotik VLAN - Image 39](https://www.geekbitzone.com/posts/2021/networking/vlans/vlan-edgerouter-mikrotik/img/edgerouter-mikrotik-swos-vlan-39.png)
Leave **Protocol** set to `All protocols`.
![EdgeRouter Mikrotik VLAN - Image 40](https://www.geekbitzone.com/posts/2021/networking/vlans/vlan-edgerouter-mikrotik/img/edgerouter-mikrotik-swos-vlan-40.png)
Head over to the **Advanced** tab and set **State** to `Established` and `Related`.
Press **Save** to close the window.
![EdgeRouter Mikrotik VLAN - Image 41](https://www.geekbitzone.com/posts/2021/networking/vlans/vlan-edgerouter-mikrotik/img/edgerouter-mikrotik-swos-vlan-41.png)
On the **Ruleset Configuration for IOT\_IN** page, press the **Add New Rule** button to create another rule.
![EdgeRouter Mikrotik VLAN - Image 42](https://www.geekbitzone.com/posts/2021/networking/vlans/vlan-edgerouter-mikrotik/img/edgerouter-mikrotik-swos-vlan-42.png)
On the **Basic** tab, change the **Description** to `Drop Local Access`.
![EdgeRouter Mikrotik VLAN - Image 43](https://www.geekbitzone.com/posts/2021/networking/vlans/vlan-edgerouter-mikrotik/img/edgerouter-mikrotik-swos-vlan-43.png)
Set default **Action** to `Drop`.
![EdgeRouter Mikrotik VLAN - Image 44](https://www.geekbitzone.com/posts/2021/networking/vlans/vlan-edgerouter-mikrotik/img/edgerouter-mikrotik-swos-vlan-44.png)
Leave **Protocol** set to `All protocols`.
![EdgeRouter Mikrotik VLAN - Image 45](https://www.geekbitzone.com/posts/2021/networking/vlans/vlan-edgerouter-mikrotik/img/edgerouter-mikrotik-swos-vlan-45.png)
Head over to the **Destination** tab and set the **Network Group** to `RF1918 ranges`.
Press **Save** to close the window.
![EdgeRouter Mikrotik VLAN - Image 46](https://www.geekbitzone.com/posts/2021/networking/vlans/vlan-edgerouter-mikrotik/img/edgerouter-mikrotik-swos-vlan-46.png)
On the **Ruleset Configuration for IOT\_IN** page, head over to the **Interfaces** tab.
![EdgeRouter Mikrotik VLAN - Image 47](https://www.geekbitzone.com/posts/2021/networking/vlans/vlan-edgerouter-mikrotik/img/edgerouter-mikrotik-swos-vlan-47.png)
On the **Interfaces** tab, set **Interface** to `switch0.10` and change the **Direction** to `in`.
Press **Save Ruleset**, followed by the **X** button to close the window.
![EdgeRouter Mikrotik VLAN - Image 48](https://www.geekbitzone.com/posts/2021/networking/vlans/vlan-edgerouter-mikrotik/img/edgerouter-mikrotik-swos-vlan-48.png)
We will now open up two ports for *DNS* and *DHCP* requests.
On the **Firewall Policies** page, place your cursor over the **IOT\_LOCAL** row and select **Actions > Edit Ruleset**.
![EdgeRouter Mikrotik VLAN - Image 49](https://www.geekbitzone.com/posts/2021/networking/vlans/vlan-edgerouter-mikrotik/img/edgerouter-mikrotik-swos-vlan-49.png)
On the **Ruleset Configuration for IOT\_LOCAL** page, press **Add New Rule**.
![EdgeRouter Mikrotik VLAN - Image 50](https://www.geekbitzone.com/posts/2021/networking/vlans/vlan-edgerouter-mikrotik/img/edgerouter-mikrotik-swos-vlan-50.png)
On the **Basic** tab, change the **Description** to `Accept DNS`.
![EdgeRouter Mikrotik VLAN - Image 51](https://www.geekbitzone.com/posts/2021/networking/vlans/vlan-edgerouter-mikrotik/img/edgerouter-mikrotik-swos-vlan-51.png)
Set the default **Action** to `Accept`.
![EdgeRouter Mikrotik VLAN - Image 52](https://www.geekbitzone.com/posts/2021/networking/vlans/vlan-edgerouter-mikrotik/img/edgerouter-mikrotik-swos-vlan-52.png)
Set the **Protocol** to `Both TCP and UDP`.
![EdgeRouter Mikrotik VLAN - Image 53](https://www.geekbitzone.com/posts/2021/networking/vlans/vlan-edgerouter-mikrotik/img/edgerouter-mikrotik-swos-vlan-53.png)
Head over to the **Destination** tab and set the **Port** number to `53`.
Press **Save** to close the window.
![EdgeRouter Mikrotik VLAN - Image 54](https://www.geekbitzone.com/posts/2021/networking/vlans/vlan-edgerouter-mikrotik/img/edgerouter-mikrotik-swos-vlan-54.png)
Back on the **Ruleset Configuration for IOT\_LOCAL** page, press the **Add New Rule** button.
![EdgeRouter Mikrotik VLAN - Image 55](https://www.geekbitzone.com/posts/2021/networking/vlans/vlan-edgerouter-mikrotik/img/edgerouter-mikrotik-swos-vlan-55.png)
Change the **Description** to `Accept DHCP`.
![EdgeRouter Mikrotik VLAN - Image 56](https://www.geekbitzone.com/posts/2021/networking/vlans/vlan-edgerouter-mikrotik/img/edgerouter-mikrotik-swos-vlan-56.png)
Set the default **Action** to `Accept`.
![EdgeRouter Mikrotik VLAN - Image 57](https://www.geekbitzone.com/posts/2021/networking/vlans/vlan-edgerouter-mikrotik/img/edgerouter-mikrotik-swos-vlan-57.png)
Set the **Protocol** to `UDP`.
![EdgeRouter Mikrotik VLAN - Image 58](https://www.geekbitzone.com/posts/2021/networking/vlans/vlan-edgerouter-mikrotik/img/edgerouter-mikrotik-swos-vlan-58.png)
Head over to the **Destination** tab and set the **Port** number to `67`.
Press **Save** to close the window.
![EdgeRouter Mikrotik VLAN - Image 59](https://www.geekbitzone.com/posts/2021/networking/vlans/vlan-edgerouter-mikrotik/img/edgerouter-mikrotik-swos-vlan-59.png)
On the **Ruleset Configuration for IOT\_LOCAL** page, head over to the **Interfaces** tab.
![EdgeRouter Mikrotik VLAN - Image 60](https://www.geekbitzone.com/posts/2021/networking/vlans/vlan-edgerouter-mikrotik/img/edgerouter-mikrotik-swos-vlan-60.png)
On the **Interfaces** tab, set **Interface** to `switch0.10` and change the **Direction** to `local`.
Press **Save Ruleset**, followed by the **X** button to close the window.
![EdgeRouter Mikrotik VLAN - Image 61](https://www.geekbitzone.com/posts/2021/networking/vlans/vlan-edgerouter-mikrotik/img/edgerouter-mikrotik-swos-vlan-61.png)
The completed Firewall Policies page should now look like this.
![EdgeRouter Mikrotik VLAN - Image 62](https://www.geekbitzone.com/posts/2021/networking/vlans/vlan-edgerouter-mikrotik/img/edgerouter-mikrotik-swos-vlan-62.png)
We have now finished configuring the EdgeRouter and will head over to the MikroTik switch to set up a VLAN.
---
## Setting up a VLAN on the CSS610-8G-2S+IN
We will begin by logging in to the CSS610-8G-2S+IN switch. Open the admin page, which in our case is `192.168.1.88`, and type in your `username` and `password`.
![EdgeRouter Mikrotik VLAN - Image 63](https://www.geekbitzone.com/posts/2021/networking/vlans/vlan-edgerouter-mikrotik/img/edgerouter-mikrotik-swos-vlan-63.png)
We can see on the **Link** tab that **Port1** is connected to the `EdgeRouter` and that **Port2** is connected to the `IOT` device. (We have named the ports ourselves).
![EdgeRouter Mikrotik VLAN - Image 64](https://www.geekbitzone.com/posts/2021/networking/vlans/vlan-edgerouter-mikrotik/img/edgerouter-mikrotik-swos-vlan-64.png)
With this knowledge at hand, navigate to the **VLAN** tab.
![EdgeRouter Mikrotik VLAN - Image 65](https://www.geekbitzone.com/posts/2021/networking/vlans/vlan-edgerouter-mikrotik/img/edgerouter-mikrotik-swos-vlan-65.png)
On the **IOT** port, set **VLAN Mode** to `strict`.
![EdgeRouter Mikrotik VLAN - Image 66](https://www.geekbitzone.com/posts/2021/networking/vlans/vlan-edgerouter-mikrotik/img/edgerouter-mikrotik-swos-vlan-66.png)
Set **VLAN Receive** to accept `only untagged` traffic.
![EdgeRouter Mikrotik VLAN - Image 67](https://www.geekbitzone.com/posts/2021/networking/vlans/vlan-edgerouter-mikrotik/img/edgerouter-mikrotik-swos-vlan-67.png)
Finally, set the **Default VLAN ID** to `10`, which is the VLAN value used on the EdgeRouter.
![EdgeRouter Mikrotik VLAN - Image 68](https://www.geekbitzone.com/posts/2021/networking/vlans/vlan-edgerouter-mikrotik/img/edgerouter-mikrotik-swos-vlan-68.png)
Press **Apply All** to save the changes.
![EdgeRouter Mikrotik VLAN - Image 69](https://www.geekbitzone.com/posts/2021/networking/vlans/vlan-edgerouter-mikrotik/img/edgerouter-mikrotik-swos-vlan-69.png)
Next, navigate to the **VLANs** tab where you will be presented by a blank page.
![EdgeRouter Mikrotik VLAN - Image 70](https://www.geekbitzone.com/posts/2021/networking/vlans/vlan-edgerouter-mikrotik/img/edgerouter-mikrotik-swos-vlan-70.png)
Press the **Append** button to create a new entry.
![EdgeRouter Mikrotik VLAN - Image 71](https://www.geekbitzone.com/posts/2021/networking/vlans/vlan-edgerouter-mikrotik/img/edgerouter-mikrotik-swos-vlan-71.png)
Enter `10` under **VLAN ID**.
![EdgeRouter Mikrotik VLAN - Image 72](https://www.geekbitzone.com/posts/2021/networking/vlans/vlan-edgerouter-mikrotik/img/edgerouter-mikrotik-swos-vlan-72.png)
Only check the port **Members** that should belong to VLAN 10. In this case `one` and `two` have been checked, i.e. the EdgeRouter and the IOT Device.
![EdgeRouter Mikrotik VLAN - Image 73](https://www.geekbitzone.com/posts/2021/networking/vlans/vlan-edgerouter-mikrotik/img/edgerouter-mikrotik-swos-vlan-73.png)
Press **Apply All** to save the changes.
![EdgeRouter Mikrotik VLAN - Image 74](https://www.geekbitzone.com/posts/2021/networking/vlans/vlan-edgerouter-mikrotik/img/edgerouter-mikrotik-swos-vlan-74.png)
The VLAN has now been set up on the MikroTik switch.
---
## Verifying the setup
We are now ready to test if the VLAN and the firewall rules actually work. In the following section we will be logging in to our devices, both inside and outside the IOT VLAN to see if certain destinations can reached with the `ping` command.
- Our EdgeRouter has an IP address of `192.168.1.1` on the main network and `10.0.10.1` on the IOT VLAN.
- The IOT Device has an IP address of `10.0.10.100`.
- We also have a computer on the main network with an IP address of `192.168.1.100`.
---
### Test 1: Can the IOT device reach the Internet?
We will ping `google.com` from `10.0.10.100` (inside VLAN 10).
```
$ ping google.com
PING google.com (172.217.169.78): 56 data bytes
64 bytes from 172.217.169.78: icmp_seq=0 ttl=118 time=1.547 ms
64 bytes from 172.217.169.78: icmp_seq=1 ttl=118 time=1.590 ms
64 bytes from 172.217.169.78: icmp_seq=2 ttl=118 time=1.713 ms
--- google.com ping statistics ---
3 packets transmitted, 3 packets received, 0.0% packet loss
round-trip min/avg/max/stddev = 1.547/1.617/1.713/0.070 ms
```
**Result:** The IOT device *can* reach the internet.
---
### Test 2: Can the IOT device reach other devices outside VLAN 10?
We will ping `192.168.1.100`, which is a computer on the main network, from `10.0.10.100`.
```
$ ping 192.168.1.100
PING 192.168.1.100 (192.168.1.100): 56 data bytes
Request timeout for icmp_seq 0
Request timeout for icmp_seq 1
Request timeout for icmp_seq 2
--- 192.168.1.100 ping statistics ---
4 packets transmitted, 0 packets received, 100.0% packet loss
```
**Result:** The IOT device *can not* reach devices outside VLAN 10 on a private network.
---
### Test 3: Can the IOT device reach the router (gateway)?
We will ping `10.0.10.1` and `192.168.1.1` from `10.0.10.100`.
```
$ ping 10.0.10.1
PING 10.0.10.1 (10.0.10.1): 56 data bytes
Request timeout for icmp_seq 0
Request timeout for icmp_seq 1
Request timeout for icmp_seq 2
--- 10.0.10.1 ping statistics ---
4 packets transmitted, 0 packets received, 100.0% packet loss
$ ping 192.168.1.1
PING 192.168.1.1 (192.168.1.1): 56 data bytes
Request timeout for icmp_seq 0
Request timeout for icmp_seq 1
Request timeout for icmp_seq 2
--- 192.168.1.1 ping statistics ---
4 packets transmitted, 0 packets received, 100.0% packet loss
```
**Result:** The router *can not* be reached from within or outside VLAN 10.
---
### Test 4: Can devices on the main network (outside VLAN 10) reach the IOT device?
We will use a computer on the main network, `192.168.1.100`, to ping the IOT device at `10.0.10.100`.
```
$ ping 10.0.10.100
PING 10.0.10.100 (10.0.10.100): 56 data bytes
64 bytes from 10.0.10.100: icmp_seq=0 ttl=63 time=0.870 ms
64 bytes from 10.0.10.100: icmp_seq=1 ttl=63 time=1.088 ms
64 bytes from 10.0.10.100: icmp_seq=2 ttl=63 time=1.290 ms
--- 10.0.10.100 ping statistics ---
3 packets transmitted, 3 packets received, 0.0% packet loss
round-trip min/avg/max/stddev = 0.870/1.083/1.290/0.172 ms
```
**Result:** Devices on the main network *can* reach the IOT network.
---
## Summary
This tutorial has shown how you can secure IOT devices from the main network by setting up a Virtual Local Area Network (**VLAN**) with firewall rules between an Ubiquiti Networks™ EdgeMAX® **EdgeRouter™ X**, and a MikroTik **CSS610-8G-2S+IN** switch running **SwOS Lite**.
---
## References
**EdgeRouter™ X**
[https://www.ui.com/edgemax/edgerouter-x/](https://www.ui.com/edgemax/edgerouter-x/)
**CSS610-8G-2S+IN**
[https://mikrotik.com/product/css610\_8g\_2s\_in](https://mikrotik.com/product/css610_8g_2s_in)
**SwOS Lite Manual**
[https://wiki.mikrotik.com/wiki/SwOS/CSS610](https://wiki.mikrotik.com/wiki/SwOS/CSS610)
**EdgeOS v2.0.9-hotfix.1 firmware**
[https://www.ui.com/download/edgemax/default/default/edgerouter-er-xer-x-sfpep-r6er-10x-firmware-v209-hotfix1](https://www.ui.com/download/edgemax/default/default/edgerouter-er-xer-x-sfpep-r6er-10x-firmware-v209-hotfix1)
**SwOS Lite 2.13**
[https://www.mikrotik.com/download](https://www.mikrotik.com/download)
**RFC1918 Private Internets**
[https://tools.ietf.org/html/rfc1918](https://tools.ietf.org/html/rfc1918)