3
votes

Is there generally any issue with assigning different domain names to the same IP address on a server, but differentiating them by port number?

Is there anything unsafe, or considered bad practice with doing this?

1
What do you plan to do with them? Presumably not web serving...T.J. Crowder
It's pretty common to have several domains resolving to the same IP. You don't really need to use different ports.ffflabs
@amenadiel I'm talking about the two domain names serving two different web sites.Hypersapien
I know. Your webserver should allow you to specify N vhosts, each ones listens for a particular host and has its own document root, so it serves different websites. There are exceptions (for example with node.js) that need additional configuration or proxy modules.ffflabs

1 Answers

4
votes

It's perfectly fine to associate multiple domains with a single IP address, and it's perfectly fine to only respond to queries on certain ports that meet whatever criteria you want to impose.

Whether it's feasible will vary on the protocol being used. For instance, if you were doing this with web serving, where (say) http://example1.com:80 (80 being the default HTTP port) was supposed to do serve one thing and http://example2.com:81 was supposed to serve something else, you'd be relying on the client issuing the request sending you the HTTP Host: header (nearly all will, it's a really important header and it's required in HTTP 1.1), so you could deny the example2.com requests on port 80 and the example1.com requests on port 81. (Why you would want to do that is a question; you could just use the standard port and vary the content you send back based on the Host header, that's extremely standard practice.)

But not all protocols tell you what domain the client looked up in order to find your IP address, so it may not be feasible to do this with other protocols.


Re your comment on the question and below on this answer:

I'm talking about the two domain names serving two different web sites.

The reason I want to do it is because we have exhausted the IP addresses that our hosting service has supplied on our web server and we have to pay to get more.

You don't need, and don't want, to use different ports for this. You can do it based on the Host header (see above). It's extremely standard practice. How you do it depends on your web server software. Apache calls this name-based virtual hosts, but I'm sure it's possible with all major web server software.