 We have three Linux machines inside virtual box the client the router and server and They set up in a small internet and the server is set up to be running the Apache web server So has a website on it the default Apache website We're going to use the client as a web browser and explore how we can Modify the host file to give some fake domain names just for testing purposes So I'll go to the client and In terms of web browsing on the command line I'm going to use links as my web browser, which is a text-based web browser and Access the server which has IP address 192.168.2.22 So this should take my client to the website of the server in this case and we'll just Press enter and we see at the top. This is the Apache 2 Ubuntu default page So this is provided by default when a patch is installed on the server. So this is the website and I'm going to acute quit. Yes, I'll quit now we don't have a domain name for our web server and We're not going to set one up this stage because in our internal network We're not going to go to the complexities of having a DNS server or registering a real domain name but sometimes for testing purposes, I would like to Give it a domain name so instead of having to type 192.168.2.22, I'd like to type in a domain name and In the host file, I'm going to show that the host file inside a Linux machine it contains local mappings of Names including domain names to IP addresses and In my host file, I have a mapping which I've put in there before that demonstrates that if I want to go to If I type in the domain name www.example.com It will take me to the address 192.168.2.22, which is that of the server Let's just try that so the idea is if I now type in via my browser links I want to go to example.com then It takes me to that same Apache 2 Ubuntu default page. It takes me to the server website to you to quit that Because what happens is that I supply this domain name and what my DNS client does is it looks in this host file to see if there is such a domain name And it finds on this third line There is a domain name that matches that and therefore it says contact the IP address 192.168.2.22 if there wasn't a value in there Then for example, it's not in the host file Then it uses the real DNS system So if it's not in the host file and that's just some cookies that links is asking me about Then it does a normal DNS lookup goes out to a real DNS server and finds the IP address for www.google.com From from the real DNS server and eventually redirects me to the real Google web page I can queue to quit so By default what happens that the DNS or the DNS lookup first consults the ETC host file If there's no matching there then it consults the real DNS server How do I know which real DNS server? There's a resolve.conf File which keeps track of the DNS servers or the name servers listed here So my real DNS servers. I actually have three configured 138 77176.10 and these other two Noting that this file is generated by some other software in the background. We normally would not modify that that's the resolver software so again When I supply a domain name to a client such as a web browser The host file is consulted if there's no answer there then the DNS server One of the DNS servers is consulted and we get the real IP address That allows us to put any domain names in the host file so Once again, if I access Google I get eventually accept the cookies and I get the Google website and I queue to quit now if I edit The host file and we need administrator privileges. I'll open it up in Vi so we sudo vi and If we insert a new line saying Read this backwards the domain name www.google.com Maps to the IP address 192 168 2.22 that is my local server Then when I try to visit Google.com I should be redirected to my local server We'll try that escape and save Now I'll do the same access the Google website and it takes me directly to my Local server showing the Apache to Ubuntu default page This is because the first check is done inside hosts So now my client thinks that www.google.com is actually my local server and it's a way for me to use that domain for testing purposes and For do some simple redirection Noting that the host file is local to my machine All right, so whatever I put in here is only relevant to my client if I then go to let's say My router another Linux machine I have which has a different host file if I Try to access a right ping Google Then it will go to the real Google website So the host file is only for making changes local to the machine So it's no good for setting up domain names across a network. It's just internally to that machine and Just the fear I'll go back and edit my host file and Delete that line Save and now I want to access Google.com Since there's no entry in the host file It should take me to the real Google website because my real DNS server is consulted to get the answer so use your host file to test different domains when you have a local server and Maybe to do redirection if you don't want to go to the real website