Thanks everyone for this great topic! It helped me set up my own network where I have a combined router+switch in one with a trunk port to my VLAN-aware access point. I have two questions I hope you can help me with ![]()
- In my situation, should I have L2 or L3 switch? I.e. should bridge1 be tagged on all VLANs or not? Why?
- How do I know whether I use âhardware accelerationâ or not? Iâm a bit confused by the many webfig/terminal locations where âvlanâ appears.
My setup is as follows:
- VLAN99 is management (172.16.99.0/24), VLAN20 for IoT (no WAN access, only access to server in VLAN99, 172.16.20.0/24), VLAN10 for guest use (only WAN access, 172.16.10.0/24)
- ether1 is used as trunk with VLAN 10 & 20 tagged and VLAN99 untagged for connection to my access point
- ether3 & ether4 are part of VLAN 10, all other ethers are part of VLAN99
- The access point broadcasts one SSID for each VLAN 10, 20, 99
- sfp1 is used for WAN and tagged with VLAN34 (dictated by ISP)
- Iâm running an IPSec server (not shown here) serving clients on 172.16.30.0/24, hence for some firewall rules filter on 172.16.0.0/16 to distinguish WAN and VPN traffic
My config:
###############################################################################
Topic: Using RouterOS to VLAN your network
Example: Router-Switch-AP all in one device
Web: > http://forum.mikrotik.com/t/using-routeros-to-vlan-your-network/126489/1
RouterOS: 6.43.12
Date: Mar 28, 2019
Notes: Start with a reset (/system reset-configuration)
Thanks: mkx, sindy
###############################################################################
#######################################
Naming
#######################################
name the device being configured
/system identity set name=ârb2011â
#######################################
VLAN Overview
#######################################
10 = Guest
20 = IoT
99 = BASE (MGMT) VLAN
#######################################
Bridge
#######################################
create one bridge, set VLAN mode off while we configure
/interface bridge add name=bridge1 protocol-mode=none vlan-filtering=no
#######################################
â Access Ports â
#######################################
ingress behavior
/interface bridge port
Purple Trunk to AP. PVID is only needed when combining tagged + untagged
trunk (vs fully tagged), but does not hurt so enable.
add bridge=bridge1 interface=ether1 pvid=99
Guest VLAN
add bridge=bridge1 interface=ether3 pvid=10
add bridge=bridge1 interface=ether4 pvid=10IoT VLAN
BASE_VLAN / Full access
add bridge=bridge1 interface=ether2 pvid=99
add bridge=bridge1 interface=ether5 pvid=99
add bridge=bridge1 interface=ether6 pvid=99
add bridge=bridge1 interface=ether7 pvid=99
add bridge=bridge1 interface=ether8 pvid=99
add bridge=bridge1 interface=ether9 pvid=99
add bridge=bridge1 interface=ether10 pvid=99Tim: WAN VLAN tagging is not set here because itâs not part of bridge
egress behavior
/interface bridge vlan
Guest, IoT, & BASE VLAN + Purple uplink trunk (ether1)
L3 switching so Bridge must be a tagged member
In case of fully tagged trunk, set ether1 to tagged for vlan 99 as well (instead of untagged)
add bridge=bridge1 vlan-ids=10 tagged=bridge1,ether1 untagged=ether3,ether4
add bridge=bridge1 vlan-ids=20 tagged=bridge1,ether1
add bridge=bridge1 vlan-ids=99 tagged=bridge1 untagged=ether1,ether2,ether5,ether6,ether7,ether8,ether9,ether10#######################################
IP Addressing & Routing
#######################################
LAN facing routerâs IP address on the BASE_VLAN
/interface vlan add interface=bridge1 name=BASE_VLAN vlan-id=99
/ip address add address=172.16.99.1/24 interface=BASE_VLANDNS server, set to cache for LAN
/ip dns set allow-remote-requests=yes servers=â172.16.99.1â
From > http://forum.mikrotik.com/t/rb951g-2hnd-vlan-tag-on-wan-port/81791/1
/interface vlan add interface=sfp1 name=WAN_VLAN vlan-id=34
Set DHCP WAN client on ether6 AND WAN_VLAN
/ip dhcp-client
add disabled=no interface=WAN_VLAN#######################################
IP Services
#######################################
Guest VLAN interface creation, IP assignment, and DHCP service
/interface vlan add interface=bridge1 name=GUEST_VLAN vlan-id=10
/ip address add interface=GUEST_VLAN address=172.16.10.1/24
/ip pool add name=GUEST_POOL ranges=172.16.10.100-172.16.10.254
/ip dhcp-server add address-pool=GUEST_POOL interface=GUEST_VLAN name=GUEST_DHCP disabled=no
/ip dhcp-server network add address=172.16.10.0/24 dns-server=172.16.99.1 gateway=172.16.10.1IoT VLAN interface creation, IP assignment, and DHCP service
/interface vlan add interface=bridge1 name=IoT_VLAN vlan-id=20
/ip address add interface=IoT_VLAN address=172.16.20.1/24
/ip pool add name=IoT_POOL ranges=172.16.20.100-172.16.20.254
/ip dhcp-server add address-pool=IoT_POOL interface=IoT_VLAN name=IoT_DHCP disabled=no
/ip dhcp-server network add address=172.16.20.0/24 dns-server=172.16.99.1 gateway=172.16.20.1Optional: Create a DHCP instance for BASE_VLAN. Convenience feature for an admin.
/ip pool add name=BASE_POOL ranges=172.16.99.100-172.16.99.254
/ip dhcp-server add address-pool=BASE_POOL interface=BASE_VLAN name=BASE_DHCP disabled=no
/ip dhcp-server network add address=172.16.99.0/24 dns-server=172.16.99.1 gateway=172.16.99.1#######################################
Firewalling & NAT
A good firewall for WAN. Up to you
about how you want LAN to behave.
#######################################
Use MikroTikâs âlistâ feature for easy rule matchmaking.
/interface list add name=WAN
/interface list add name=VLAN2WAN
/interface list add name=VLAN
/interface list add name=BASE/interface list member
add interface=sfp1 list=WAN
add interface=WAN_VLAN list=WAN
add interface=BASE_VLAN list=VLAN2WAN
add interface=GUEST_VLAN list=VLAN2WANadd interface=IoT_VLAN list=VLAN2BASE
add interface=BASE_VLAN list=BASE
add interface=BASE_VLAN list=VLAN
add interface=GUEST_VLAN list=VLAN
add interface=IoT_VLAN list=VLANVLAN aware firewall. Order is important.
##################
INPUT CHAIN
##################
/ip firewall filter
add chain=input action=accept connection-state=established,related comment=âAllow Estab & RelatedâAllow BASE_VLAN full access to the device for Winbox, etc.
add chain=input action=accept in-interface-list=BASE comment=âAllow BASE VLAN router accessâ
Allow IKEv2 VPN server on router
add action=accept chain=input comment=âdefconf: accept IKEâ dst-port=500,4500 protocol=udp
add action=accept chain=input comment=âdefconf: accept ipsec AHâ protocol=ipsec-ah
add action=accept chain=input comment=âdefconf: accept ipsec ESPâ protocol=ipsec-espAllow clients to do DNS, for both TCP and UDP
add chain=input action=accept dst-port=53 src-address=172.16.0.0/16 proto=tcp comment=âAllow all LAN and VPN clients to access DNSâ
add chain=input action=accept dst-port=53 src-address=172.16.0.0/16 proto=udp comment=âAllow all LAN and VPN clients to access DNSâadd chain=input action=drop comment=âDropâ
##################
FORWARD CHAIN
##################
/ip firewall filter
add chain=forward action=accept connection-state=established,related comment=âAllow Estab & RelatedâAllow selected VLANs to access the Internet
add chain=forward action=accept connection-state=new in-interface-list=VLAN2WAN out-interface-list=WAN comment=âVLAN Internet Access onlyâ
Allow IoT IoT_VLAN to access server in BASE_VLAN, but no WAN.
add chain=forward action=accept connection-state=new in-interface=IoT_VLAN out-interface=BASE_VLAN dst-address=172.16.99.2 comment=âAllow IoT_VLAN â server in BASE_VLANâ
add chain=forward action=accept connection-state=new in-interface=BASE_VLAN out-interface=IoT_VLAN comment=âAllow all of BASE_VLAN â IoT_VLANâAllow IPSec traffic from 172.16.30.0/24
add action=accept chain=forward comment=âDEFAULT: Accept In IPsec policy.â ipsec-policy=in,ipsec src-address=172.16.30.0/24
add action=accept chain=forward comment=âDEFAULT: Accept Out IPsec policy.â disabled=yes ipsec-policy=out,ipsecadd chain=forward action=drop comment=âDropâ
##################
NAT
##################
/ip firewall nat
add chain=srcnat action=masquerade out-interface-list=WAN comment=âDefault masqueradeâ
add action=masquerade chain=srcnat comment="Hairpin NAT > https://www.steveocee.co.uk/mikrotik/hairpin-nat/> " dst-address=172.16.99.2 out-interface=BASE_VLAN src-address=172.16.0.0/16##################
Disable unused service ports, whatever this is
##################
/ip firewall service-port
set ftp disabled=yes
set tftp disabled=yes
set irc disabled=yes
set h323 disabled=yes
set sip disabled=yes
set pptp disabled=yes
set udplite disabled=yes
set sctp disabled=yes#######################################
VLAN Security
#######################################
Only allow ingress packets without tags on Access Ports
/interface bridge port
Only
set bridge=bridge1 ingress-filtering=yes frame-types=admit-only-untagged-and-priority-tagged [find interface=ether2]
set bridge=bridge1 ingress-filtering=yes frame-types=admit-only-untagged-and-priority-tagged [find interface=ether3]
set bridge=bridge1 ingress-filtering=yes frame-types=admit-only-untagged-and-priority-tagged [find interface=ether4]
set bridge=bridge1 ingress-filtering=yes frame-types=admit-only-untagged-and-priority-tagged [find interface=ether5]
set bridge=bridge1 ingress-filtering=yes frame-types=admit-only-untagged-and-priority-tagged [find interface=ether6]
set bridge=bridge1 ingress-filtering=yes frame-types=admit-only-untagged-and-priority-tagged [find interface=ether7]
set bridge=bridge1 ingress-filtering=yes frame-types=admit-only-untagged-and-priority-tagged [find interface=ether8]
set bridge=bridge1 ingress-filtering=yes frame-types=admit-only-untagged-and-priority-tagged [find interface=ether9]
set bridge=bridge1 ingress-filtering=yes frame-types=admit-only-untagged-and-priority-tagged [find interface=ether10]
/interface bridge portFor tagged + untagged trunk (management VLAN being untagged), we allow both type of frames
set bridge=bridge1 ingress-filtering=yes frame-types=admit-all [find interface=ether1]
Only allow tagged packets on WAN port
set bridge=bridge1 ingress-filtering=yes frame-types=admit-only-vlan-tagged [find interface=sfp1]
#######################################
MAC Server settings
#######################################
Ensure only visibility and availability from BASE_VLAN, the MGMT network
/ip neighbor discovery-settings set discover-interface-list=BASE
/tool mac-server mac-winbox set allowed-interface-list=BASE
/tool mac-server set allowed-interface-list=BASE#######################################
Turn on VLAN mode
#######################################
/interface bridge set bridge1 vlan-filtering=yes