Achievable logo
Exam preparation
Lifestyle topics
Achievable blue logo on white background
Achievable blue logo on white background

How to edit your hosts file on Windows, Mac, or Linux

The hosts file is a simple text file that maps hostnames to IP addresses. It can be a powerful tool for network troubleshooting, website development, or even blocking specific websites on your computer. Whether you’re using Windows, Mac, or Linux, here’s a step-by-step guide to editing your hosts file. What is a hosts file? The …
Achievable blue logo on white background
How to edit your hosts file on Windows, Mac, or Linux
Achievable blue logo on white background
Achievable blue logo on white background
Achievable courses
Prepare for your exam with Achievable's comprehensive online courses. Our adaptive learning technology helps you study smarter and achieve your goals.
Online textbook
Chapter quizzes
Practice exams
Laptop displaying the Achievable exam prep dashboard and a smartphone displaying a quiz question

The hosts file is a simple text file that maps hostnames to IP addresses. It can be a powerful tool for network troubleshooting, website development, or even blocking specific websites on your computer. Whether you’re using Windows, Mac, or Linux, here’s a step-by-step guide to editing your hosts file.


What is a hosts file?

The hosts file is part of your computer’s operating system and is used to map IP addresses to hostnames. When you type a website address into your browser, your computer checks the hosts file first to see if you’ve mapped that domain to a specific IP address. If a match is found, your computer uses the IP address in the hosts file to connect to the site. In simpler terms, the hosts file is just a simple way for your computer to find certain websites faster by following the directions it already has written down.


What you’ll need

Before you begin, you’ll need:


  • Administrator access: You must have administrative privileges to edit the hosts file.
  • Text editor: A simple text editor like Notepad on Windows, TextEdit on Mac, or Nano on Linux will do.

Editing the hosts file on Windows

Locate the hosts file:


  • Path: C:\Windows\System32\drivers\etc\hosts

Open the hosts file:


  • Search for Notepad in the Start menu, right-click, and select “Run as administrator.”
  • In Notepad, go to File > Open and navigate to C:\Windows\System32\drivers\etc.
  • Select “All Files” from the dropdown to see the hosts file, then open it.

Edit the hosts file:


  • To block a website, add a new line at the end of the file with the format: 127.0.0.1 http://www.blockedwebsite.com.
  • To redirect a domain, specify the IP address you want it to point to.

Save changes:


  • Save the file, ensuring it remains in the same location and format.

Editing the hosts file on Mac

Gabriel Beaudry / Unsplash / “We’ve moved to a new house so I wanted to share my new home office. (Same setup new location)” / Unsplash license

Locate the hosts file:


  • Path: /etc/hosts

Open the terminal:


  • Open Terminal from Applications > Utilities.

Open the hosts file with a text editor:


  • Use the command: sudo nano /etc/hosts (or use another text editor like vim).

Edit the hosts file:


  • Add or modify entries in the same way as on Windows.

Save changes:


  • Press Control + O to save and Control + X to exit.

Editing the hosts file on Linux

Locate the hosts file:


  • Path: /etc/hosts

Open the Terminal:


  • Access Terminal from your applications menu.

Open the Hosts File with a Text Editor:


  • Use the command: sudo nano /etc/hosts (or vim).

Edit the hosts file:


  • Add or modify entries as needed.

Save changes:


  • Save and close the file with Control + O and Control + X.

Security considerations

Be cautious when editing the hosts file, as incorrect entries can block access to websites or redirect you to malicious sites. Remember to always back up your hosts file before making changes. Simply copy and paste the original content into a new text file as a backup.


Conclusion

Editing your hosts file is a straightforward process that can be incredibly useful for managing network connections and controlling access to websites. Whether you’re using Windows, Mac, or Linux, these steps will guide you through the process safely and effectively. Always proceed with caution and keep a backup of your original hosts file to avoid any issues.


Achievable blue logo on white background
Achievable blue logo on white background
Achievable courses
Prepare for your exam with Achievable's comprehensive online courses. Our adaptive learning technology helps you study smarter and achieve your goals.
Online textbook
Chapter quizzes
Practice exams
Laptop displaying the Achievable exam prep dashboard and a smartphone displaying a quiz question
Achievable blue logo on white background
Achievable logo
Have questions?
Proven success at scale
Partner with Achievable to modernize your training program, increase your pass rates, and help people achieve their professional goals
Enterprise