Hosts For Mac



The /etc/hosts file on the Mac can be hard to find. Here are some tips for finding and editing it, and what you can do with it.

Where is the /etc/hosts file in Mac OS X?

QEMU on OS X (macOS) hosts. While QEMU's main host platform is Linux, it is also supported on operating systems for Apple's Mac computers (known as OS X or macOS).The official support policy covers the last two released versions of OSX; QEMU might work on older versions, but it is not guaranteed and it might not even compile on older versions.

The hosts file used by Mac OS X is in /etc/. Windows users sometimes have problems finding it since there’s no %SystemRoot%system32driversetc folder in the Mac OS. UNIX users might not expect /etc/ to be hidden by the Mac OS X Finder, so they often look in /Library/Application Support/.

  1. Backups of your hosts file is made in /Library/Application Support/Hosts. The backup or your hosts file from before you started using Hosts.prefpane is called hosts.orig and each session a backup.
  2. TeamViewer Host. TeamViewer Host is used for 24/7 access to remote computers, which makes it an ideal solution for uses such as remote monitoring, server maintenance, or connecting to a PC or Mac in the office or at home. Install TeamViewer Host on an unlimited number of computers and devices. As a licensed user, you have access to them all!
  3. Feb 03, 2020 On most.nix variants as well as on the Mac, it will also display the value of the replies’ TTL field, giving an indication of the number of hops between source and destination. For ping to work, the pinged host must abide by RFC 1122 which specifies that any host must process ICMP echo requests and issue echo replies in return.

Accessing /etc/hosts

/etc/ is hidden by default in the Finder. The easiest way of getting to the mac hosts file is to open /Applications/Utilities/Terminal.app. Then type:
sudo nano /etc/hosts

…you will need to type in your password. Your hosts file will open in the text editor nano.

Why ‘sudo nano’?

The hosts file, in addition to being hidden, is also protected by the system. Using sudo makes the editor nano run as a super-user, which makes editing the file possible.

Adding entries to the /etc/hosts file on Mac

In nano, on a new line type the IP Address followed by at least one space or tab and then the hostname. Examples:
127.0.0.1 mydevsite.local
192.168.1.222 ads.shadycompany.biz

…hit ctrl + o to Save, and then ctrl + x to Quit the text editor.

Background: What is /etc/hosts used for?

The hosts file is a simple way of mapping IP Addresses to hostnames. It overrides mappings provided by the Domain Name System network. The hosts file is commonly used by network administrators to provide access to LAN resources when no name resolution is available. The other common usage is to block access to specified hosts by adding host entries resolving them to — for example — 127.0.0.1.

Another use for the hosts file is for easily allowing your Mac to run multiple virtual servers, mainly useful for web developers. See here for more about using /etc/hosts for Virtual Servers: Adding an entry to /etc/hosts on OS X.

More Resources:
http://en.wikipedia.org/wiki/Hosts_(file).

If you find this page useful, check out my ebook. It contains an overhauled version of the hosts file info here, plus useful stuff to do with the Mac Terminal, bash, AppleScript, and Automator. Get to grips with the Mac Terminal and scripting tools now. More Info >

System cleanup in one click
Make your Mac fast and secure with CleanMyMac X.
Hosts For MacHosts for mac app

If you use your Mac every day, you know how seamless and intuitive the experience can be. It’s almost akin to play: dragging and dropping icons and files, and having the whole environment neatly arranged.

Despite the apparent ease of use, Macs are highly capable machines that could really open up their programmatic side and let you control them right from your keyboard. All this is because macOS is based on the Unix system, just like Linux and many others that are known for providing much greater levels of control compared to more closed systems, such as Windows.

Control over Mac’s performance with Setapp

And that’s only part of what Setapp does for you. A single toolkit with 180+ apps enables your macOS to work seamlessly.

Why is having a more open system such a big deal? Simply, controlling macOS programmatically speeds up lots of everyday tasks and reveals lots of functionality that is otherwise completely inaccessible through a regular graphic interface. You might have even already used the key Unix-like tool in your Mac’s arsenal — Terminal.

Terminal allows you to perform nearly every function you normally use your mouse for: navigate folders, change preferences and settings, execute commands, etc. One of the unique tasks that can be easily controlled through Terminal is configuring your Mac’s Hosts file.

What And Where Is Hosts File On Mac

Hosts file is a hidden gem on your Mac that lets you override DNS settings exactly as specified. Let’s elaborate. Any website on the internet has a standard numeric TCP/IP address (e.g. 155.135.55.81) — that’s how your browser is actually able to find the website you want. However, no one would ever want to remember all those TCP/IP numbers, and that’s why the Domain Management System (DNS) was created.

Every time you put in a URL in your browser (e.g. setapp.com), it pings the domain server, which in turn translates the requested domain into the TCP/IP format, and only then connects as to be able to display it.

Having said that, there are instances when you don’t want the domain name to go to the actual TCP/IP, but would much rather write down your own. This can be necessary when you want to test a new website you’re developing locally, or a new development server altogether. You can also use Hosts file on Mac to block adware and spyware websites, and even some time-wasting ones (e.g. social media).

