RB5009 help to configure (Switch, VLANs)

Hello,

I’ve been trying to get the configuration to work, but after a week, I’m really fed up… I was searching for similar topics, trying to glue the configuration but without a luck.
I also followed this article http://forum.mikrotik.com/t/using-routeros-to-vlan-your-network/126489/1
and no luck.

Could you help me to get the router to work, please?

# VLAN Overview 
###############
# VLAN_10: Backend devices - 10.0.10.0/24
# - Linux device - Controller for UniFi
# - UniFi AP device
# Services:
# - Pi-hole as DNS forwarder - for all VLANs
# 
# VLAN_20: Media Services (TV modem)  - 10.0.20.0/24
# - Access to the Internet
# - Blocked access to other VLANs
# 
# VLAN_30: Wi-Fi Home users  - 10.0.30.0/24
# - Access to the Internet
# - Access to IoT VLAN to the printer (AirPrint)
# - Access to VLAN_10 ports (22,53,80,443)
# - Access to VLAN_50 ports (22,80,443,3389)
# 
# VLAN_40: Wi-Fi Guest  - 10.0.40.0/24
# - Access only to the Internet (80,443)
# - Access to VLAN_10 DNS server (53)
# 
# VLAN_50: IoT (printer as well?)  - 10.0.50.0/24
# - Access to the Internet
# - DNS for devices 1.1.1.1
# - Printer IP: 10.0.50.2
# 
# VLAN_60: DMZ  - 10.0.60.0/24
# - Access to the Internet
# - Access to VLAN_10 DNS server (53)
# - Access from the Internet: exposed ports to the Internet (8888) from IP 10.0.60.2
#
# VLAN_100: Management port ether8  - 10.0.100.0/24
# - Outgoing: Access to all VLANs and Internet
# - Incoming: Blocked from other VLANs

# Port overview
# ether1 - WAN (dhcp client)
# ether2 - Backend devices (VLAN_10 Access)
# ether3 - Unifi AP device (VLAN_10 Access, VLAN_30 SSID:HOME, VLAN_40 SSID:GUEST, VLAN_50 SSID:IoT)
# ether4 - Linux device (VLAN_20 Access)
# ether5 - Linux Device (VLAN_60 Access)
# ether6 - Management port (VLAN_100)

# VPN: OpenVPN Server 
# - Access to the Internet
# - Access to VLAN_10 to ports (53, 443, 22)
# - Access to VLAN_30 to IP 10.0.30.2 (3389)
# - Access to VLAN_50 to printer 10.0.50.2 (AirPrint)
# - Access to VLAN_60 to ports 22,3389

Post your complete config please.

/export file=anynameyouwish ( minus the router serial number and any public WANIP information )

Then I can guide you in the right direction.

Here is the output:
I haven not configured more than below, as I wanted to solve this issue first.

# jan/02/1970 06:42:38 by RouterOS 7.5
# software id = 2XKJ-KFM8
#
# model = RB5009UPr+S+
/interface bridge
add name=BR1 protocol-mode=none vlan-filtering=yes
/interface vlan
add interface=BR1 name=BLUE_VLAN vlan-id=10
/interface wireless security-profiles
set [ find default=yes ] supplicant-identity=MikroTik
/ip pool
add name=BLUE_POOL ranges=10.0.10.2-10.0.10.254
/ip dhcp-server
add address-pool=BLUE_POOL interface=BLUE_VLAN name=BLUE_DHCP
/interface bridge port
add bridge=BR1 frame-types=admit-only-untagged-and-priority-tagged interface=\
    ether2 pvid=10
/ip neighbor discovery-settings
set discover-interface-list=!dynamic
/ip address
add address=10.0.10.1/24 interface=BLUE_VLAN network=10.0.10.0
/ip dhcp-server network
add address=10.0.10.0/24 dns-server=192.168.0.1 gateway=10.0.10.1

what i dont get on your diagram is why is vlan10 which seems to be home users, not used for home wifi?
Why change to vlan30 for home users. What is the purpose of vlan20… IOT devices, media devices?

Or is vlan10 the stated vlan for your ISP connection on ether1 ???

Yes, you are right @anav.
I’ve updated network diagram and VLAN/Port overview.
Should be better now unless you have comments to the design of network.

