I am setting up an email server and it is reachable on port 25 at mx.example.tld when I am coming from outside the LAN.
All good so far.
But when I try to connect to it from LAN the connection gets refused because it originates from LAN and wants to get in via WAN.
already listening on all interfaces. I have worked around the issue for now using hostnames functionality in openwrt. returning the local lan ip. I was hoping for a solution that does not need that
NAT loopback (i.e. the OpenWrt setting) only works for the IP in question (i.e. testing the server from the server's IP).
You will have to:
Make a local DNS entry for mx.example.tld for the LAN IP as @frollic noted; or
Make a firewall port forward that places the packet into the originating zone, this will cause the packet to forward using the normal rules for the zone
I advise the DNS method
# in /etc/config/dhcp
config domain
option ip '192.168.1.xxx'
option name 'mx.example.tld'
# in /etc/config/firewall
config redirect
option target 'DNAT'
option src 'wan'
option proto 'tcp'
option src_dport '25'
option dest_port '25'
option src_ip '192.168.1.0/24'
option name 'REDIRECT_SMTP_LAN'
option dest_ip '192.186.1.xxx'
option dest 'lan'