3.7.13.5.13. Configure Port Forwarding using the CLI
To forward inbound network packets from one port to an alternative port or address, first enable IP address masquerading for a zone, for example external, by entering the following command as root:
~]# firewall-cmd --zone=external --add-masquerade
To forward packets to a local port, that is to say to a port on the same system, enter the following command as root:
~]# firewall-cmd --zone=external --add-forward-port=port=22:proto=tcp:toport=3753
In this example, the packets intended for port 22 are now forwarded to port 3753. The original destination port is specified with the
port option. This option can be a port, or port range, together with a protocol. The protocol, if specified, must be one of either
tcp or
udp. The new local port, the port or range of ports to which the traffic is being forwarded to, is specified with the
toport option. To make this setting permanent, add the
--permanent option and reload the firewall.
To forward packets to another
IPv4 address, usually an internal address, without changing the destination port, enter the following command as root:
~]# firewall-cmd --zone=external --add-forward-port=port=22:proto=tcp:toaddr=192.0.2.55
In this example, the packets intended for port 22 are now forwarded to the same port at the address given with the
toaddr. The original destination port is specified with the
port. This option can be a port, or port range, together with a protocol. The protocol, if specified, must be one of either
tcp or
udp. The new destination port, the port or range of ports to which the traffic is being forwarded to, is specified with the
toport. To make this setting permanent, add the
--permanent option and reload the firewall.
To forward packets to another port at another
IPv4 address, usually an internal address, enter the following command as root:
~]# firewall-cmd --zone=external --add-forward-port=port=22:proto=tcp:toport=2055:toaddr=192.0.2.55
In this example, the packets intended for port 22 are now forwarded to port 2055 at the address given with the
toaddr. The original destination port is specified with the
port. This option can be a port, or port range, together with a protocol. The protocol, if specified, must be one of either
tcp or
udp. The new destination port, the port or range of ports to which the traffic is being forwarded to, is specified with the
toport. To make this setting permanent, add the
--permanent option and reload the firewall.