1/24/1111:01 am MacMost Now 507: Editing Your Hosts File Web developers should know that they can edit their Mac's hosts file to supersede DNS and point a domain name to a different web server. This is very useful for testing out sites before launching them or switching DNS. Check out MacMost Now 507: Editing Your Hosts File at YouTube for closed captioning and more options. Video Transcript: Hi this is Gary with MacMost Now. On today's episode I'm going to show you how to edit your hosts file. So this is a tip especially for web designers. So say your setting up a new site at a new server and the DNS hasn't yet resolved to appoint the domain name to that server. Or perhaps your actually moving the domain name to a new server and you want to test it out before you do the big DNS switch over for the entire internet. Well there is a way to actually have your Mac point to the new server without having the rest of the internet do it. The host file is basically your little DNS. It will map a domain name to an IP address if you wanted to. So you add an entry in there specifically for the site your working on to point to the exact web server that your developing on. So in order to do this your going to have to have enabled the route user. To see how to do that you go to this support page at Apple. Once you have route user enabled you can go into terminal and edit this host file. Your going to do it using Sudo first because you have to do this as the route user. And then one of the many text editors available in terminal we will use nano. And then the host file can be found at slash ETC slash hosts. And here's the file. So there's not much in it to begin with and yours may look a little different depending on what operating system you started out with on your Mac. But basically it's a list with IP addresses on the left and domain names on the right. So for instance, If I wanted to put a fake IP address in here, and I can map it to any domain name I want, like that. Then I can exit by using control X and yes for saving changes write to that file and I've now overwritten the host file with my new version. Now in some places you may hear that you need to flush the DNS cache. You can do that with the dscacheutil flush cache command here. I've never had to use that so it always seems to work for me right away. So using that example, if I would now open Suffari, Firefox or any browser or any thing into peak line email what ever, and go to my domain name dot com it would map that to the IP address I specified my host file regardless whats out there in DNS servers on the internet. So if I just established a new account at a new hosting service, I can build a web site there and tell my Mac that the site exists there and actually view it as any body else would eventually. You test it out and make sure it works great and then actually do the DNS change for the rest of the world to switch over to the DNS server. Oh and when you do the main DNS switch, make sure you remove this entry from the host file, or just 8commit out the line so that you can see the site just like every body else does. Hope you found this tip useful. Until next time, this is Gary with MacMost Now.Related Subjects: Web (70 videos) Related Video Tutorials: Mac Photos Editing Shortcuts ― Understanding Mac File Extensions ― Viewing File Contents With Quick Look ― 3 Ways To Print File Listings On Your Mac Comments: One Response to “MacMost Now 507: Editing Your Hosts File” Antrim 9 years ago Super helpful, especially as I am in the process of changing hosts. Thanks. Comments Closed.