You are on page 1of 4

home.swkls.org http://home.swkls.

org/mikrotik-vlan-trunk-and-unifi-ap/
Steve Andrews
Mikrotik VLAN Trunk and Unifi AP
Suppose we have an access point capable of multiple SSID and VLAN. We want to set up an open hotspot
f or public access on one channel, and a secured channel f or staf f . For this exercise, we will use a Ubiquiti
Unif i AP and set up two WLANs. The f irst WLAN will be called Public and be assigned to VLAN ID 20. The
second WLAN will be called Secured and be assigned to VLAN ID 10. Our basic diagram looks something
like this:
The general idea will be to create a VLAN trunk between the AP and the Mikrotik router to pass traf f ic f or
both VLANs. In addition, the Unif i AP will be in its own subnet f or management purposes and needs to be
untagged (not assigned to a VLAN). The Public WLAN will be given its own subnet and will pass through a
hotspot conf igured on the Mikrotik, while the Secured WLAN will be part of the regular wired LAN.
The Unif i AP is already conf igured with the two WLANs / VLANs, is adopted by a controller at the def ault
address (http://unif i:8080/inf orm ), and has a static IP of 192.168.250.199.
If we are not running a DNS server of our own, we can tell the AP to use the Mikrotik routers IP
(192.168.88.1) f or DNS and then insert a static entry to f orward requests to the appropriate:
/ip dns static
add address=1.1.1.1 disabled=yes name=uni ttl=1d
Obviously, change 1.1.1.1 to your controllers IP address.
Next, lets use port 5 of the router and construct a trunk f or both VLANs and the untagged management
subnet of the AP. We need to un-assign the master port option f or port 5 if it is set as a slave to another
port. The name of the interf ace has been set to ether5-vlan-wireless. We create our two VLANs:
/interface vlan
add arp=enabled disabled=no interface=ether5-vlan-wireless l2mtu=1594 mtu=\
1500 name=vlan10secured use-service-tag=no vlan-id=10
add arp=enabled disabled=no interface=ether5-vlan-wireless l2mtu=1594 mtu=\
1500 name=vlan20public use-service-tag=no vlan-id=20
Now, what we want to do is create a bridge which will include both port 2 (regular LAN / wired clients) and
VLAN10 (secured wireless). We need to then assign / move the DHCP server that was running on port 2 to
the bridge. First, create the bridge:
add admin-mac=00:00:00:00:00:00 ageing-time=5m arp=enabled auto-mac=yes \
disabled=no forward-delay=15s l2mtu=1594 max-message-age=20s mtu=1500 \
name=bridge1 priority=0x8000 protocol-mode=none transmit-hold-count=6
Now, assign both port 2 and vlan10 to the bridge:
/interface bridge port
add bridge=bridge1 disabled=no edge=auto external-fdb=auto horizon=none \
interface=vlan10secured path-cost=10 point-to-point=auto priority=0x80
add bridge=bridge1 disabled=no edge=auto external-fdb=auto horizon=none \
interface=ether2-master-local path-cost=10 point-to-point=auto priority=\
0x80
In my case, I pref er to assign IP addresses to secured wireless machines via the alternate conf iguration tab
in Windows TCP/IP settings. But f or this to work, the wireless client must not see any DHCP services
running on the secured WLAN it is connecting to. So, we create a bridge f ilter rule to block DHCP on
VLAN10:
/interface bridge settings
set use-ip-rewall=yes
/interface bridge lter
add action=drop chain=input disabled=no in-interface=vlan10secured \
ip-protocol=udp mac-protocol=ip src-port=67-68
Notice the f irst line that tells the bridge to use f irewall rules. Very important!
As f or IP addresses on the local interf aces, we have the f ollowing:
/ip address
add address=192.168.88.1/24 comment="default conguration" disabled=no \
interface=ether2-master-local network=192.168.88.0
add address=192.168.151.1/24 disabled=no interface=vlan20public network=\
192.168.151.0
add address=192.168.250.1/24 disabled=no interface=ether5-vlan-wireless \
network=192.168.250.0
These addresses are f or the normal LAN (192.168.88.0/24), the public wireless (192.168.151.0/24), and the
Unif i management subnet (192.168.250.0/24). The Unif i needs an untagged or non-vlan path to
communicate with a controller. If we didnt care about the AP communicating with a controller, we could drop
the IP assignment f or the physical port 5. Please note that if you are using guest portal on the Unif i, you
need the controller.
Now, we move or create a DHCP service f or the bridge interf ace and VLAN20:
/ip dhcp-server
add address-pool=default-dhcp authoritative=after-2sec-delay bootp-support=\
static disabled=no interface=bridge1 lease-time=3d name=default
add address-pool=vlan20public authoritative=after-2sec-delay bootp-support=\
static disabled=no interface=vlan20public lease-time=3d name=vlan20public
/ip dhcp-server network
add address=192.168.88.0/24 comment="default conguration" dhcp-option="" \
dns-server=192.168.88.1 gateway=192.168.88.1 ntp-server="" wins-server=""
add address=192.168.151.0/24 comment=vlan20public dhcp-option="" dns-server=\
"" gateway=192.168.151.1 ntp-server="" wins-server=""
A little explanation may be in order in regards to the DHCP stuf f . The service needs to run on the bridge
interf ace, and will not work on a port assigned to a bridge. So, if we have the def ault DHCP server going on
the def ault port 2, and then move port 2 into a bridge, DHCP stops. Furthermore, being as the DHCP
service is now on the bridge, it will also hand out leases to the wireless clients on VLAN10 as well as port 2,
and whatever other ports might be slaved to port2. Again, in my case, I didnt want DHCP running across the
VLAN10 interf ace, so it was blocked by f ilter rules.
As f or the hotspot service, we need to run it on the VLAN20 interf ace:
/ip hotspot
add disabled=no idle-timeout=none interface=vlan20public keepalive-timeout=\
/ip hotspot prole
set [ nd default=yes ] dns-name=spot.hot hotspot-address=192.168.151.1 \
This is just a snippet f or the hotspot, but the main thing to take away is that the interf ace needs to be the
VLAN interf ace, not the physical port.
Lets not f orget to block traf f ic between our public and internal networks, and also block public traf f ic to
the AP management subnet:
/ip rewall lter
add action=drop chain=input disabled=no dst-address=192.168.88.0/24 \
src-address=192.168.151.0/24
add action=drop chain=input disabled=no dst-address=192.168.250.0/24 \
src-address=192.168.151.0/24

You might also like