I have issue with SSH going out (tcp 22) to server outside my network. I use ZeroTier VPN (added to LAN interface list) and this NAT line
Chain dstnat, action dst-nat, in interface list LAN, dst port 22 (connect to home server from VPN)
But when I try to connect from internal network to ssh outside my network, this dst-nat redirect it to local port.
Any ideas why is it going through dstnat chain when I expect srcnat? I solved it by adding in interface VPN but I would like to understand reason behind this behaviour.
Can you post your config and try to explain in simpler terms what you are trying to do? I think you just want to redirect any outbound ssh traffic somewhere? If that’s the case, it’s a destination NAT you need, redirect back to the MikroTik or dst-nat to other IP. No source NAT involved unless you are intentionally sending it up a VPN tunnel but you are not clear what you are trying to do.
I have small server in my network accessible from both inside and outside on port 22.
When I connect from computer in the same network to another server outside my network with the same port (22), it is forwarded to the server in my LAN as both of them use port 22 and I have rule to forward port 22.
I expected NAT rule with action dst-nat not to catch any connection from my local network unless it is changed to src-nat. So I guess connections outside goes thru both src-nat and then dst-nat?
SRC-NAT and DST-NAT are very distinct operations, they happen at very different times (dst-nat is pretty early in packet processing, before firewall, and src-nat happens pretty late, after firewall) and both can affect same packet/connection … if there are src-nat and dst-nat rules which match against same packet/connection. Which means that one has to be careful when constructing rules, one needs to add appropriate matching criteria so that rules only apply to packets needing it.
Which means that connection going outside should only hit src-nat and if it’s not, then dst-nat is “too greedy”. OTOH connection being directed at internal server should hilt only dst-nat and specific src-nat (see bellow), it should not hit the default “masquerade traffic going out” rule …
When looking at your diagram I’m guessing you’ll need hair-pin NAT for those SSH connections (so both dst-nat and src-nat for elligible connections).