How to Configure MikroTik Static Routes Between Networks

Aisyah Aldina

Illustration of a direction signpost for a guide on how to configure MikroTik static routes between networks

Hi everyone, in this post I want to show you how to configure MikroTik static routes between networks. A static route is a path you write into the routing table by hand, and it basically says: to reach network X, send the packet to router Y. This approach works well for small to medium networks, such as a head office and a branch office, or two floors of a building where each floor has its own router.

This article continues MikroTik basic configuration with Winbox for beginners and how to create a bridge on MikroTik. I am using two MikroTik CHR routers running RouterOS 7.25.2 in VirtualBox, each with a client on its own LAN. Many static routing tutorials out there still use RouterOS 6 and stop right after adding the route. Here I take it all the way through, including the most common mistake of forgetting the return route, proving it with the sniffer, and then testing check-gateway by pulling the link cable.

Static Routing Lab Topology

Plan the addressing for each network

MikroTik static routing lab topology with R1, R2, the 10.10.10.0/30 link, and two LANs on different subnets

There are three networks, each on a different subnet.

LAN R1  : 192.168.56.0/24  gateway 192.168.56.10 (bridge1 on R1)
Link    : 10.10.10.0/30    R1 ether4 = 10.10.10.1, R2 ether1 = 10.10.10.2
LAN R2  : 192.168.20.0/24  gateway 192.168.20.1 (ether2 on R2)

R1 is the router we have been using since the start of this series, and it connects to the internet through ether1. R2 is a new router. The link between the routers uses a /30 because it only needs two IP addresses, following the example in the MikroTik documentation. Make sure the LAN subnets on the two sides are different, because routing cannot tell apart two networks whose addresses overlap.

Set Up IP Addresses on Both Routers

Check the link interface on R1

Interface ether4 on router R1 used as the link to router R2

Click Interfaces. In this lab I added a fourth adapter to the R1 VM, so ether4 shows up. The ether4 cable is connected to ether1 on R2.

Assign the link IP on R1

Assigning IP 10.10.10.1/30 to ether4 as the link to R2

Click IP, then Addresses, and click New. Set Comment to link ke R2, Address to 10.10.10.1/30, and Interface to ether4. Click OK.

/ip address add address=10.10.10.1/30 interface=ether4 comment="link ke R2"

Basic configuration of R2

Basic configuration of router R2 from the terminal with link IP 10.10.10.2/30 and LAN 192.168.20.1/24

R2 is still a clean install, so I configured it from the terminal. The important parts are the link IP 10.10.10.2/30 on ether1 and the LAN IP 192.168.20.1/24 on ether2, plus a DHCP server so clients on the R2 LAN get an IP automatically.

/system identity set name=MikroTik-R2
/ip dhcp-client remove [find]
/ip address add address=10.10.10.2/30 interface=ether1 comment=link-ke-R1
/ip address add address=192.168.20.1/24 interface=ether2 comment=LAN-R2
/ip pool add name=pool-lan2 ranges=192.168.20.100-192.168.20.200
/ip dhcp-server add name=dhcp-lan2 interface=ether2 address-pool=pool-lan2 lease-time=30m
/ip dhcp-server network add address=192.168.20.0/24 gateway=192.168.20.1 dns-server=192.168.20.1
/ip dns set servers=8.8.8.8,1.1.1.1 allow-remote-requests=yes

I ran the dhcp-client remove line because a fresh CHR automatically adds a DHCP client on ether1, while ether1 on R2 does not go to an ISP but to R1. The DHCP server is explained in the article on how to set up a MikroTik DHCP server.

The Situation Before Any Static Route

Test ping from R1

Ping from R1 to 10.10.10.2 succeeds but ping to 192.168.20.1 times out
/ping 10.10.10.2 count=3; /ping 192.168.20.1 count=3

The ping to 10.10.10.2 works because that address is on the same subnet as ether4. The ping to 192.168.20.1 times out because R1 has no idea that the 192.168.20.0/24 network sits behind R2.

Look at the R1 routing table

The R1 routing table has no path to 192.168.20.0/24 yet
/ip route print

There are only DAc (dynamic, active, connected) routes for the directly attached networks, plus a DAd default route from the ISP DHCP client. A packet to 192.168.20.1 matches no route other than 0.0.0.0/0, so it gets sent to 10.0.2.2, in other words out to the internet, and of course it never arrives.

Adding a Static Route on R1

Create a new route in WinBox

Adding a static route to 192.168.20.0/24 with gateway 10.10.10.2 in WinBox

Click IP, then Routes, and click New. Set Comment to ke LAN R2, Dst. Address to 192.168.20.0/24, and Gateway to 10.10.10.2. Leave Distance empty, since the default for a static route is 1. Click OK.

/ip route add dst-address=192.168.20.0/24 gateway=10.10.10.2 comment="ke LAN R2"

Fill in Gateway with the IP of the neighboring router, not an interface name. The MikroTik documentation recommends using an IP as the gateway so features like check-gateway can work, and that gateway must be on a directly connected network.

Check that the route is active

The static route to the R2 LAN is active with the AS flags

The route to 192.168.20.0/24 appears with the AS flags. A means active, or in use, and S means static. Other flags you will often see in RouterOS 7 are D for dynamic, C for connected, d for DHCP, I for inactive, and U, which means the gateway is unreachable.

The Most Common Mistake: Forgetting the Return Route

The R1 LAN client still fails

R1 LAN client ping to 192.168.20.1 still fails with 100 percent packet loss
ping -c 3 192.168.20.1

