



For example, The New York Times website returns an IP address of 170.149.172.130. Make note of the IP address that’s returned and use it in your Mac hosts file mapping.

Note: The + short option keeps the output to just the information we need, which is the IP address.Open up terminal and type “ $ dig + short 104.25.27.105“.To dig the site via Terminal, we simply open up Terminal and then run the dig command on URL, which will then return the IP address as output. To determine a website’s IP address, you can use the dig command, which comes standard with macOS. In our case, we want to block Facebook so we’ll map to 0.0.0.0 which, as an invalid IP address, which will result in an error.Īlternatively, you can enter the IP address of a valid site instead of 0.0.0.0, which will result in users attempting to access Facebook being directed to the site of your choosing.To do this, type the IP address you wish to assign, followed by two tabs and the hostname.In our example, we’ll pretend that the computer we’re using is a device that we want to use exclusively for work, not allowing ourselves to get distracted by Facebook on our work machine. In addition to testing newly developed websites and web hosting migrations, another reason to edit the hosts file is to block access to specific websites. To edit the file, you’ll add your own lines after broadcasthost. It also contains default IP values for localhost and broadcasthost. For each line, any text after the pound sign is ignored by the computer, making it a good way to add notes and descriptions to your files. Any line that starts with a # sign is a comment and is not read by the /etc/hosts file.
