Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

is it possible to use CNAME (alias) for <host:port>

Is there a way i can hide the port from url and use cname (alias) instead of :.

For e.g. If my url is http://myserver.com:40089/webapps/index.jsp Is its possible for me to use http://mycname/webapps/index.jsp

Reason i am telling is, i can move around the box called myserver.com to say myserver1.com. I dont want client to always change this url whenever i am moving. Instead my client should be unaware of where the service is running and on which port.

Is it possible? I am using jetty as my webserver.

Thanks in advance.

like image 712
Ajay Avatar asked Apr 09 '11 11:04

Ajay


People also ask

Should I use CNAME or alias?

Use a CNAME record if you want to alias one name to another name, and you don't need other records (such as MX records for emails) for the same name. Use an ALIAS record if you're trying to alias the root domain (apex zone), or if you need other records for the same name.

Can you add CNAME to host file?

Go to your domain's DNS records. Add a record to your DNS settings, selecting CNAME as the record type. Return to the first window or tab and copy the contents of the Label/Host field. Paste the copied contents into the Label or Host field with your DNS records.

Can you specify a port in a DNS record?

There is no way to specify port numbers in DNS. If you are running a website, your server must respond to HTTP requests on port 80 if you don't want to have an ugly port number in the URL.

Can a CNAME point to multiple hosts?

A DNS CNAME record maps one hostname to another. This means that you can have multiple hosts with the same IP address, but each with a different name. For example, www.mydomain.com might be mapped to www1.mydomain.com and www2.mydomain.com so that they all resolve to the same IP address.


3 Answers

With DNS CNAME you can only point from one hostname to another. Port numbers are a totally different piece of cake.

There are several problems with the described situation:

  • if you set the CNAME in your DNS you probably have to modify your webserver as well to handle the new hostname because HTTP protocol works like this
  • as @stevevis said you'll loose your cookies and caches and even the rankings in the search engines
  • you still have to include the port number in your addresses: http://mycname:40080/webapps/index.jsp

You haven't mentioned but I assume that you cannot modify your webserver settings, because in this case you could modify the port number as well.

But there is a solution for this problem with small sacrifices.

You can install an HTTP reverse proxy server to forward the requests to the webserver (for e.g. HAProxy, nginx, etc.) but with this you'll loose the original clients' IP address (of course you can forward it in an HTTP header but you have to modify the code on your previous domain to handle this).

like image 168
KARASZI István Avatar answered Oct 29 '22 11:10

KARASZI István


Try using a SRV record for doing that. It is what I used to get a custom domain for my minecraft server.

like image 45
NdT Avatar answered Oct 29 '22 11:10

NdT


No. CNAME only maps names, not ports. You need a reverse proxy if you want to map x:b to c:d.

like image 3
bmargulies Avatar answered Oct 29 '22 11:10

bmargulies