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.

3
  • 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 2, 2011 at 21:18
  • There's only one IP address.
    – user76231
    May 2, 2011 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 2, 2011 at 23:02

4 Answers 4

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.

3
  • Actually, if this is indeed http traffic, a solution could be set up fairly easily using Apache VirtualHosts and mod_proxy.
    – EEAA
    May 2, 2011 at 21:32
  • It's not http traffic.
    – user76231
    May 2, 2011 at 22:36
  • There is more than "A" (address) records on dns servers. For example, in this case "SRV" could be a good solution.
    – pbacterio
    Oct 2, 2017 at 9:16
0

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

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.

2
  • 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 2, 2017 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 2, 2017 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.

2
  • 1
    it is not http traffic as user76231 told. So apache or nginx it will not work in his case.
    – Rainer
    Oct 2, 2017 at 9:01
  • Sorry, I must have missed that comment. Yes, you are right. This will not work for non-http traffic. Oct 2, 2017 at 10:26

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .