Forward only web traffic to another interface

18,774

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  10.0.0.0/8 port 80  from 192.168.0.0/16

or

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
--                         ------      ----
10.0.0.0/8 80 on eth1      ALLOW FWD   192.168.0.0/16 on eth0

For more info you can see

man ufw 
Share:
18,774

Related videos on Youtube

Darryl Williams
Author by

Darryl Williams

Cloud Infrastructure and DevOps Expert with around decade experience in IT Infrastructure. Expert in Designing and building Infrastructure as code, automation of cloud infrastructure provisioning , system provisioning , apps/Micro services deployments , CI/CD pipelines , building highly available and reliable IT Infrastructure platforms.

Updated on September 18, 2022

Comments

  • Darryl Williams
    Darryl Williams over 1 year

    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.

    Thanks

    • Thomas Ward
      Thomas Ward over 8 years
      Why is nginx listening on eth1 only?
    • Darryl Williams
      Darryl Williams over 8 years
      because nginx is running in docker bind to eth1.
  • Darryl Williams
    Darryl Williams over 8 years
    I tried , it is not working.
  • pl_rock
    pl_rock over 8 years
    have you written any rule for outgoing . ? this will forward incoming address . write rule for outgoing
  • Darryl Williams
    Darryl Williams over 8 years
    No, there is not rule for outgoing
  • Darryl Williams
    Darryl Williams over 8 years
    Please give me rule for outgoing address also
  • pl_rock
    pl_rock over 8 years
    sudo ufw route allow in on eth0 out on eth1 to 10.0.0.0/8 port 80 from 192.168.0.0/16 sudo ufw route allow in on eth1 out on eth0 from 10.0.0.0/8 to 192.168.0.0/16 apply both rule
  • Darryl Williams
    Darryl Williams over 8 years