Now let’s discover how we can actually change Hosts file on Mac.

How to edit Hosts file on Mac

To edit Hosts file Mac features is not a difficult although completely non-obvious process. To open Hosts file on Mac, which is hidden, you need to use Terminal:

  1. Launch Terminal
  2. Type sudo nano /etc/hosts and press Return
  3. Enter your admin password

Now you’ll notice you’re in the Nano text editor, from where you can actually edit Mac’s Hosts file. As you can see, some of the TCP/IP addresses are already reflected in here against localhost and broadcasthost titles. All you need to do to input your own TCP/IP is to follow the same format:

  1. Use the Return key to create some space below the existing records
  2. Type in the TCP/IP address
  3. Press the Tab key
  4. Enter the domain name
  5. Save the file by pressing Ctrl + O
  6. Exit with Ctrl + X
  7. In Terminal, type sudo killall -HUP mDNSResponder followed by Return to clear your Mac’s DNS cache and prevent any clashes between DNS and the Hosts file

The changes should take effect immediately. Using the Mac Hosts file this way you can literally input any TCP/IP you need, from other websites to your own development server to your Mac (just type in 127.0.0.1), which can be useful when you want to avoid using social media or other distractions. You could also outright block malicious websites with a 0.0.0.0 address.

When adding multiple entries, make sure each one has its own line. To cancel the change, repeat the process above but simply delete the line you’ve added before that is no longer needed.

Fix a malfunctioning Mac Hosts file

Sometimes when you add too many entries to your Hosts file Mac might not process them correctly. It could be that some of the TCP/IP addresses are responding to the same domain name or you’ve deleted some other essential information.

To resolve the situation, you could try following the instructions above to get to the Nano text editor and then delete everything there and retype the default configuration:

##

# Host Database

#

#

# localhost is used to configure the lookback interface

# when the system is booting. Do not change this entry.

##

127.0.0.1 localhost

Hosts For Mac

255.255.255.255broadcasthost

::1localhost

While this might or might not work, there is a better preventative way of making sure you don’t end up somehow crushing your system — creating consistent backups.

Keep your files safe with Disk Drill

Hosts For Mac

No chance you can damage your system. With Disk Drill, you’ll be able to instantly schedule backups and recover files.

Disk Drill is the top-rated data recovery and backup tool. It lets you effortlessly back up files to any external drive, so you always have a copy of your information on hand.

If you don’t have enough space on your external disk to duplicate your hard drive and just want to protect your Mac Hosts file, you can simply duplicate it in its original state, before making any changes.

To locate the Hosts file on Mac:

  1. Select Go ➙ Go to Folder… from the Mac menu bar
  2. Type in /private/etc/hosts
  3. Click Go

You should end up within the 'etc' folder and have the Mac Hosts file highlighted. Just copy the document onto an external hard drive using Disk Drill and then you can confidently experiment with the Hosts file without the fear of breaking anything.

If however the problem has already occurred, Disk Drill can try to recover your file using its recovery mode. To give it a try, launch Disk Drill and click Recover next to your Macintosh HD.

Protect your daily internet presence

When your sole purpose for tinkering with the Hosts file on Mac is being haunted by adware, spyware, or something of that type — relax — there’s a much better way to get rid of those intruders.

Secure Mac against any issues with CMM X

Detect and remove malware or get rid of caches, CleanMyMac X will help you solve every Mac problem in minutes.

CleanMyMac X is an all-in-one optimization utility that easily detects and deletes malware from your Mac. Just select Malware Removal scan from the sidebar and CleanMyMac X would find any malicious files on your computer in seconds.

Besides, CleanMyMac X makes it easy to flush DNS cache (without using Terminal), as well as clear browser cache, run maintenance scripts, and effortlessly keep your Mac in top shape overall. Just start with a quick Smart Scan and every now and then go through a variety of optimization tests, which are located in the sidebar, and simply follow the instructions.

As you can see, you have a few options to find and edit Mac’s Hosts file. Feel free to follow the guide above and experiment with various TCP/IP settings to check your development server or block undesired websites.

Also remember that not everything has to be done through the Mac Hosts file. In fact, treat it as the last resort and try to rely more on using intuitive software like CleanMyMac X when it comes to optimizing your browser and removing malware. And if you absolutely have to use the Hosts file, make sure you properly back up your Mac with Disk Drill, so you can recover your Hosts file if things go awry.

Best of all, you can try both CleanMyMac X and Disk Drill for free through Setapp, a widely popular Mac platform with more than 150 apps across dozens of categories. Now that you’ve been warned and prepared, go get your Hacker Mode on!

Setapp lives on Mac and iOS. Please come back from another device.

Hosts Mac Port

Meantime, prepare for all the awesome things you can do with Setapp.

Read on

Sign Up

Setapp uses cookies to personalize your experience on our website. By continuing to use this site, you agree to our cookie policy.

Host For Mac