How does my local HOSTS file resolve but IP will not - dns

I'm in the process of launching a new website. I migrated all the code to the new server. The admin at the new host told me that I have to add an entry to my hosts file and then I will be able to see the website. So essentially he had me add:
111.222.3333.4444 example.com www.example.com
These are example, but after doing this, it worked. My question is, is how? If I visit the IP directly in my browser I get a 403 Forbidden error. Does the host have a way to resolve this IP to a location on their server if resolved from a domain name? I'm just confused as to how this works. I understand that by changing the IP address I can get the domain name to resolve to any IP, but I'm wondering why, on the hosts end, does this now resolve this way, but not by typing in the IP directly.
Thanks!

Does the host have a way to resolve this IP to a location on their
server if resolved from a domain name?
Not exactly. Your browser, when sending the request to the IP address, will send one important piece of information called 'Host header', that is the actual host name as you typed in your browser.
You usually can not open the website just by entering the IP address in your browser's address bar because web servers (and possibly many other network components that are between you and the web server) often do not host only one web site on that IP address so they rely on exact domain name typed in address bar to serve the right content.
You can test this by using one of the browser add-ons that allow you to add your own headers. Add header named 'Host' with the value 'example.com' and with that try to open your site by typing only provided IP address.

Related

How to configure DNS host record so that my website shows domain name instead of ip address?

Currently I have a golang app that is serving at X.X.X.X:443. Suppose my domain name is example.com. I want to link example.com to X.X.X.X:443. I tried entering this into A Record but it doesn't allow me to use port. Therefore, I currently use URL Redirect Record. I tried to link CNAME Record to this URL Redirect Record but to no avail. It just keeps showing my ip address instead of example.com.
I don't mind having example.com:443.
Can I know how should I solve this problem? Is it supposed to be solved on the DNS side? Some suggest that I must host on port 80. Is it true?
According to the documentation (https://cloud.google.com/appengine/docs/standard/go/tools/local-devserver-command)
the parameter to change the host is : --admin_host=ADMIN_HOST
Definition is : "Host name to which the local development server's administration console should bind (default: localhost)."

domain poiting to website

I have a a website on my server on a subdomain. let's say at this adress:
subdomain.sourceserver.com/site/
I mapped a freshly bought domain (mynewdomain.com) to my server. So now mynewdomain.com resolves with the IP of my server.
And http://mynewdomain.com displays the website located at subdomain.source-server.com/site/
When I start browsing in the pages of the website, the adress displayed changes back to http://subdomain.sourceserver.com/site/blabla.php
I would like to keep it with the domain name:
http://mynewdomain.com/blabla.php
How can I do that ?
Do I have to create a CName on the DNS zone subdomain.sourceserver.com ?
Thanks in advance !
Cheers,
Mat
DNS is not what's changing the address in your browser, it is likely your web code or web server config. My suspicion is that your site is configured to be "subdomain.sourceserver.com/site/", so links inside the site are pointed at "http://subdomain.sourceserver.com/site/something.file", which is why the visible URL changes.
http://mynewdomain.com is resolving to the same IP address as your previous name, so your web browser is taking you to the same content. Unless you have virtual hosts configured so that the server pays attention to the headers, it will simply serve out the content to the request that lands on it's IP:port.
Virtual host examples

Make original site url name to some fake url name

I am new to rewrite site url name. I have a site url like http://66.15.101.250/test/ . this is my owned server link So i want to change this site url to something other name like http://testsite/test/ ( i do not want to give domain name to this ip address url).And i have otheres site running on this http://66.15.101.250/test/ server . I have no idea how to do this, what should i do.
Is this possible through .htaccess file or something else
Thanks in advance
Your server can only respond to requests it receives, and will only receive requests routed to it by DNS, so if you don't own the domain name, you can't receive public traffic directed towards it. You could silently redirect users from
http://66.15.101.250/test/ to the content found at http://testsite/test/ but they would still see the http://66.15.101.250/test/ url in their browser.
If you think about it, its a good thing you can't do this or I could make stealyourcreditcardinfo.com appear as paypal.com. Indeed most uses for what you are asking about would not be legitimate ones...
For your own internal testing purposes, you can make virtual host entry for testsite.com and your server will respond to any requests it receives for testsite.com. You then change your HOSTS file to point testsite.com to 127.0.0.1 and testsite.com will work in your browser, but only on your machine because you manually overrode your own DNS. The DNS everyone else is using is still pointing testsite.com to the actual IP address somewhere else
If you need this for testing purposes (as it seems to me), you can put 66.15.101.250 testsite in your hosts file and configure a virtual host for testsite in your webserver.

How do I redirect to a shared virtual hosted site in the hosts file?

I want to change my hosts file to redirect a web address to my site...
normally I would just do... ping mysite.com then in the hosts file, if the IP came out as 99.99.99.99, I'd write...
99.99.99.99 siteiwanttoredirect.com
But in this case my site is on virtual shared hosting... which means the IP I get back from the ping is the same as a few other sites and if I type that IP in the address bar, www.mysite.com won't come up. Here's a bit more details: someone who asked a question about why pinging it wouldn't give the correct IP.
So what I would like to know is... if you're on virtual shared hosting, how can you specify redirects to your site in the hosts file?
Thanks,
Matt
You cannot. With the hosts file you can change the IP address, but your shared hosting provider needs the HTTP Host header to be set up correctly -- which in your case will still be siteiwanttoredirect.com and not mysite.com . Your hosting provider will therefor not know who's site to show.
What you could do is redirect to some host you control (f.i. localhost) and run a proxy server there. If you set up Apache on your machine, with a virtual host for siteiwanttoredirect.com which does a reverse proxy to mysite.com , it should work.
This is handled via the host header of the website, and not anything on your local machine, like your hosts file.
I would make sure your host has that set up, then as long as people visit your sit via the website name, and not IP, everything should work.
On a shared host, the website you get is determined by the domain name you ask for thanks to the Host HTTP header. For this to work properly the web server needs to be configured correctly so it knows what website to serve in response to which Host request - this is usually called 'Add-on Domains' on CPanel driven shared hosting.

How does my shared host's nameserver resolve http://servername.com/~username/ to my top level domain?

I recently moved my website to a shared hosting solution at asmallorange.com, but I had to set my domain to use their provided nameservers in order for the site to properly resolve. I was determined to keep control of the domain's DNS but I could find no way to make my top level domain resolve to the shared location which was in the format of
server.asmallorange.com/~username
So I know I'm missing something here, my question is this:
What in their nameservers/DNS entry makes it possible for server.sharedhost.com/~username to serve as a top level domain? (ie. http://topleveldomain.com)
Nothing. DNS simply maps topleveldomain.com to server.sharedhost.com. It's the webserver which looks at the Host: topleveldomain.com header and knows that's equivalent to server.sharedhost.com/~username.
Nothing. They are having your domain name resolve to the same IP that server.asmallorange.com resolves to, but then they are making their web server aware of the domain name topleveldomain.com, and telling the webserver that it is the same as server.asmallorange.com/~username.
Virtual hosts aren't a DNS trick, they're an HTTP trick - the hostname requested is sent by the browser in a Host: field of every request.
apache has a "mod_user" which you can enable in your apache conf file. Using this and virtual hosts is how that is accomplished.
Virtual Hosts in Apache are how this is done.
However just because you set the DNS up to go "mydomain.com resolves to 1.2.3.4", which is their IP address, doesn't mean that you're giving up control of your domain name.

Resources