DNS and apache relation - apache

when I hit the URL say wget yahoo.com. What all steps take place from the time I hit ENTER till I get the webpage. This is with Solaris machine having Apache webserver and DNS configured . I want to know how does the DNS and apache interact to display the webpage.

Slightly simplified, but the entire dns workings aren't that interesting to you I think ;)
wget requests the ip address for yahoo.com from your local dns server (or isp dns server)
your local dns servers returns the ip address from cache if available and if not it requests the record from the yahoo.com dns servers
wget connects to the ip address and passes yahoo.com as host so the server at yahoo.com knows what domain it needs to return

wget makes an OS call for say news.yahoo.com
the local resolver, based on the config (/etc/nsswitch.conf) looks at /etc/hosts, then makes a request to the DNS server configured in /etc/resolv.conf
that server, if properly configured will talk to the on of the Internet root server to find out who is responsible (in terms of DNS) for yahoo.com
your DNS server will then talk directly to the DNS server responsible for yahoo.com, to get the address for news.yahoo.com, and return the ip address
wget will make an http connection to that ip address
when the yahoo web server running at that ip address (what you call apache) receives the request, it checks what url you asked for, the url is inside the http request.
based on the url you asked for, it will send you a different page (typically, one server running at one ip address, serves more than one url, even more than one domain sometimes).
Note that some browsers will make a search request if the URL you enter isn't a proper URL. So if you type "stackoverflow" in the address bar in firefox, firefox goes to google, make search, and direct you to the first link in that search. I believe the microsoft browser does the same, but does it search on bing.

Related

What am I missing with this Apache setup? Getting 408s in the access.log

I have a bit of a janky setup configured in an attempt to create a little test website that I can navigate to from a source external to my network. I'm working with a dynamic IP address which obviously isn't ideal, but this page isn't meant to be viewed by anyone. I'm using DuckDNS to route to my WAN IP, and that allows me to quickly update the dynamicIP that duckDNS points to in a flash when my Dynamic IP refreshes. I have ports 80 and 443 forwarded on my router to route to my webserver IP. I have apache configured to listen on ports 80 and 443.
I can hit the website internally from my computer and phone (when its on the network), but when I attempt to hit the site from an external source, I get 408s. I'm still a little new to apache, so I'm trying to see what I've missed here? What's weird is that I see the 408s in the access.log - so wouldn't that mean the attempt is at least making it to the webserver?

How does node-express listen both on localhost and local IP?

I started using node express not too long and developed a simple http server using the default settings.
I have always tested it with requests to localhost:3000 with Postman and on the browser and everything was fine.
Then I needed to move the service on the local network so that even applications not running on my machine can access it.
I got my local IP and before perform any modification I tried first with Postman using the IP address instead of localhost and also with the browser on my smartphone to check what would have happened. With my surprise it was already working on the local network, in the sense that I got a response message from the server (which might be dangerous since I did not even know).
I guess the line where you specify which address and port the server should listen on is server.listen(port);
If the address is not specified does it mean that it should listen both to localhost and local IP? Or is node-express automatically forwarding from one address to the other? Otherwise how can it work both on localhost and local IP?
node-express and all other web application servers listen to port, not IP address. That is, as long as port X is listened on your machine (server.listen(port); in node-express) and not blocked by firewall, and another host H can access your machine by IP, H can visit the web application that listen X.
If the address is not specified does it mean that it should listen both to localhost and local IP? Or is node-express automatically forwarding from one address to the other?
"port listening" happens on transport layer, while IP address belong to network layer. When listening to the HTTP request, node-express does not care about the visitor's IP address.
Is there a way to see which resource both of them are pointing to?
All clients visit resource in web application in the same way, it has nothing to do with client's IP, unless you manually configure it in the web application.

Cant access my website through its IP address

