Reputation: 63
I recently got to know about DNS (Domain Name System Or Domain Name Server) and how it works. I want to know - can I access to a website by using its IP address and how? -ThankYou
Upvotes: 5
Views: 22221
Reputation: 1060
Yes, you can access any domain using IP address. Domain is just a name of website, IP address is the address of the page/website. You can always ping website using command prompt:
ping www.google.com
You get one ip address which in this case is 216.58.197.78
.
NOTE: The IP may change with time. So make sure you run the ping command to find out the latest IP.
Now when you hit the ip address in browser you will be redirected to google.com. You can think of DNS (Domain Name System) as a table which provides mapping between IP address(216.58.197.78) and domain name(www.google.com)
Upvotes: 2
Reputation: 2770
TL;DR: It depends how the server is configured but probably not and I would not rely on it.
This is because the website you are trying to access is likely behind a reverse proxy or load balancer. The load balancer acts like a railroad switch depending on the hostname you use to connect to it.
For simplicity, imagine that google.com
and mail.google.com
are on the same server with the same IP: 192.168.1.1
.
If you were to try to connect directly to http://192.168.1.1/
, how would the web server know which service you wanted? It wouldn't. In fact there are companies who's business is based solely around load balancing other companies' servers.
When you connect to a host with your browser, for example: https://www.google.com
, your browser sends a special HOST=www.google.com
header behind the scenes. The load balancer processes this header and routes the request to the correct server (which may be on a completely different server, network, etc).
Digital Ocean has a great tutorial on how to configure a basic virtual host for nginx. This demonstrates the basics of what a multi-host configuration might look like.
If you don't want to mess with DNS servers, you could set up a local lab environment on your desktop simply by modifying your hosts
file. You can google where your operating systems hosts file is located.
If you have access to cURL, you can test the results like so:
# if you've configured a virtual host for mysite01.local on port 80
curl --verbose --header 'Host: mysite01.local' 'http://127.0.0.1'
# if you've configured a virtual host for mysite02.local on port 80
curl --verbose --header 'Host: mysite02.local' 'http://127.0.0.1'
# depending on your configuration this may return a 404 or point to one of your previous sites
curl --verbose 'http://127.0.0.1'
Upvotes: 12