Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Im currently using ufw to enforce some basic firewall rules. Is it possible to also use ufw to do port forwarding?

Specifically im wanting to forward incoming traffic to my server (same machine running ufw) on port 80 to port 8080. (http traffic forwarded to tomcat)


share|improve this question
up vote 26 down vote accepted

To have a concrete example, let's say you want to forward requests going to 80 to a server listening on port 8080.

Note that you will need to make sure port 8080 is allowed, otherwise ufw will block the requests that are redirected to 8080.

sudo ufw allow 8080/tcp

Add before filter section in /etc/ufw/before.rules(top of file):

-A PREROUTING -p tcp --dport 80 -j REDIRECT --to-port 8080

Then restart ufw.

share|improve this answer
could you explain this line by line please? also, is there not something like ufw forward 80 to 8080? I thought UFW was Uncomplicated. – Tom Mar 11 '12 at 11:58
Looks like there are no ufw commands for setting up the port fowards, so it must be done via configuraton files. More detailed description about the configuration file syntax is available at:… – Juha Palomäki Jul 24 '12 at 9:01
That doesn't work for me, I receive following message in /var/log/syslog after turning loggin on: [52627.259812] [UFW BLOCK] IN=eth0 OUT= MAC=xxx SRC=xxx DST=xxx LEN=60 TOS=0x00 PREC=0x00 TTL=59 ID=59278 DF PROTO=TCP SPT=53997 DPT=8080 WINDOW=14600 RES=0x00 SYN URGP=0. It may be useful to know that before everything, I denied all incoming requests using ufw deny incoming and allowed only ssh,80,443. Could someone please advise what is the problem? – Yura Jul 31 '14 at 8:05
@Yura I had the same problem (8080 was blocked when I looked at syslog). Running sudo ufw allow 8080/tcp fixed the problem for me. – Tim Swast Jan 29 at 3:19
@TimSwast I somehow solved or overcame this issue at that time, but anyway thanks a lot for your help :) – Yura Jan 29 at 16:24

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.