From the client on the R1 LAN with the IP 192.168.56.101, the ping to 192.168.20.1 still shows 100% packet loss, even though the route on R1 is already active.

Prove it with the sniffer on R2

The sniffer on R2 only captures incoming packets from 192.168.56.101 because there is no return route

While the client keeps pinging, I ran this command on R2.

/ip route print; /tool sniffer quick interface=ether1 ip-protocol=icmp duration=4

The R2 routing table only contains two connected networks. The sniffer captures ICMP packets coming in from 192.168.56.101 with the incoming arrow, but not a single reply goes out. The packets do arrive, R2 just does not know which way to send the reply because 192.168.56.0/24 is not in its table.

My experience: Before looking at the sniffer, I suspected the R1 firewall was blocking something. It turned out R1 was forwarding the packets correctly, and the problem was purely on the R2 side. This is why static routing always has to be thought of in both directions: every router needs to know the way there and the way back. Interestingly, a ping from R1 itself to 192.168.20.1 already worked, because its source is 10.10.10.1, which R2 knows as a connected network. So do not test only from the router, test from the client as well.

Add the return route on R2

Adding the return route 192.168.56.0/24 via 10.10.10.1 on router R2
/ip route add dst-address=192.168.56.0/24 gateway=10.10.10.1 comment=ke-LAN-R1
/ip route print

The route to 192.168.56.0/24 via 10.10.10.1 immediately gets the As flags.

Testing Connectivity Between Networks

Ping from the R1 LAN to the R2 LAN

R1 LAN client successfully pings the router and client on the R2 LAN with TTL 63 and 62
ping -c 3 192.168.20.1; ping -c 3 192.168.20.200

The R1 LAN client can now ping the R2 router and the client on the R2 LAN. Pay attention to the TTL. The reply from 192.168.20.1 has a value of 63 and the reply from the client 192.168.20.200 has a value of 62. Linux starts with a TTL of 64 and it drops by one at every router, so these numbers prove the packets really did pass through one and two routers.

Tracepath from the R2 LAN

Tracepath from the R2 LAN to the R1 LAN through 192.168.20.1 and 10.10.10.1, internet still Net Unreachable
tracepath -n 192.168.56.101; ping -c 3 8.8.8.8

The path from the R2 LAN client is easy to read: 192.168.20.1, then 10.10.10.1, then it reaches 192.168.56.101 in 3 hops. On Windows, use the tracert command. However, the ping to 8.8.8.8 gets a Destination Net Unreachable answer from 192.168.20.1, because R2 has no route to the internet yet.

Add a default route on R2

Adding the default route 0.0.0.0/0 via 10.10.10.1 on router R2
/ip route add dst-address=0.0.0.0/0 gateway=10.10.10.1 comment=default-ke-R1
/ip route print

The default route 0.0.0.0/0 means every destination that is not in the table gets sent to R1. With this default route, the route to 192.168.56.0/24 is technically already covered, but I keep it anyway so the routing table stays easy to read.

The R2 LAN client can reach the internet

R2 LAN client successfully pings google.com after the default route is added
ping -c 3 google.com

The R2 LAN client successfully pings google.com. There is no need to add NAT on R1, because the masquerade rule from the NAT article uses out-interface-list=WAN. Packets from 192.168.20.0/24 leaving through ether1 are NATed automatically, while traffic between the LANs over ether4 is not NATed, so the real client IP stays visible, just like in the sniffer earlier.

Check Gateway to Detect a Broken Link

The route goes inactive when the link drops

With check-gateway ping, the route becomes inactive when the link to R2 goes down
/ip route set [find comment="ke LAN R2"] check-gateway=ping

With check-gateway=ping, R1 pings 10.10.10.2 every 10 seconds. I then unplugged the virtual cable on ether1 of R2. When I checked 30 seconds later, the route had already changed to Is, or inactive, and WinBox showed the USI flags. This is useful if you have a backup route with a higher distance, because the backup route is used automatically when the main route becomes inactive.

The route comes back and the config is exported

The route is active again after the link reconnects, along with the static route export output
/ip route print where dst-address=192.168.20.0/24
/ip route export where static

After the cable was plugged back in, the route returned to As. The export command shows every static route as a command, which is handy for documentation or for copying to another router.

Common Problems and How to Fix Them

Ping from the router works but ping from the client fails

This is almost always because the return route is missing on the destination router. Check the routing tables on both routers with /ip route print.

The route has the U flag or is not active

The gateway cannot be reached. Make sure the gateway IP is on the same subnet as one of the router interfaces and that the subnet mask is the same on both ends of the link, for example /30 on both.

The client can ping the router but not the client on the other side

Check the forward chain of the firewall on both routers and the firewall on the client computer. Windows Defender Firewall often blocks incoming ping, especially on the Public network profile, so allow ICMP echo request while testing.

The real client IP is not visible on the far router

The masquerade rule is too broad, for example it has no out-interface. Limit masquerade to the WAN interface or WAN interface list only.

When to move to dynamic routing

Once you have many routers and the paths change often, writing routes one by one becomes tedious and error prone. That is where OSPF is a better fit, and it will be covered in its own article.

That is it, two LANs on different subnets are now connected through static routes on MikroTik, complete with the return route, a default route, and check-gateway. In the next article we will cover how to back up and restore a MikroTik configuration. If you have a topology with more than two routers and you are not sure how to lay out the routes, feel free to ask in the comments below.

Leave a Comment