Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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. :)

share|improve this question

marked as duplicate by Chris S Sep 14 '12 at 1:19

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

    
What protocol? You only told us what it's not. That's not helpful. –  David Schwartz Mar 10 '12 at 11:35
    
This is only possible with an application proxy. –  Jodie C Mar 10 '12 at 14:22

2 Answers 2

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 **

share|improve this answer

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.

share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.