0

Possible Duplicate:
How to use DNS to redirect domain to specific port on my server

So I've been trying to figure out how to redirect a subdomain to a specific port.

Let's assume the application will always request the default port and that default port is, say, 30000. We have sub1.domain.com, sub2.domain.com and sub3.domain.com, all of them pointed at the same IP. I want to redirect the request to sub1.domain.com:30000 to port 31000, sub2 to 32000 and sub3 to 33000. All of them on the same IP.

I've tried socat/netcat and iptables but they all resolve the domains to an IP address which, in this case, is the same so it breaks the redirection.

Any ideas? Is this even possible? I have some networking knowledge and understand layers a bit… The problem here is cross-layer, so I'm not sure there's even a way to do it unless I write a server that listens on that port and redirects based on requested domain… :\

Thank you in advance. :)

2 Answers2

2

I don't think iptables can do such a trick. It is better suited to deal with IPs not domain names.

For HTTP traffic, you can do such a thing using a proxy server (or HTTP load balancer) which will get your request and redirect them according to the defined rules.

If this is a non-HTTP traffic, we can not give you more help unless you are more specific. However, the basic idea can be the same given that your protocol behaves similarly to HTTP. One important note mentioned by @Yvette which is adding the host information (such as Host header in HTTP). Otherwise, you may not be able to recognize the requested sub domain name.

Khaled
  • 35,688
  • 8
  • 69
  • 98
1

You can try to add a header identifying which host to be requested to your requests.

It just like the following request.

HOST: xxoo1 ** your original request data **

Siyuan Miao
  • 111
  • 2