I'm a student, and I'm trying to understand the idea behind IP addresses. I learn that typing in a url is the same as typing in the corresponding IP address - either way, we'll be directed to the same web page.
I used the ping
command to find the IP address of howstuffworks.com
. I then typed that IP address in my browser ( google chrome ) but got this error :
The requested URL was not found on this server.
Why? I tried the same with google.com
IP, and it worked fine.
Also, the IP addresses that I found using the ping
command were IPv4 ( for google, it was 173.194.40.80
) . Why did it not show an IPv6 address??
To answer the second part of your question:
The
ping
command chooses one of the addresses to ping when the hostname has multiple addresses. On Windows systemsping
can be used both for IPv4 and IPv6. On Unix-like systems you have to useping6
for IPv6.If you want to look what is in the DNS you'll have to use a tool that is made for that purpose such as
host
ordig
(when on Unix-like system) ornslookup
(when on a Windows system). For example:As you can see there is more in the DNS than
A
andAAAA
records :-)And to make this answer at least a little on-topic for StackOverflow, here is how you can properly deal with name resolving in a dual-stack environment. Write the code in such a way that it automatically uses whatever protocol is available. This is an example in Python:
The relation between FQDNs (e.g. www.stackoverflow.com) and IP addresses (e.g. 198.252.206.140) is not necessarily a one-to-one relation. For instance, if I do a DNS lookup for www.stackoverflow.com, I get 198.252.206.140. So, the website for www.stackoverflow.com is hosted on a web server with the IP address 198.252.206.140. But, it's possible that there may be other web sites hosted at 198.252.206.140 as well.
That's why we have the
Host
command in the http protocol. After the browser makes a connection to the web server on port 80, the browser sends thehost
command to indicate which site on the web server it is attempting to connect to. See http://blog.tonycode.com/tech-stuff/http-notes/making-http-requests-via-telnet for a good tutorial on how this works. Copied below is a telnet session with 198.252.206.140, where an http connection is made, and thehost
command is issued to select www.stackoverflow.com, and the default response for www.stackoverflow.com is returned (which in this case is a 301 redirect to stackoverflow.com):The host name is roughly equivalent to the IP address up to the moment when your browser reaches the remote server.
But the
HTTP/1.1
protocol specifies that the client (the browser) must pass the host name as an header, as in:This is very useful, as it allows several sites to be hosted on the same server, or anyway to be reachable from the same IP address.
You can find this out using the utility command
curl
:Or using your browser with some plugin that allows to set custom headers.