Ubuntu – Forward only web traffic to another interface


My Ubuntu server has two interfaces.

1) Public - eth0

2) Internal -  eth1

How can I forward web traffic (port 80) to nginx running on eth1 from Public interface eth0 ?
I don't know exact ufw rules to complete this.


Best Answer

ufw will not solve your problem that will allow forwarding but it will not do forwarding . if you want to forward your traffic then you have to write NAT rule that will forward your traffic that comes on public ip to private ip.

If you want to allow forwarding from particular network to another network then you can use like:

sudo ufw route allow in on eth0 out  on  eth1  to port 80  from


If you want to forward all network request then you can use like

sudo ufw route allow in on eth0 out  on  eth1  to  any port 80  from any

It will show like :

sudo ufw status
Status: active
To                         Action      From
--                         ------      ---- 80 on eth1      ALLOW FWD on eth0

For more info you can see

man ufw 
Related Question