Its making more sense now thanks!
Except for the DMZ, what do you mean by that specifically what will you be using it for… will it need internet access for example??

Good catch!, Updated the code block at the first post. Added also VPN part.

Im no good with opnvpn, Good at wireguard though which is faster and easier to implement.

Do you have a bunch of vpn users that need access to your subnets?

No, no, just me.
Wireguard is fine as well.

Here is a sample setup…
I didnt have the IP address of the pihole server…
Also its easier to allow a lan subnet or users to access a particular IP or set of IP addresses in another LAN, doing it by ports alone is unknown to me.


/interface bridge
add name=onebridge
/interface wireguard
add name=WG listen-port=55820
/interface wireguard peers
add interface=WG public-key=<remote device1 generaged public key> allowed-address=192.168.50.2/32  { remote laptop }
add interface=WG public-key=<remote device2 generaged public key> allowed-address=192.168.50.3/32 { remote iphone/ipad }
/interface vlan
add interface=onebridge name=vlan10_control vlan-id=10
add interface=onebridge name=vlan20-Media vlan-id=20
add interface=onebridge name=vlan30-Home vlan-id=30
add interface=onebridge name=vlan40-Gwifi vlan-id=40
add interface=onebridge name=vlan50-IOT vlan-id=50
add interface=onebridge name=vlan60-DMZ vlan-id=60
add interface=onebridge name=vlan100-Manage vlan-id=100
/interface list
add comment=defconf name=WAN
add comment=defconf name=LAN
add name=Manage
add name=block-printer
/ip pool
add name=dhcp_control ranges=10.0.10.2-192.168.10.254
add name=dhcp_media ranges=10.0.20.2-192.168.20.254
add name=dhcp_home ranges=10.0.30.2-192.168.30.254
add name=dhcp_gwifi ranges=10.0.40.2-192.168.40.254
add name=dhcp_iot ranges=10.0.50.2-192.168.50.254
add name=dhcp_dmz ranges=10.0.60.2-192.168.60.254
add name=dhcp_manage ranges=10.0.100.5-192.168.100.10
/ip dhcp-server
add address-pool=dhcp-control interface=vlan10-Control name=control-server
add address-pool=dhcp_media interface=vlan20-Media name=media-server
add address-pool=dhcp_home interface=vlan30-Home name=home-server
add address-pool=dhcp_gwifi interface=vlan40-Gwifi name=gwifi-server
add address-pool=dhcp_iot interface=vlan50-IOT name=iot-server
add address-pool=dhcp_dmz interface=vlan60-DMZ name=dmz-server
add address-pool=dhcp_manage interface=vlan100-Manage name=manage-server
/interface bridge port
add bridge=onebridge comment=defconf ingress-filtering=yes frame-types=admit-priority-and-untagged interface=ether2 pvid=10
add bridge=onebridge ingress-filtering=no interface=ether3 pvid=10
add bridge=onebridge ingress-filtering=yes frame-types=admit-priority-and-untagged interface=ether4 pvid=20
add bridge=onebridge ingress-filtering=yes frame-types=admit-priority-and-untagged interface=ether5 pvid=60
add bridge=onebridge ingress-filtering=yes frame-types=admit-priority-and-untagged interface=ether8 pvid=100
/interface bridge vlans
add bridge=onebridge tagged=onebridge untagged=ether2,ether3 vlan-ids=10
add bridge=onebridge tagged=onebridge,ether3  vlan-ids=30,40,50
add bridge=onebridge tagged=onebridge untagged=ether4 vlan-ids=20
add bridge=onebridge tagged=onebridge untagged=ether5 vlan-ids=60
add bridge=onebridge tagged=onebridge untagged=ether8 vlan-ids=100
/ip neighbor discovery-settings
set discover-interface-list=MANAGE
/interface detect-internet
set detect-interface-list=NONE
/interface list member
add interface=ether1 list=WAN
add interface=vlan10-Control list=LAN
add interface=vlan20-Media list=LAN
add interface=vlan30-Home list=LAN
add interface=vlan40-Gwifi list=LAN
add interface=vlan50-IOT list=LAN
add interface=vlan60-DMZ list=LAN
add interface=vlan100-Manage list=LAN
add interface=vlan100-Manage list=MANAGE
add interface=WG list=MANAGE
add interface=vlan60-DMZ list=block-printer
add interface=vlan40-Gwifi list=block-printer
/ip address
add address=10.0.10.1/24 interface=vlan10-Control network=10.0.10.0
add address=10.0.20.1/24 interface=vlan20-Media network=10.0.20.0
add address=10.0.30.1/24 interface=vlan30-Home network=10.0.30.0
add address=10.0.40.1/24 interface=vlan40-Gwifi network=10.0.40.0
add address=10.0.50.1/24 interface=vlan50-IOT network=10.0.50.0
add address=10.0.60.1/24 interface=vlan60-DMZ network=10.0.60.0
add address=10.0.100.1/24 interface=vlan100-Manage network=10.0.100.0
add address=192.168.50.1/24 interface=WG network=192.168.50.0
/ip dhcp-server network
add address=10.0.10.0/24  gateway=10.0.10.1 dns-server=10.0.10.1
add address=10.0.20.0/24   gateway=10.0.20.1 dns-server=Pihole(IP)
add address=10.0.30.0/24  gateway=10.0.30.1 dns-server=Pihole(IP)
add address=10.0.40.0/24  gateway=10.0.40.1  dns-server=Pihole(IP)
add address=10.0.50.0/24  gateway=10.0.50.1  dns-server=1.1.1.1
add address=10.0.60.0/24  gateway=10.0.60.1  dns-server=Pihole(IP)
add address=10.0.100.0/24   gateway=10.0.100.1  dns-server=Pihole(IP)
/ip dns
set allow-remote-requests=yes servers=8.8.8.8,1.1.1.1
/ip firewall address list
add address=10.0.50.0/24 list=exclude-pihole
add address=10.0.10.2  list=exclude-pihole
add address=10.0.10.2  list=thirty2ten  {  destination IP on vlan10 being accessed by home users }
add address=10.0.10.3  list=thirty2ten  {  destination IP on vlan10 being accessed by home users }
add address=10.0.50.2 list=thirty2fifty  {  destination IP on vlan50 being accessed by home users }
/ip firewall filter
add action=accept chain=input comment=\
    "defconf: accept established,related,untracked" connection-state=\
    established,related,untracked
