I have a CentOS 7 box with 2 NICs acting as a gateway; one NIC is connected to the internet while the other NIC is connected to our LAN.
The first NIC belongs to the 'external' zone of firewalld, it has masquerading on and is set to forward port 22, 80 and 443 to those boxes inside the internal network that manage SSH and the web servers; let's say that, from the internet, the box appears as "example.com" at address "1.2.3.4" while its name in the LAN is "gateway.lan" with address "192.168.1.1".
Everything works, with a significant caveat; since we want to be able to connect via SSH using the internet name of the box (ssh example.com) also from within the LAN (where the SSH box is named "server.lan" and has address 192.168.1.10), the only way to make this work seems to be setting a rule in firewalld's 'internal' zone forwarding all accesses to port 22 of "1.2.3.4" back to port 22 of the SSH box:
internal (active)
target: default
icmp-block-inversion: no
interfaces: XXXXXX
sources:
services: dns
ports:
protocols:
masquerade: yes
forward-ports:
source-ports:
icmp-blocks:
rich rules:
rule family="ipv4" destination address="1.2.3.4" forward-port port="22" protocol="tcp" to-port="22" to-addr="192.168.1.10"
The rule alone does not work unless masquerading is on for the 'internal' zone; unfortunately, this also obviously causes the external IPs that hammer that box trying to brute-force a root password to appear as coming from "192.168.1.1" (the "gateway.lan" address) in the logs of "server.lan", which makes it impossible to use Fail2Ban on the "server.lan" box to hamper the thousands of daily attempted accesses.
What am I doing wrong? I think enabling masquerading on the "internal" zone is conceptually wrong but I could find no other way the make the firewalld rule work. I have no qualms in keeping the masquerading on but I'd like to know how Fail2Ban may be then made to work when behind a gateway...
Any advice to any other way to make a configuration like this work as I'm expecting?