Tip:
Highlight text to annotate it
X
How do you edit the hosts files on a Mac?
The reason why you will probably want to do this is if you are doing a website migration
--
you want to be able to
access the new server without editing the nameservers.
That way you can make sure everything’s working properly, before you guys pull the
trigger
and switch the DNS over.
Or you just want to block some software from accessing their hostname, so
you want to reroute the IP address.
This is how you would do it.
First of all, on the top right, click on the Spotlight.
Go ahead and type in the word “Terminal.”
Open Terminal, and it’s this command prompt thing that pops up.
In there, type in
sudo vi /etc/hosts
What that will do is open the VI program and open the hosts file as a superuser.
You will have to do so to edit that file because of the permissions of the file.
Go ahead and press Enter,
and it will ask you for the password --
it’s most likely the same password that you use to log into your Mac.
After you type in the password, click on Enter,
and then it will open up the file.
In order to edit the file, it’s a little bit tricky, if you’re not familiar with
how to use Linux.
But what you will do is press "i", to get into the insert mode,
then use the arrow keys to navigate just to that location.
Then type in the IP address,
space,
whateverdomain.com.
Then you probably want to hit space again, to put in the IP address,
space,
and www.whateverdomain.com.
That way, you cover both the domain as well as the www version of the domain name.
To save it, what you will do is go ahead and press -- on your keyboard -- Esc.
Then type in a colon ":"--
so you would hold down Shift and hit the semicolon key. That will give you the colon.
Type in "w"
and "w" on your keyboard,
for “write to that file” and “quit.”
If you want to test if it worked, you will go to upload maybe a test HTML file
to your new server, with the word “test” in it.
Go to open Safari or Chrome, type in
whateverdomain.com/test.html.
If it shows up, then that means you’ve done it properly.
Now internally, your computer is mapping that hostname or that domain name
to the new service IP address.
If it’s not, then [laughs] you probably messed up, and it’s not working.
If you’re having problems, feel free to reach out to me as well.
You can go to my blog, yanhuang.me, click on Contact, and you can drop me a line there.
If you did it properly, it should work, though.
Hopefully, you found this helpful.
If you did, go ahead and leave a comment below here.
Like this video, go to my blog yanhuang.me, go ahead and Like me on Facebook,
follow me on Twitter, 1+ my Google+, and make sure you subscribe to my mailing list.