Linux.com

Home Linux Community Forums Hardware Networking traffic redirection by domain name to external addresses

traffic redirection by domain name to external addresses

Link to this post 01 Apr

Hi.

We using Linux CentOS.

For example - we have 3 hosts - host1.domain.com, host2.domain.com, host3.domain.com. Hosts connected via VPN.

Task: host1.domain.com must be a gateway for http/https traffic, and redirect requestes to host2.domain.com and host3.domain.com.

host1.domain.com will have external IP and accepts request on 80 port.

host2.domain.com and host3.domain.com - internal IP and accepts request on 8080 and 8443 ports.

How this can be realised? IPTABLES, NGINX, something else?

And - what about other traffic? SSH, samba etc.

Thanks.

Link to this post 12 May

For port redirection:

iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 80 -j REDIRECT --to-port 8080

iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 443 -j REDIRECT --to-port 8443

From one IP to another and one port to another:

iptables -t nat -I PREROUTING --src 1.1.1.1 --dst 2.2.2.2 -p tcp --dport 80 -j REDIRECT --to-ports 8080

For the redirection of requests from host1 to host2 or host3 (assuming you are loadbalancing), I would probably actually use ldirector and not iptables.

If you are also controlling your own DNS, you might use round-robin DNS to do this.

Who we are ?

The Linux Foundation is a non-profit consortium dedicated to the growth of Linux.

More About the foundation...

Frequent Questions

Join / Linux Training / Board