B
B
barabaris2022-01-08 09:33:36
iptables
barabaris, 2022-01-08 09:33:36

IP address, domain and subdomain?

And so the bottom line:
There is a server on CentOS (aka a gateway) configured iptables - ip address 22.22.22.22 external IP
There is a web server with the address - 33.33.33.33 (address - site.com) local IP
There is a mail server with the address - 44.44.44.44 (address subdomain.site.com) local IP
The question is how to make site.com redirect to 33.33.33.33 (web server) when contacting subdomain.site.com and redirect to 44.44.44.44 (mail server) when contacting subdomain.site.com
How can it be implemented via iptables or redirect?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
H
hint000, 2022-01-08
@hint000

and when accessing subdomain.site.com redirected to 44.44.44.44 (mail server)
The mail server does not care about the domain when establishing a connection, so be guided by the port numbers.
iptables -A PREROUTING -d 22.22.22.22 -p tcp --dport 25 -j DNAT --to-destination 44.44.44.44
iptables -A PREROUTING -d 22.22.22.22 -p tcp --dport 465 -j DNAT --to-destination 44.44.44.44
iptables -A PREROUTING -d 22.22.22.22 -p tcp --dport 587 -j DNAT --to-destination 44.44.44.44

iptables -A PREROUTING -d 22.22.22.22 -p tcp --dport 80 -j DNAT --to-destination 33.33.33.33
iptables -A PREROUTING -d 22.22.22.22 -p tcp --dport 443 -j DNAT --to-destination 33.33.33.33

If your mail server does not use port 465/tcp or 587/tcp, then you can remove the extra rules.

D
Drno, 2022-01-08
@Drno

In short - you need to do port forwarding in iptables

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question