ufw: how to forward single port to another port on different interface
10,887
DNAT
may suffice:
# iptables -t nat -A PREROUTING -i eth0 -p tcp -d 192.168.1.2 --dport 8080 -j DNAT --to-destination 192.168.3.2:80
The UFW before.rules
file from some altagoobingleduckgoing looks like it uses the iptables-save
format, so thus may contain something along the lines of:
*nat
:PREROUTING ACCEPT [0:0]
-A PREROUTING -i eth0 -p tcp -d 192.168.1.2 --dport 8080 -j DNAT --to-destination 192.168.3.2:80
COMMIT
Related videos on Youtube
Author by
sergius
Updated on September 18, 2022Comments
-
sergius over 1 year
I have two interfaces eth0 (192.168.1.2) and eth1 (192.168.3.2).
I receive data from 8080 at eth0. I want to forward it to eth1 port 80.
I'm using UFW, because i don't understand iptables and how to add it at the beggining of /etc/ufw/before.rules.
I've already edited DEFAULT_FORWARD_POLICY="ACCEPT" on /etc/default/ufw and already edited net.ipv4.ip_forward=1 on /etc/ufw/sysctl.conf
-
davidbaumann over 8 yearsSo there's a service running on eth1 port 80, and you want it to accept connections on eth0 port 8080?
-
sergius over 8 yearspeople connect to eth0 8080, but the server is at eth1 80. I want to redirect or forward the data so they can see my server.
-
davidbaumann over 8 yearsImho, if you are in control of that service, it should be better to configure the service, instead of doing this workaround...
-
sergius over 8 yearsi can't change this scenario, need to solve it with this configuration. Thanks, David =)
-