add action=drop chain=input comment="defconf: drop invalid" connection-state=\
    invalid 
add action=accept chain=input comment="defconf: accept ICMP" protocol=icmp
add action=accept chain=input dst-port=55820 protocol=udp log=yes
add action=accept chain=input in-interface-list=MANAGE
add action=accept chain=input dst-port=53 protocol=tcp in-interface-list=LAN
add action=accept chain=input dst-port=53 protocol=udp in-interface-list=LAN
add action=drop chain=input comment="drop all else"
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
add action=fasttrack-connection chain=forward comment="defconf: fasttrack" \
    connection-state=established,related hw-offload=yes
add action=accept chain=forward comment=\
    "defconf: accept established,related, untracked" connection-state=\
    established,related,untracked
add action=drop chain=forward comment="defconf: drop invalid" \
    connection-state=invalid
add action=accept chain=forward in-interface-list=MANAGE out-interface-list=LAN
add action=accept chain=forward in-interface=WG
add action=accept chain=forward in-interface-list=LAN out-interface-list=WAN
add action=drop chain=forward in-interface-list=block-printer out-interface=Vlan50-IOT
add action=accept chain=forward in-interface-list=LAN out-interface=vlan50-IOT dst-address=10.0.50.2/32
add action=accept chain=forward in-interface-list=LAN dst-address=10.0.10.2  dst-port=53 protocol=tcp
add action=accept chain=forward in-interface-list=LAN dst-address=10.0.10.2  dst-port=53 protocol=udp
add action=accept chain=forward in-interface=vlan30-Home out-interface=vlan10-Control  dst-address-list=thirty-2-ten
add action=accept chain=forward in-interface=vlan30-Home out-interface=vlan50-IOT  dst-address-list=thirty-2-fifty
add action=accept chain=forward connection-nat-state=dstnat comment="allow port forwarding"
add action=drop chain=forward comment="drop all else"
/ip firewall nat
add action=masquerade chain=srcnat out-interface-list=WAN
add chain=dstnat in-interface-list=LAN src-address-list=!exclude-pihole protocol=udp dst-port=53 action=dst-nat to-addresses=10.0.10.2
add chain=dstnat in-interface-list=LAN src-address-list=!exclude-pihole protocol=tcp dst-port=53 action=dst-nat to-addresses=10.0.10.2
add action=dst-nat chain=dstnat in-interface-list=WAN dst-port=8888 \
 protocol=tcp to-addresses=10.0.60.2
