

Now, add the rule for the SSH connection and restart UFW Firewall using the command: sudo ufw allow OpenSSH sudo ufw allow in ssh sudo ufw enable

The image below shows an example of configuration, through which all the requests that have been made on port 70 will be redirected on port 8600. A PREROUTING -p tcp -dport exposed_port -j REDIRECT -to-port effective_port So, edit the UFW configuration file in the "/etc/ufw/les" directory manually : cd /etc/ufw sudo nano lesīefore * filter section, insert these instructions, modifying respectively the parameters "exposed_port" and "effective_port" with the port number on which to enable the requests from outside and that of the port that the service is actually listening on. Replace 'port_number' with your destination port you want traffic to be directed to.Īs previously said, there is no direct command to type. Do it by using the command: sudo ufw allow port_number/tcp However, this operation is possible by acting on the configuration rules on which UFW is based, the default application for configuring the firewall on Ubuntu.įirst, make sure that the destination port is enabled for TCP traffic, otherwise UFW will block all the requests towards that port. Originally, there are no commands that allow port forwarding, that is, to redirect the traffic received on a given port to another port of your choice.

In case of a local server, go to the next step and open the terminal of your server. If you haven’t done so yet, following our guide is recommended to connect securely with the SSH protocol. To start, connect to your server via an SSH connection.
