0

Lets say I have two domains pointing to my IP:

first.com and second.com pointing to 127.0.0.1

When someone connects to first.com:6000 it should go to 127.0.0.1:6000. But when someone connects to second.com:6000 I need it to go to 127.0.0.1:6001.

What's the best way to achieve this? I'm using Ubuntu 10.10.

user76231
  • 33
  • 2
  • 4
  • Can you please better clarify what you are looking to achieve? Is the communication via http(s) or via some other protocol? Also are the domain names CNAME DNS records to each other or are they unique IP addresses? – Red Tux May 02 '11 at 21:18
  • There's only one IP address. – user76231 May 02 '11 at 22:37
  • You're 50% there... there's one other question you forgot to clarify on: Is the communication via http(s) or via some other protocol? – Red Tux May 02 '11 at 23:02

4 Answers4

1

This is not possible.

The domain name gets resolved to an IP address by the connecting client, and the IP communication to the server just contains a request for the port on the IP address that it resolved to. You will have to change your software configuration to find another solution. You either need to programatically make a different request in the first place or have the answering server do some work in the background or perhaps your API can prompt for the domain as part of your chat with the port.

Caleb
  • 11,813
  • 4
  • 36
  • 49
0

For some protocols you could use SRV dns records: https://en.wikipedia.org/wiki/SRV_record

pbacterio
  • 276
  • 2
  • 6
0

What you need is a multiplexer for TCP connections. Probably you can use HAProxy (http://www.haproxy.org/) to do what you want, but there are more options. HAProxy is not limited to HTTP connections. For example, I know someone who has used it for SMTP connections. The idea is a follows. You define a HAProxy frontend running on port 6000 that has two rules for dispatching traffic:

frontend frontend_name
  bind *:6000

  acl first_host hdr(host) -i first.com
  acl second_host hdr(host) -i second.com

  use_backend first_backend if first_host
  use_backend second_backend if second_host

Then you define two backends for each host. You will need three separate ports for frontend and two backends. I have not personally tested it, but the syntax should be more or less OK.

Edit: This will work only for HTTP/HTTPS connections. However, if your protocol includes the server name in a request it might be possible to extract the server name from the request with req.payload function.

JooMing
  • 815
  • 7
  • 11
  • 1
    haproxy can only work with pattern if used protocol including fqdn in requests. Protocol is still not known here. So it may work only in some cases. – Rainer Oct 02 '17 at 11:08
  • Good catch! Indeed, the acl matching by the fqdn will require HTTP/HTTPS connections. I've updated my answer about the limitations. – JooMing Oct 02 '17 at 13:39
-1

You need to have a web-server like apache or nginx running on port 6000. This web-server can then re-route your requests to desired port as your pre-defined rules.

Ketan Patil
  • 101
  • 2