I have hosting with godaddy with a private IP address. I am able to access my websites and others via the domain name, but not via IP Address.
I am now trying to access the HTTP via port 80 but it gives an error that the website is not setup.
Are there any workarounds on turning allowing accessing the website and other folders through the IP address over http?
This sounds to me like you were on a managed webpack that grants you access to the to-be-served content but not to the webserver or its config itself.
What you are experiencing there is an effect of a technique called virtual-hosts in which multiple sites are tied to one IP address. For this to work in the realm of HTTP, the Host header got introduced in HTTP/1.1. It allows clients to send a domain name for which they want to receive content.
If you request a raw IP, though, the Host header won't look like Host: example.com but rather like Host: 123.45.67.89. The server will not be able to associate a domainname with this as it is unlikely to be found elsewhere in the request. Therefore, it will be forced to serve content out of its default document directory which usually contains further documentations regarding the further configuration of the webserver in question. Linux distributions like to add additional informations specific to them. Check if you see any mentioning of e.g. Debian, RedHat, or Centos.
I am not sure if this is fixable. Usually webservers like Apache support IP-based virtual hosts. If a masshoster like godaddy is really going to address this is uncertain. Try to contact their support and see.
1]If you are using host headers, make sure you have a DNS entry pointing your URL to your IP
2]Telnet port 80 from a machine outside your network.If it fails then check with your ISP that port 80 should not block in firewall.

How to use a domain for two IP's

I have a minecraft server and I want to make it so example.com points to two IP addresses. I want to know how to make it. So, apache, godaddy, or whatever detects a browser and sends it to the website version and when a client is being detected it sends it to the minecraft server.
For example:
I type example.com in my browser and it takes me to the website.
I type example.com in my minecraft server list and hit enter and it shows my minecraft server.
Thank you.
They do this by adding specific entries to your DNS record. By setting an SRV record you can forward all requests on a specified port to a separate target which may be another domain, a sub-domain, separate directory, or another IP address.
Example SRV record:
_http._tcp.example.com. IN SRV 0 5 80 www.example.com.
_minecraft._tcp.example.com IN SRV 0 5 25565 play.example.com.
In the above example you could also replace the domains used at the end of either record with a separate IP address and it would also work.
Of course your exact method of adding these records depends on who is the host that is controlling your DNS records and what method of edit they offer to you.
You can't use a domain for two IP addresses. However, It is possible to have a web server on the same network. That way the domain name should work with the web server and your minecraft server.

Apache unable to access local DNS ip address

I just set up a server in my house using private IP.
I can access my server using my domain from outside network/ outside from my house.
But I cannot access it from local network using my domain or my private IP address.
What can be the problem for this? is it the Apache settings?
(I can access it if I edit the /etc/hosts file)
Did you use the internal or external IP in your hosts file to get it working? If it was external IP it's probably the DNS issue. If it was the internal IP, the issue could be in the routers NAT.
Some routers/setups will only apply their NAT rules on packets traversing the external internet facing interface.
____________
| |
Server ---IntIf-|IntIP--ExtIP|-ExtIf--- Internet
|____________|
This is a bit simplified but basically when you access the external IP from the internal network the packet, following the dotted line, reaches the routers external IP before a NAT rule can be applied on ExtIf and then the router can't find anything listening so rejects/drops the connection.
To confirm if it is the DNS problem. Run an nslookup $domain from both your local and external boxes and see if they return the same IP address. If the IP's are the same and it's still not working you will need to take a closer look at the router, hopefully that's possible. If not you may need an internal DNS server that can respond with the internal IP addresses for any domains it knows about then forward any other requests externally.
The NAT issue is called NAT Loopback, Hairpinning or Reflection. See here for a linux solution.
If you can access it when you put in an entry in /etc/hosts, then likely it is DNS related. I am assuming you are putting in the public (external IP) and not an internal IP for testing.
If you have recently updated your DNS, then likely your local router (or ISP's DNS server) will still have the old IP cached or the fact that there is no DNS record setup cached. You could reboot your router to try and clear the cached entry, but it could well be cached at the ISP and you can only wait until it updates there (usually somewhere under 24 hours, often just a few hours). However, you could configure your computer to use a different DNS server for a while - eg. 8.8.8.8 or 4.4.4.4 which are both run by Google.