Iptables forward incoming traffic multiple ip

by Francesco   Last Updated July 12, 2019 14:00 PM - source

I have a server with 5 ipv4


and I need to forward only the incoming traffic from port 80 to port 8080 (and same ip) so

95.x.y.1:80 --> 95.x.y.1:8080
95.x.y.2:80 --> 95.x.y.2:8080
95.x.y.3:80 --> 95.x.y.3:8080
95.x.y.4:80 --> 95.x.y.4:8080
95.x.y.5:80 --> 95.x.y.5:8080

Besides iptables it's possible to make something similar with nginx(reverse proxy)? The main issue is to have with Ubuntu18 "different" servers with nginx for each ip that route traffic to a specific Ubuntu user. Any guide/help/example will be greatly appreciated

Answers 1

iptables -t nat -A PREROUTING --dst 95.x.y.1 -p tcp --dport 80 -j DNAT --to :8080
iptables -t nat -A PREROUTING --dst 95.x.y.2 -p tcp --dport 80 -j DNAT --to :8080
iptables -t nat -A PREROUTING --dst 95.x.y.3 -p tcp --dport 80 -j DNAT --to :8080
iptables -t nat -A PREROUTING --dst 95.x.y.4 -p tcp --dport 80 -j DNAT --to :8080
iptables -t nat -A PREROUTING --dst 95.x.y.5 -p tcp --dport 80 -j DNAT --to :8080
Anton Danilov
Anton Danilov
July 12, 2019 13:57 PM

Related Questions

iptables smart loadblancer with geoip

Updated July 24, 2018 15:00 PM