/tool mac-server
set allowed-interface-list=NONE
/tool mac-server mac-winbox
set allowed-interface-list=MANAGE

Thank you very much @anav for your support.

I’ve applied the following config and PC cannot obtain IP from DHCP on ports: ether2 and ether3 - getting IP 169.254.x.x. On the ether4 and ether5 DHCP works fine.
What could be wrong?

Also its easier to allow a lan subnet or users to access a particular IP or set of IP addresses in another LAN, doing it by ports alone is unknown to me.

Sure, will get back to this.

/interface bridge
add name=onebridge vlan-filtering=yes
/interface vlan
add interface=onebridge name=vlan10_control vlan-id=10
add interface=onebridge name=vlan20-Media vlan-id=20
add interface=onebridge name=vlan30-Home vlan-id=30
add interface=onebridge name=vlan40-Gwifi vlan-id=40
add interface=onebridge name=vlan50-IOT vlan-id=50
add interface=onebridge name=vlan60-DMZ vlan-id=60
add interface=onebridge name=vlan100-Manage vlan-id=100
/interface list
add comment=defconf name=WAN
add comment=defconf name=LAN
add name=Manage
add name=block-printer
/interface wireless security-profiles
set [ find default=yes ] supplicant-identity=MikroTik
/ip pool
add name=dhcp_control ranges=10.0.10.2-10.0.10.254
add name=dhcp_media ranges=10.0.20.2-10.0.20.254
add name=dhcp_home ranges=10.0.30.2-10.0.30.254
add name=dhcp_gwifi ranges=10.0.40.2-10.0.40.254
add name=dhcp_iot ranges=10.0.50.2-10.0.50.254
add name=dhcp_dmz ranges=10.0.60.2-10.0.60.254
add name=dhcp_manage ranges=10.0.100.5-10.0.100.10
/ip dhcp-server
add address-pool=dhcp_media interface=vlan20-Media name=media-server
add address-pool=dhcp_home interface=vlan30-Home name=home-server
add address-pool=dhcp_gwifi interface=vlan40-Gwifi name=gwifi-server
add address-pool=dhcp_iot interface=vlan50-IOT name=iot-server
add address-pool=dhcp_dmz interface=vlan60-DMZ name=dmz-server
add address-pool=dhcp_manage interface=vlan100-Manage name=manage-server
/interface bridge port
add bridge=onebridge comment=defconf frame-types=\
    admit-only-untagged-and-priority-tagged interface=ether2 pvid=10
add bridge=onebridge ingress-filtering=no interface=ether3 pvid=10
add bridge=onebridge frame-types=admit-only-untagged-and-priority-tagged \
    interface=ether4 pvid=20
add bridge=onebridge frame-types=admit-only-untagged-and-priority-tagged \
    interface=ether5 pvid=60
add bridge=onebridge frame-types=admit-only-untagged-and-priority-tagged \
    interface=ether8 pvid=100
