Title: How to edit your Mac's Hosts file, and why you would want to Post by: HCK on September 05, 2014, 09:00:31 am How to edit your Mac's Hosts file, and why you would want to
<div class="field field-name-body field-type-text-with-summary field-label-hidden"><div class="field-items"><div class="field-item even" property="content:encoded"><p><a href='http://www.imore.com/how-edit-your-macs-hosts-file-and-why-you-would-want' title="How to edit your Mac's Hosts file, and why you would want to"><img src='http://www.imore.com/sites/imore.com/files/styles/large_wm_brw/public/field/image/2014/09/hosts_hero.jpg?itok=4VBRWvxS' />[/url]</p> <p>If you're setting up a new web server or another device that's going to be connected to the Internet and you want to put it through its paces before it's live, or if you're having trouble with spyware and adware networks, there's an invisible file on your Mac that can help. It's called the Hosts file, and this is how to use it.</p> <!--break--> <h2>The Domain Name System</h2> <p>When you type in the domain name of a web site you want to visit there's a lot happening behind the scenes. Every web site, every service, almost every device connected to the Internet has a unique numeric address that tells all the other devices where it is — its TCP/IP address. The Domain Name System (DNS) translates those numeric addresses into something a bit more recognizable and memorable to humans, like, "www.imore.com" for example.</p> <p>The first time you type in a web address, your Mac pings a DNS server — typically one automatically configured for you by your Internet Service Provider — to find out the TCP/IP address of the server you're trying to connect to. Your Mac builds up a hidden cache file to remember those details later on, when you visit the same site again.</p> <h2>The Hosts file</h2> <p>The Domain Name System and its associated cache is your Mac's standard way of knowing how to get to where it's going on the Internet, but there's another file that can be very useful. It's called the Hosts file, and it can be used to override the default DNS information.</p> <p>There are some practical reasons for why you'd want to use the Hosts file instead of just letting DNS do its thing. Let's say you're testing a development server you're about to deploy, and you'd like to use its domain name instead of the machine's specific IP address. Before the system's online and accessible to anyone using DNS, you can use the Host file instead: Enter the machine's IP address and when you use that domain name, your Mac will go to that device instead.</p> <p>You can also use the Hosts file to block or work around spyware and ad networks by "zeroing out" their IP addresses - putting in 0.0.0.0 then the name of the domain you'd like to block.</p> <h2>How to edit the Hosts file</h2> <p>The best way to work with the Hosts file is using the <strong>Terminal</strong> application found in your Mac's <strong>Utilities</strong> folder. You'll need to know the IP address of the device you'd like to send your Mac to, or the domain names you're trying to keep your Mac away from.</p> <ol><li>Double-click <strong>Terminal</strong>.</li> <li>type <tt>sudo nano /etc/hosts</tt> then hit <strong>return</strong>.</li> <li>You'll be asked for your password. Enter your admin password.</li> </ol><p><a href='http://www.imore.com/how-edit-your-macs-hosts-file-and-why-you-would-want' title="How to edit your Mac's Hosts file, and why you would want to"><img src='http://www.imore.com/sites/imore.com/files/styles/large/public/field/image/2014/09/hosts_terminal.jpg?itok=dJ_-OmRA' />[/url]</p> <p><a href='http://www.imore.com/how-edit-your-macs-hosts-file-and-why-you-would-want' title="How to edit your Mac's Hosts file, and why you would want to"><img src='http://www.imore.com/sites/imore.com/files/styles/large/public/field/image/2014/09/hosts_command_line.jpg?itok=i4m5GS6g' />[/url]</p> <p>You're now in the Nano text editor. You should see something that looks like this:</p> <p><a href='http://www.imore.com/how-edit-your-macs-hosts-file-and-why-you-would-want' title="How to edit your Mac's Hosts file, and why you would want to"><img src='http://www.imore.com/sites/imore.com/files/styles/large/public/field/image/2014/09/hosts_nano_editor.jpg?itok=rrv_Tler' />[/url]</p> <p>If you want to add a new device or domain, move the cursor using the cursor keys and position it after the text you see, then begin typing. If you're mapping a particular IP address on your local network to a domain, you can type the IP address, hit <strong>tab</strong>, then type the domain name.</p> <p>Conversely, if you'd like to make sure a web URL doesn't go to its intended site — if you're trying to keep your Mac away from certain sites, use "127.0.0.1." That'll map it back to your Mac. Even if your Mac is assigned a different IP address by its router, 127.0.0.1 defaults to the local machine thanks to the default settings in that hose file.</p> <p>Once you're done, hold down the <strong>control</strong> and <strong>O</strong> keys to save the file, then <strong>control</strong> and <strong>X</strong> to exit.</p> <p>Back at the command line, type <tt>sudo killall -HUP mDNSResponder</tt> then type <strong>return</strong>. That will flush your Mac's DNS cache, so it doesn't get confused by any changes you've made to the Hosts file.</p> <p>Don't forget you've modified the Hosts file, because at some point you may need to undo the changes you've made in order to keep your Mac working right.</p> <p>Have any questions? Let me know.</p> </div></div></div><div id="comment-wrapper-nid-26745"></div><img width='1' height='1' src='http://tipb.com.feedsportal.com/c/33998/f/616881/s/3e261ad6/sc/4/mf.gif' border='0'/><br clear='all'/> <a href="http://da.feedsportal.com/r/206157452942/u/49/f/616881/c/33998/s/3e261ad6/sc/4/rc/1/rc.htm" rel="nofollow"><img src="http://da.feedsportal.com/r/206157452942/u/49/f/616881/c/33998/s/3e261ad6/sc/4/rc/1/rc.img" border="0"/>[/url] <a href="http://da.feedsportal.com/r/206157452942/u/49/f/616881/c/33998/s/3e261ad6/sc/4/rc/2/rc.htm" rel="nofollow"><img src="http://da.feedsportal.com/r/206157452942/u/49/f/616881/c/33998/s/3e261ad6/sc/4/rc/2/rc.img" border="0"/>[/url] <a href="http://da.feedsportal.com/r/206157452942/u/49/f/616881/c/33998/s/3e261ad6/sc/4/rc/3/rc.htm" rel="nofollow"><img src="http://da.feedsportal.com/r/206157452942/u/49/f/616881/c/33998/s/3e261ad6/sc/4/rc/3/rc.img" border="0"/>[/url] <img src="http://da.feedsportal.com/r/206157452942/u/49/f/616881/c/33998/s/3e261ad6/sc/4/a2.img" border="0"/> (http://da.feedsportal.com/r/206157452942/u/49/f/616881/c/33998/s/3e261ad6/sc/4/a2.htm)<img width="1" height="1" src="http://pi.feedsportal.com/r/206157452942/u/49/f/616881/c/33998/s/3e261ad6/sc/4/a2t.img" border="0"/><img src="http://feeds.feedburner.com/~r/TheIphoneBlog/~4/1PDAsNMtVuU" height="1" width="1"/> Source: How to edit your Mac's Hosts file, and why you would want to (http://feedproxy.google.com/~r/TheIphoneBlog/~3/1PDAsNMtVuU/story01.htm) |