Route ICMP ping reponse via different route?

Probably you ask why? So…

I have this network:
S = server on the internet
W = Work router
H = Home router

For security reasons, we allow SSH traffic to our servers only form W router.
So I have VPN between H and W and on H router I have special route, to route all traffic from H to S via W (via VPN).
It works very well, but there is one problem:

For monitoring reasons, I need to ping from S to H.
Ping doesn’t work, coz ICMP ping packet is not routed back to S: due to a specific route, it’s routed back via W (VPN).

My idea is some setup, where I can modify route only for specific traffic, like: when ICMP ping packed is from S, then not route it via W but send in back directly via default gateway.
I tried to play with Firewall, Mangle, Routes… but without success.
Any clue how to solve this?

Thanx a lot!

And, to be more specific, my idea - not sure if right - is:

  • Mark incomming ICMP packed by route-mark
  • Add a new route for marked packets to send via WAN (not VPN)

Coz it’s ping, I’m not sure if I need to mark incomming packets, or outgoing packets and if the incomming and outgoing packed is the same, or if those are two packes, and if I mark incomming ICMP packed, if it’s this routing mark preserved in returning - outgoing - packet :slight_smile:

I think I understand what you are trying to do, but without seeing all the necessary info, it makes it difficult to make suggestions, i.e. what these special and specific routes looks like?

Home Router:

#      DST-ADDRESS        PREF-SRC        GATEWAY            DISTANCE
1 ADS  0.0.0.0/0                          my-home-isp-gateway       1
3 A S  ;;; Office network
       10.1.1.0/24                        l2tp-out-office           1
4 ADC  10.1.2.0/24        10.1.2.1        bridge                    0
11 ADC  10.1.99.1/32      10.1.99.2       l2tp-out-office           0
28 A S  ;;; production server via VPN
       1.2.3.4                            l2tp-out-office           1

This is my working config on the home router.
So I’m routing traffic to prodcution server 1.2.3.4 not via default gateway, but via VPN to office network.
It works well, but when I ping from 1.2.3.4 via WAN (not thru VPN) it fail, coz the ICMP packed is received on Mikrotik, but then routed not to WAN back, but via the VPN

After reading this doc: https://wiki.mikrotik.com/wiki/Manual:IP/Firewall/Mangle#Marking_packets
I found it’s better to work with connection-marking then packet-marking
Using mangle, I’m able to mark the connection succesfully:

1 X  ;;; Ping from 1.2.3.4
     chain=prerouting action=mark-connection new-connection-mark=server-conn passthrough=no protocol=icmp src-address=1.2.3.4 in-interface=ether1-wan

But cannot find out, how to porce returing ICMP packets to be routed thru WAN inerface…

Difficult to follow you and think there is a language barrier, in short (As there can be NATing, etc involved here) I suspect the following is happening:

  1. You ping server 1.2.3.4 (Private IP) from home it works, reason is you have VPN to office with a route to route all traffic to this subnet via L2TP VPN
  2. You try to ping device at home on Private IP from server 1.2.3.4 (Private IP) but does not work, I suspect the reason is that you do not have a route on office router back to your home subnet, so the packet is going out via the WAN / Internet instead of VPN and internet does not know what to do with Private IP’s, so drops the packet

Normally, the solution is connection marking. What you need to do is to choose an outgoing route for an (icmp ping) response depending on the in-interface of the (icmp ping) request it responds to.

A connection mark is assigned to all packets of a connection, regardless the direction.

So:


/ip firewall mangle add chain=prerouting protocol=icmp in-interface=your-WAN-interface-name connection-state=new action=mark-connection new-connection-mark=from-wan

connection-marks each first request of a ping sequence incoming from the IP address of the server with a connection mark “from-wan”.


/ip firewall mangle add chain=output connection-mark=from-wan action=mark-routing new-routing-mark=bypass-vpn

assigns a routing mark “bypass-vpn” to packets sent by the H Mikrotik itself (not forwarded by it) if they belong to a connection marked “from-wan”.


/ip route add dst.address=0.0.0.0/0 gateway=my-home-isp-gateway routing-mark=bypass-vpn

provides a route for route-marked packets via the normal WAN gateway regardless their destination address.

It is actually possible do it in a simpler way, just route-mark icmp ping response (and no other) packets towards

dst-address=S.S.S.S

with

new-routing-mark=bypass-vpn

, but you still need the last two steps, the specific route for the routing mark and the marking rule in

chain=output

of

/ip firewall mangle

, and it will only work until the IP address of the server changes. Use of connection-mark makes sure that what came in via WAN will be responded via WAN and what came in via the tunnel will be responded via the tunnel regardless particular IP addresses.

PS: only after CZFan has mentioned the language barrier I’ve realized there is none in my case and that the OP’s nickname has a very special meaning :slight_smile:

sindy, thank You very much for explaining the principle. And it’s finally working NOW!

But just for informtaion, there was a atrouble with routing, but I fixed. You suggested this:

/ip route add dst.address=0.0.0.0/0 gateway=my-home-isp-gateway routing-mark=bypass-vpn

but the trouble was, that there is another route, lower in the routing table:

28 A S  ;;;Traffic to server via VPN
        server-ip-address/32                  l2tp-out          1

The trouble is (what I know), that this specific rote have a priority before 0.0.0.0/.0 route, so I modified the rout for returning ICMP packets to this:

/ip route add dst.address=server-ip-address/32 gateway=my-home-isp-gateway routing-mark=bypass-vpn

And now it works like a charm!

And thanx also to CZFan, sure, wan can speak Czech, but unfortunatelly, it’s (still) not the Word’s default language, bit it will come one day!
Thanx guys!!!

So no, my mistake, I was pinging some other hostname by mistake, I’ll continue today evening :slight_smile:
Anyway thanx a lot!

Not exactly true. I know you’ve already found yourself that the reason why it didn’t work as expected was different, but just to clarify: the route with the longest ****

dst-address

prefix is always chosen among all matching routes, that’s true, but only within the same routing table (routing mark, it is almost the same).

Wow, it’s finally working. The trouble was, that in an route for outgoing marked packed I used for gateway interface name (doesn’t work) instead of inerface’s ip address (which works).

Again, there is more to it. In RouterOS, you can only use interface names as routes’ gateways in case of point-to-point interfaces such as tunnels, because the implicit “address” of the gateway is simply “the other end of the tunnel”. For point-to-multipoint (bus-like) interfaces such as Ethernet, you have to configure an address of a particular device on the bus which can handle the packets as a gateway.

On other systems, interface name can be indicated as a gateway even on point-to-multipoint connections, thanks to an icmp router solicitation mechanism. All devices with routing capabilities advertise the fact that they are routers using an icmp broadcast message every other while, and when a device with interface name configured as a gateway needs to route a packet outside the subnet via that interface, it sends it to any of these routers. The router then routes the packet and if its outgoing interface for that packet is the same like the incoming one, it forwards the packet anyway but it also informs the sender that next time it should send it directly to that other device. And the sender is supposed to cache this instruction and follow it the next time it sends a packet to the same destination.

sindy, thank You for very sophisticated and detailed explanation! :slight_smile: