This is a common issue caused by the inability to do a Hairpin NAT. Most cheap home routers handle this simply by turning on port forwarding. However, higher end routers actually need separate rules to address the issue.
Your regular NAT rules only work from outside your network. If you try to connect from inside your network there is a NAT issue.
Consider this...
- You have
Server A on your local network with IP 10.10.10.10.
- You have
Computer A on your local network with IP 10.10.10.20.
- You have
Router A with a LAN IP of 10.10.10.1 and a WAN IP of 11.11.11.11.
- You have
Computer B outside your network with IP 12.12.12.12.
- You have
port 22 forwarded from your WAN IP to Server A.
From outside your network the traffic looks like this:
Computer B tries to connect to Server A:
Source IP: 12.12.12.12 Src Port: 12345
Destination IP: 11.11.11.11 Dest Port: 22
Router A NATs the packet and sends it on to Server A:
Source IP: 12.12.12.12 Src Port: 12345
Destination IP: 10.10.10.10 Dest Port: 22
Server A responds to Computer B:
Source IP: 10.10.10.10 Src Port: 22
Destination IP: 12.12.12.12 Dest Port: 12345
Router A NATs the packet and sends it on to Computer B:
Source IP: 11.11.11.11 Src Port: 22
Destination IP: 12.12.12.12 Dest Port: 12345
Everything works as intended. Now, consider the same scenario but from inside your network:
Computer A tries to connect to Server A:
Source IP: 10.10.10.20 Src Port: 12345
Destination IP: 11.11.11.11 Dest Port: 22
Router A NATs the packet and sends it on to Server A:
Source IP: 10.10.10.20 Src Port: 12345
Destination IP: 10.10.10.10 Dest Port: 22
Server A responds to Computer A:
Source IP: 10.10.10.10 Src Port: 22
Destination IP: 10.10.10.20 Dest Port: 12345
The source IP is on the same subnet as the destination IP. Server A does not send the packet back to the router, it sends it directly to Computer A. Computer A drops the packet, because it came from 10.10.10.10 and it sent the original packet to 11.11.11.11. It expects the packet to return from 11.11.11.11.
To resolve the issue, you must create a second, more specific NAT rule to match traffic originating from inside your network. It will come after your original NAT rule. You'll need to do a Source NAT that looks like this:
srcnat src-address=10.10.10.0/24 dst-address=10.10.10.10 dst-port=22 out-interface=LAN action=masquerade
Now, lets look at this again:
Computer A tries to connect to Server A:
Source IP: 10.10.10.20 Src Port: 12345
Destination IP: 11.11.11.11 Dest Port: 22
Router A NATs the packet and sends it on to Server A:
Source IP: 10.10.10.1 Src Port: 12345
Destination IP: 10.10.10.10 Dest Port: 22
Server A responds to Computer A:
Source IP: 10.10.10.10 Src Port: 22
Destination IP: 10.10.10.1 Dest Port: 12345
Router A NATs the packet and sends it on to Computer A:
Source IP: 11.11.11.11 Src Port: 22
Destination IP: 10.10.10.20 Dest Port: 12345
Everything works as intended.
How you implement this second NAT rule is dependent on your router hardware and software. Your mileage may vary.