I'm new to Mikrotik environment, and I need some help for the following scenario:
-
I have an ADSL router (main internet connection) with IP range of
192.168.1.0/24
, connected to Ethernet 1 of my Mikrotik router (WAN Port) -
I have another ADSL router (VPN connection to connect to main branch) with IP range of
172.200.1.0/24
, connected to Ethernet 2 of my Mikrotik router -
I have WiFi enabled Mikrotik as Ap bridge with IP range of
192.168.88.0/24
(everyone connect to this router using WiFi and physical connection)
What I want to do is as follows:
-
When people want to access the Internet, the Mikrotik router should route packets automatically to Ethernet 1 interface (first ADSL).
-
If people want to go to certain destinations (e.g.
221.35.12.x
) their packet has to be routed to Ethernet 2, which is the Second ADSL to connect to main branch.
Additional information
The gateway for first ADSL is 192.168.1.1
, and for second one is 172.200.1.17
.
So far, I have managed to access the gateway of the second ADSL, but when I ping the actual destination address of 221.35.12.x
, it returns unreachable
and when I tracert
that address, it shows the packet goes to 192.168.88.1
and from there drops.
Can anyone help for the above scenario with a complete solution?
Best Answer
Preliminary setup: You will need to set up the two WAN connections. Assume
IFC1
to be the first WAN port (e.g.ether1
) interface andIFC2
to be the second WAN port (e.g.ether5
).Some of this may already be configured. If using a different type of WAN connection such as PPPoE then adjust accordingly.
When the DHCP client connects, routes should be added, below is an example.
If you don't see two
0.0.0.0/0
routes with the correct gateways, you can create them as static routes (/ip route add ...
). This is basic Mikrotik stuff beyond the scope of this answer.Differentiating between the two WAN connections will be done using policy routing. On each default WAN route set a routing mark.
The values
unid2rm
andunid3rm
are arbitrary text strings. This means the Mikrotik will send packets marked with a given routing mark through the given gateway IP.Second, configure the firewall. Look at the
FORWARD
chain. The goal here is to exclude marked connections for the secondary (non-default) WAN from going through fasttrack.Change the numbers 8 and 9 so that the rules are positioned at the start of your
FORWARD
chain.Now in the
PREROUTING
chain, mark the incoming connections. If you're only steering outbound connections, you can skip this.The next step involves the
MANGLE
table and is where the magic happens for you. Here you mark a connection based on the criteria you set.This is saying "when there is a connection to
221.35.12.5
which is not already marked, mark it with connection markunid2cm
". You can set it based on source IP, MAC, etc. and add as many of these as needed. Then the companion is:Note the difference between
unid2rm
andunid2cm
. These rules take packets from a marked connection and give them a routing mark. The routing mark is then used in Mikrotik's route table as mentioned earlier.Every setup is a bit different, so you might need to play around to make it work for you.
Added: Mikrotik usually sets up NAT automatically on the
WAN
interface list. The very first step at the top of the answer ensures that both interfaces are in the list.