/interface bridge vlan
add bridge=onebridge tagged=onebridge untagged=ether2,ether3 vlan-ids=10
add bridge=onebridge tagged=onebridge,ether3 vlan-ids=30,40,50
add bridge=onebridge tagged=onebridge untagged=ether4 vlan-ids=20
add bridge=onebridge tagged=onebridge untagged=ether5 vlan-ids=60
add bridge=onebridge tagged=onebridge untagged=ether8 vlan-ids=100
/interface list member
add interface=vlan20-Media list=LAN
add interface=vlan30-Home list=LAN
add interface=vlan40-Gwifi list=LAN
add interface=vlan50-IOT list=LAN
add interface=vlan60-DMZ list=LAN
add interface=vlan100-Manage list=LAN
add interface=vlan60-DMZ list=block-printer
add interface=vlan40-Gwifi list=block-printer
/ip address
add address=10.0.20.1/24 interface=vlan20-Media network=10.0.20.0
add address=10.0.30.1/24 interface=vlan30-Home network=10.0.30.0
add address=10.0.40.1/24 interface=vlan40-Gwifi network=10.0.40.0
add address=10.0.50.1/24 interface=vlan50-IOT network=10.0.50.0
add address=10.0.60.1/24 interface=vlan60-DMZ network=10.0.60.0
add address=10.0.100.1/24 interface=vlan100-Manage network=10.0.100.0
/ip dhcp-server network
add address=10.0.10.0/24 dns-server=10.0.10.1 gateway=10.0.10.1
add address=10.0.20.0/24 dns-server=10.0.20.1 gateway=10.0.20.1
add address=10.0.30.0/24 dns-server=10.0.30.1 gateway=10.0.30.1
add address=10.0.40.0/24 dns-server=10.0.40.1 gateway=10.0.40.1
add address=10.0.50.0/24 dns-server=1.1.1.1 gateway=10.0.50.1
add address=10.0.60.0/24 dns-server=10.0.60.1 gateway=10.0.60.1
add address=10.0.100.0/24 dns-server=10.0.100.1 gateway=10.0.100.1
/ip dns
set allow-remote-requests=yes servers=8.8.8.8,1.1.1.1

If seems this was left out?

/ip address
add address=10.0.10.1/24 interface=vlan10-Control network=10.0.10.0

Yup, concur that is the problem but its in my config, so just not copied over quite right. That addition should make a slight difference :wink:

Yes, you were right @anav& @Buckeye.
Everything works as expected now - a HUGE THANK YOU @anav for your support!

I’m trying to understand the config and firewall rules, and of course there are multiple questions, but I have to dive into the documentation first, and so far, I would like to ask for the following:

There is a rule to allow ICMP;

add action=accept chain=input comment="defconf: accept ICMP" protocol=icmp

This rule allows ICMP to WAN from the Internet, I changed action to drop, and there is no option to PING WAN port from the Internet, but this blocked ping to the VLAN Gateways. What to do Sir?

What those two rules does mean?

/ip firewall nat
add chain=dstnat in-interface-list=LAN src-address-list=!exclude-pihole protocol=udp dst-port=53 action=dst-nat to-addresses=10.0.10.2
add chain=dstnat in-interface-list=LAN src-address-list=!exclude-pihole protocol=tcp dst-port=53 action=dst-nat to-addresses=10.0.10.2

There is a rule to allow ICMP;
Code: Select all
add action=accept chain=input comment=“defconf: accept ICMP” protocol=icmp
This rule allows ICMP to WAN from the Internet, I changed action to drop, and there is no option to PING WAN port from the Internet, but this blocked ping to the VLAN Gateways. What to do Sir?

