I wanted to forward requests comming to a server on port 2222 to the same server port 22.
I'm using ufw for the firewall on the server.
- allow port 22 and 2222 on the server.
$ sudo ufw allow 22
$ sudo ufw allow 2222
- Setup port forwarding requests by editing
/etc/ufw/before.rules. Add the following to the top, just before*filtersection:
*nat
:PREROUTING ACCEPT [0:0]
-A PREROUTING -p tcp --dport 2222 -j REDIRECT --to-port 22
COMMIT
- Finally, enable the
ufwrules and restartufwservice:
$ sudo ufw enable
$ sudo service ufw restart