The firewalld
in Linux is quite flexible and quite number of task can be achieve with just a single line of code. It just a matter of to get the parameter correctly.
Just to overcome the laziness of application team to change port, lets us port forwarding instead.
# firewall-cmd --add-forward-port='port=<port>:proto=tcp:toport=<toPort>:toaddr=<toAddress>'
Explanation
code
- Flagging
firewall-cmd
that this is a port forwarding rule,--add-forward-port=''
- Define protocol and port number that hit the host,
port=<port>:proto=tcp
- Define destination port and address to be forwarded,
toport=<toPort>:toaddr=<toAddress>
Note: Above command is to get the port forwarding work immediately after hitting enter. No need to reload service nor server reboot. The catch is, this is non-persistent configuration and as its name implies, the configuration will revert back once the OS being rebooted.