The solution is to be more “specific”. After all, also your “vlan gateways” will be “hit” with this rule since they are part of the router and the default rules does not specify interfaces etc.
So DUPLICATE this rule, and on the top one edit the rule and add the incoming WAN/Internet interface! (so be more specific that you want to drop ICMP coming in from Internet
Then edit the rule below, change it to “allow” again (you changed it to “drop”, change that) and you should be able to ping all your VLAN-gateways from internally your LAN.

The other rules with the DNAT is to prevent the DNAT-action to be executed specifically on the packets coming from your PIHOLE itself. (which sits on the “LAN”).
Your PIHOLE should be the only device that can remotely do “dns” from the Internet without being intercepted/dnat’ted to itself :wink:
Any other device on the network (= src-address-list=!exclude-pihole) doing DNS (either UDP or TCP) on 53 will be “intercepted” / NAT’ted and delivered to your Pihole on 10.0.10.2

I do not recommend to block ICMP its valid to allow and it performs useful functions and should be left at is.
Any other advice is questionable and what is the source of that advice??

As to the the second question you will note that to use pi-hole there is a two part strategy,
one is to assign pi hole as the dns-server in the dhcp-server network settings and the second are the 2 rules to ensure that people cannot bypass what you have set in the dns-server!!

As you can see below, all the subnets are assigned to the pihole EXCEPT the IOT subnet which you wanted to use 1.1.1.1.
Furthermore the dns server for the subnet which the pi-hole is in is set to the gateway as we dont want to corral the pi-hole and send it to itself.
So the users of IOT based on this will go to 1.1.1.1 and the users on 10.0.10.0/24 will use the routers IP DNS services 8.8.8.8,1.1.1.1

/ip dhcp-server network
add address=10.0.10.0/24 gateway=10.0.10.1 dns-server=10.0.10.1
add address=10.0.20.0/24 gateway=10.0.20.1 dns-server=Pihole(IP)
add address=10.0.30.0/24 gateway=10.0.30.1 dns-server=Pihole(IP)
add address=10.0.40.0/24 gateway=10.0.40.1 dns-server=Pihole(IP)
add address=10.0.50.0/24 gateway=10.0.50.1 dns-server=1.1.1.1
add address=10.0.60.0/24 gateway=10.0.60.1 dns-server=Pihole(IP)
add address=10.0.100.0/24 gateway=10.0.100.1 dns-server=Pihole(IP)

So in step 2, we have to ensure that
a. users cannot bypass the entries above and
b. we have to then force the OTHER USERS in 10.0.10.0/24 ( but not the pi-hole) to also use the pi-hole.

Hence the identification of the targetted IPs, to exclude from these destination rules ( the pi-hole and the 10.0.50.0 subnet )


Then by the below rules any user from the LAN that needs DNS services ( like browsing ) will be “forced” to the pi-hole address.
/ip firewall nat
add chain=dstnat in-interface-list=LAN src-address-list=!exclude-pihole protocol=udp dst-port=53 action=dst-nat to-addresses=10.0.10.2
add chain=dstnat in-interface-list=LAN src-address-list=!exclude-pihole protocol=tcp dst-port=53 action=dst-nat to-addresses=10.0.10.2.

However we also in the same rule besides saying all users from the LAN, we add the other statement or condition for the rule to be true and the action to be carried out AS.
everybody NOT on the source address list.
ALL USERS ON LAN AND ALL USERS NOT ON SOURCE ADDRESS LIST ----------> if true then carry out the action.

So the two conditions are almost the same, the first one says all users on the LAN, and the second in effect ANY user except those identified on list).


(the ! symbol is not to be used lightly however as in the wrong hands it can create a mess of unintended consequences )

Yikes I noticed on your post of the config you FAILED to copy the ip dhcp-server network properly ???

I started this post, then didn’t finish it until @anav had several new post, so he already found this

Now that you mention it, I just did a comparison of the two configs with winmerge, and there are some other differences as well, and this is also missing from matumatu’s config, and it also looks significant to the problem:

/ip dhcp-server
add address-pool=dhcp-control interface=vlan10-Control name=control-server

It’s easy to stop looking once you find a problem that could cause the problem, even if there are more things that could also cause the same problem.

It appears that there are other difference things removed (wireguard and firewall), but it does look like he fixed an unfinished edit you made in the /ip pool section where some of the 192.168 substrings didn’t get changed to 10.0. and a few syntax fixes (changed admit- to admit-only-)

But I am quite impressed by @anav’s ability to create complete configs without being able to test them, so I am not meaning to throw stones; I didn’t notice them until WinMerge showed the differences. The config @anav posted in post #10 got @matumatu going in the correct direction.

There’s a lot of differing advice on disabling at least icmp echo-requests. This it probably the most common reason people do: Blocking ICMP echo (ping) to make grc.com happy

Does it really enhance security? Probably not as long as you don’t have other problems in your config. The intent is to reduce the knocking on the door. It doesn’t prevent the scanning for open ports, but it probably does reduce the quantity. Similar to not putting your phone number on checks, which used to be recommended, but isn’t any longer. Or publishing your email address on forums. Some people also recommend using “hidden” SSIDs for the same reason. These measures make it marginally less convenient for war drivers.

What is ironic is that some users block icmp echo-requests, but then expose their router’s webfig to the internet, which is a much bigger risk.

I cannot control the ability to copy and paste LOL.
But I do understand the difficulty for a new person having made the mistake to find it easily.

That is why I prefer clean and organized configs that one can then more easily spot errors.
What you stated though is a useful exercise for anyone, to compare configs.

I do this using notepadd++ which has that capability.

In can be found in PLUGINS and the function of COMPARE!
++++++++++++++++++++++++++++++++++++++++++++++++
But I am quite impressed by @anav’s ability to create complete configs without being able to test them,
I have an internal CHR :wink: