How to Block Websites on MikroTik with Address List

Aisyah Aldina

No entry road sign illustration for a guide on how to block websites on MikroTik

Hi everyone, in this post I want to show you how to block websites on MikroTik. The need to block websites comes up a lot in offices, schools, and internet cafes, for example to shut out social media during working hours. The problem is that almost every website now uses HTTPS and a CDN, so old methods such as web proxy or Layer7 are no longer effective.

In this article I try out three methods that still work on RouterOS 7.25.2: an address list with domain names, DNS static NXDOMAIN, and tls-host. I tested each method from a client computer on the LAN with curl, along with its strengths and weaknesses. The firewall used here continues from the basic MikroTik firewall for security article.

Before Blocking

Test access from the client

Before blocking, reddit.com and example.com answer HTTP 200 from the client
curl -sI -m 8 https://www.reddit.com | head -1
curl -sI -m 8 https://example.com | head -1

Both websites answer with HTTP/2 200, which means they can be opened. Example.com is used as a comparison to make sure the block does not affect other websites.

Method 1: Address List with Domain Names

Add the domain to an address list

Address list containing the domain name www.reddit.com and dynamic IPs resolved by the router
/ip firewall address-list add list=situs-blokir address=www.reddit.com comment="blokir reddit"
/ip firewall address-list print where list=situs-blokir

In RouterOS 7, an address list can hold domain names. The router looks up the IP addresses of that domain by itself and adds them as dynamic entries with the D flag. In this lab, www.reddit.com resolved to four IP addresses. The router also updates these IP addresses automatically based on the DNS TTL. The list name situs-blokir means blocked sites, and the comments are in Indonesian to match the screenshots.

Create the reject rule

Forward reject rule with dst-address-list situs-blokir above the accept ongoing connections rule
/ip firewall filter add chain=forward action=reject reject-with=icmp-network-unreachable dst-address-list=situs-blokir in-interface-list=LAN comment="blokir situs dari address list" place-before=[find comment="forward: terima koneksi lanjutan"]

The rule is placed above the rule that accepts ongoing connections, so connections that are already running get cut off as well. I used reject so the client is refused right away, instead of waiting for a timeout as it would with drop.

Address list test result

Reddit fails with Couldn't connect to server while example.com still returns HTTP 200

Reddit fails immediately with the message Couldn’t connect to server, while example.com still returns HTTP/2 200.

The weakness of this method is that many large websites use a CDN whose IP addresses are shared with other websites. The Reddit IP addresses in this lab belong to the Fastly network, so other websites that happen to use the same IP addresses can get blocked too.

Method 2: DNS Static NXDOMAIN

Create an NXDOMAIN DNS entry

DNS static entry for facebook.com with type NXDOMAIN and match-subdomain
/ip dns static add name=facebook.com type=NXDOMAIN match-subdomain=yes comment="blokir facebook via DNS"
/ip dns cache flush

The router will answer facebook.com and all of its subdomains, such as www.facebook.com, with NXDOMAIN, which means the domain is treated as if it does not exist. This method is not affected by the CDN because what gets blocked is the name. You can read more about the router DNS in the MikroTik DNS server article.

The loophole: the client uses another DNS

Through the router DNS facebook returns NXDOMAIN, but a direct query to 8.8.8.8 still gets through
resolvectl flush-caches
nslookup www.facebook.com
nslookup www.facebook.com 8.8.8.8

Through the router DNS, www.facebook.com returns NXDOMAIN. But when the client asks 8.8.8.8 directly, it still gets the Facebook address. This means users only need to change the DNS on their computer to get around the block.

Force clients to use the router DNS

NAT redirect rules for UDP and TCP port 53 so clients must use the router DNS
/ip firewall nat add chain=dstnat in-interface-list=LAN protocol=udp dst-port=53 action=redirect to-ports=53 comment="paksa DNS ke router udp"
/ip firewall nat add chain=dstnat in-interface-list=LAN protocol=tcp dst-port=53 action=redirect to-ports=53 comment="paksa DNS ke router tcp"

Every DNS query from the LAN to any server is redirected to the router DNS.

Other DNS servers are blocked too

After the redirect, a query to 8.8.8.8 also returns NXDOMAIN and curl fails to resolve

Now even a query to 8.8.8.8 gets NXDOMAIN, because it is actually the router that answers it, and curl fails with Could not resolve host.

My experience: While trying the DNS method, I first thought the block was not working because the browser and systemd-resolved on Linux were still holding the old address in their cache. After clearing the client cache with resolvectl flush-caches and the router cache with /ip dns cache flush, the result matched right away. On Windows, use ipconfig /flushdns.

Method 3: tls-host for HTTPS

Create the tls-host rule

Reject rule with tls-host tiktok.com and a drop rule for UDP 443 to block QUIC
/ip firewall filter add chain=forward action=reject reject-with=tcp-reset protocol=tcp dst-port=443 tls-host=*tiktok.com in-interface-list=LAN comment="blokir tiktok via tls-host" place-before=[find comment="forward: terima koneksi lanjutan"]
/ip firewall filter add chain=forward action=drop protocol=udp dst-port=443 in-interface-list=LAN comment="blokir QUIC" place-before=[find comment="forward: terima koneksi lanjutan"]

When a browser opens an HTTPS website, the site name is sent unencrypted at the start of the TLS connection (SNI). Tls-host matches this name, and the asterisk at the front covers all subdomains. The second rule blocks QUIC, or UDP port 443, because modern browsers can use HTTP/3 over UDP, which tls-host cannot read.

tls-host test result

The tiktok domain still resolves, but the HTTPS connection is reset by the router

The domain www.tiktok.com still resolves to an Akamai IP address, but as soon as the HTTPS connection starts, the router sends a reset and curl shows Connection reset by peer.

The weakness is that tls-host does not work if the browser uses Encrypted Client Hello, which hides the SNI. This rule also inspects every HTTPS connection, so it puts more load on the router CPU when the list gets long.

Check the Counters of All Rules

See how many packets were blocked

Counters of the address list, tls-host, and DNS redirect rules increasing during the test
/ip firewall filter print stats where comment~"blokir|QUIC"
/ip firewall nat print stats where comment~"paksa DNS"

The address list rule rejected 8 packets, the tls-host rule 1 packet, and the DNS redirect rule has already redirected 9 queries. The QUIC counter is still at 0 because curl does not use HTTP/3, but browsers such as Chrome will use it.

Which Method Should You Use

Address list : easy, but can also block other sites on the same CDN
DNS NXDOMAIN : light and clean, must be paired with a DNS redirect
tls-host     : precise for HTTPS, must be paired with a QUIC block
Layer7       : not recommended, heavy and cannot read HTTPS

For an office or school network, combining DNS NXDOMAIN with a DNS redirect is the lightest option. Add tls-host for websites that keep slipping through.

Common Problems and How to Fix Them

The website still opens after being blocked

Old connections are still stored or the DNS cache has not been cleared. Remove the connections in IP, Firewall, Connections, clear the DNS cache on the router and the client, then try again.

The browser uses DNS over HTTPS

Firefox and Chrome can use DoH, which does not go through port 53. Turn off DoH in the browser, or block popular DoH servers with tls-host, for example dns.google and cloudflare-dns.com.

Other websites get blocked too

That is the side effect of an address list on shared CDN IP addresses. Switch to the DNS or tls-host method for that website.

The block does not apply to IPv6

If your network uses IPv6, create similar rules in IPv6 Firewall. The DNS NXDOMAIN method still works for IPv4 and IPv6 at the same time.

At this point you have three tested ways to block websites on MikroTik, along with how to close their loopholes. For the opposite case, when you want to open access from the internet to a server on the LAN, see MikroTik port forwarding to a local server. If you have a website that is hard to block, tell me about it in the comments.

Leave a Comment