Why do IP addresses given by dig not work? - networking

I'm trying to learn more about networks and came across the following:
When I use dig to get the IP address of stack overflow, I get the following result:
dig stackoverflow.com +short
151.101.1.69
151.101.193.69
151.101.129.69
151.101.65.69
However, copying any of these IP addresses in my browser returns:
Fastly error: unknown domain: 151.101.65.69. Please check that this domain has been added to a service.
What am I getting wrong here? Why can't I access these IP addresses through my browser?

Many server IP addresses today are configured to serve different websites depending on the Host header that is sent by the browser in the address bar. This is known as virtual hosting. Fastly is one such provider that uses those IP addresses as part of it's content delivery network. But if you enter them directly into your browser the servers will have no idea what website you are trying to access.
You can observe this behavior with curl:
curl -I 151.101.65.69 # This will give an error
curl -I -H "Host: stackoverflow.com" 151.101.65.69 # Specifying the host redirects to the correct website

Related

Host command providing wrong twitter IP address

I'm building a clone of the host command. I've tried finding the host of twitter.com and have received the same IP-Address both on my version and the real host command. The address is: 104.244.42.65.
For some reason, when I input this IP-Address into the browser, it says that there's no webpage with that IP address. Why is this happening?
The host command uses ICMP to detect if the DNS name of the host can be resolved and host is reachable. And you can resolve and reach the IP that resolved for twitter.com.
However, the web server of Twitter is probably configured to answer only if asked by DNS name and when your browser sends a HTTP GET request with the IP, the server does not respond.
Twitter gets tons of requests per minute. The surely use load-balancers that redirect "twitter.com" to multiple IP addresses and they don't want people to use particular IP addresses, which would mess up their load balancers.

How does 1.1.1.1 resolve to a website when .1 is not a TLD

When typing 1.1.1.1 in address bar of a browser it opens up https://1.1.1.1/, This is first time I saw .1 top level domain so I looked it up on various domain registrars. I could not find it so I checked if was actually a TLD on iana.org and wikipedia.org. It does not seem to be a top level domain so I went back and checked TLS certificate which was issued to https://cloudflare-dns.com/
So I thought it was maybe a clever JavaScript hack which changes URL after page load but then I checked network requests and they seem to have 1.1.1.1 as domain name too (shown below)
Request URL: https://1.1.1.1/
Request Method: GET
Status Code: 200
Remote Address: 1.1.1.1:443
How does cloudflare do this?
I saw .1 top level domain
It is not.
1.1.1.1 is an IPv4 address, that is all. Nothing more, nothing less. And the website on it has a certificate with the IP address, which is possible, yet rare.
When you use any URL, with an hostname, that hostname is converted to an IP address and the browser connects to it. You can however put an IP address directly in an URL in which case the browser connects to it directly, it skips the DNS resolution of name to IP address.
Numerical TLD are forbidden by current ICANN rules, exactly to disambiguate them with IP addresses.
See my longest explanation at Number in the top-level domain? about TLDs and numbers in them.
How does cloudflare do this?
Anyone could do exactly the same as them, but with obviously less usefulness. Just make sure to create the proper certificate, some CAs allow to provide certificates on IP addresses, but not all of them, and it is not the standard case. The webserver should also be configured accordingly, to accept an IP address in the URL where it would expect an hostname to be able to serve the proper website, especially if multiple ones are on the host (in which cases for HTTPS you need separate IP addresses, one per website).
You can see the same site as here
https://one.one.one.one/
% dig one.one.one.one +short
1.0.0.1
1.1.1.1

When I get the ip address using the terminal, I get an ip address for a different website, how is this possible?

When I ping or traceroute the website I want to resolve, I get an ip address back, but when I put that into the browser, it leads to a different website. How is this possible?
The IP address you are getting is for a SHARED HOSTING. In Shared Hosting multiple websites are hosted on same IP address. If you have dedicated hosting, you will get your website when you hit the IP address.
The http request sent by your browser includes a Host header that tells the server which website you are trying to reach. This is how multiple websites can be hosted with a single IP address.

How to determine the IP of the server to which a client is connecting to? Is it possible?

I am now just starting to understand Httpcontexts and server side logic. Total beginner.
I have understood how to read the http requests from a client and get the remote IP etc.
I came across the hostname property.
I believe hostname and domain are completely different.
My undersanding is that stackoverflow is the domain name.
Given its widespread reach, stackoverflow can have multiple servers and hence multiple ip addresses.
So is there a way to determine to which server a client is requesting to in asp.net core 2.0?
You are correct that stackoverflow.com is a domain name. A domain name points to an IP address. That's called DNS. stackoverflow.com points to one single IP address not multiple. There's probably a load balancer at that IP address which then points you to an available server, which is internal you can't see that, but that's another story.
If you ping stackoverflow.com you get:
The whole point of DNS is to not use IP address but a domain name.
I'm not sure why you would want to see the IP. Maybe this stackoverflow question can help: Resolve HostName to IP

Find my IP address when ssh'ing when behing a web proxy

I'm on a corporate network and need to find out the external IP address that my ssh is showing up as so I can white-list it.
I can't use whatismyip.com or "curl ifconfig.me" because this network is proxying all the web traffic, so the IP is different than what SSH goes out as.
Is there an equivalent service that I can SSH to and it will repeat my external IP address?
Ok, finally got around to solving this myself:
http://ipcheck.finne.us/
Chrome won't do a request on port 22, so
curl http://ipcheck.finne.us:22/

Resources