I'm preparing to teach a class where I want to explain that a domain name (often referred to as a URL) corresponds to an IP address and that you can use an IP address directly in the browser instead of a domain name. I've hosted my own website before and was able to access it using the static IP and port number in the browser, but when I tried to enter the IP addresses of other sites like Wikipedia or Heroku, I encountered errors like "400 Bad Request" and "404 Not Found." I'm looking for tips on how to find the IP addresses of these websites and how to demonstrate this concept without running into issues during my lesson.
3 Answers
When you try reaching servers via their IPs, you might hit those errors because many servers handle requests based on the domain name they were called with. For example, Amazon might handle requests from many domain names through a single IP. If you just access the IP, the server might not know what site you want due to the absence of the necessary headers. You could take a look at using tools like dig or nslookup for insight into how DNS resolves names to IPs and then explain how they interact with web servers.
It's important to clarify that a URL isn’t simply interchangeable with an IP address. You might confuse your students by suggesting they are equivalent. The domain name resolves to an IP address, but when you're visiting a site, the server often relies on both the IP address and the requested domain to serve the correct content. When you enter just an IP, it might not direct you correctly if that server hosts multiple sites. You can illustrate this better by showing how DNS converts a domain to an IP and by using `ping` in the command line to reveal the IP address of a domain. But remember, many sites share an IP, so you may not always get the expected result just by using an IP.
So what’s the best way to demonstrate this? Can you give a practical example?
You got this! Start with a DOS command prompt and use `ping` to get the IP address from a domain. For instance, `ping google.com` will return the IP address. Once you have that, try accessing it directly in the browser. Just remember that the site's server can host multiple domains, so typing in the IP alone may not work for every website due to how virtual hosts function. The real takeaway is to show the students that while an IP address can technically point to a server, the domain name is what guides the server to present the right site—it's about understanding the connection, not just replacements.
That makes sense! So, using a generic example like Google is a good start. What if I want to show a small, shared hosting example?

Gotcha! So it's all about the headers and how servers communicate, not just the numbers.