Help Center
How to Modify the Hosts File in Windows, Linux, and macOS
Introduction
This tutorial will guide you through the steps to modify the hosts file in Windows, Linux, and macOS to direct a domain to a specific IP address. This is a useful technique for web development testing, blocking websites, or redirecting network traffic.
What is the Hosts File?
The hosts file is a plain text file used by operating systems to map domain names to IP addresses.
Modifying the Hosts File in Windows
-
Open Notepad as Administrator:
- Right-click on the Notepad icon and select "Run as administrator."
-
Open the Hosts File:
- In Notepad, go to File -> Open.
- Navigate to
C:\Windows\System32\drivers\etc
. - Select "All Files" as the file type and open the hosts file.
-
Modify and Save:
- Add the line
desired_IP domain_name.com
. - Save the changes.
- Add the line
Modifying the Hosts File in Linux
-
Open a Terminal:
- Use the shortcut Ctrl+Alt+T or search for "Terminal" in your applications.
-
Edit with Privileges:
- Type
sudo nano /etc/hosts
and press Enter (it may ask for your password).
- Type
-
Modify and Save:
- Add the line
desired_IP domain_name.com
. - Save with Ctrl+O and exit with Ctrl+X.
- Add the line
Modifying the Hosts File in macOS
-
Open Terminal:
- Go to Applications -> Utilities -> Terminal.
-
Edit the File:
- Type
sudo nano /etc/hosts
and press Enter (enter your password if prompted).
- Type
-
Modify and Save:
- Add the line
desired_IP domain_name.com
. - Save with Ctrl+O and exit with Ctrl+X.
- Add the line
Final Considerations
- After modifying the hosts file, you may need to restart your browser or clear the DNS cache for the changes to take effect.
- Be careful when modifying the hosts file, as mistakes can prevent access to certain websites.
Related articles
- Screen command in CentOs: more efficient sessions
- Solution: 'Service Unavailable' on CloudLinux servers
- Database export via command line
- Protect your data: configure RAID notifications with S.M.A.R.T.
- List CronJobs for all cPanel users
- Delete unnecessary files from the /tmp partition
- Change reserved disk space in CentOS
- Know your hardware: get accurate information on CentOS 7
- Basic SSH commands
- Optimize accounts with manual rearrange
- IP blocking in CSF via command line
- Clear DNS cache: solution to resolution problems
- Change file permissions via command line
- How to open and close ports using CSF in WHM?
- How to Use Telnet to Test SMTP Connectivity on Port 25
- Adjusting reserved space on Linux disks
- Adjusting reconstruction speed in RAID on Linux
- Where are NGINX logs stored?
- Configuring RAID failure notifications with mdadm
- Differences between Legacy VPS and Cloud VPS
- Install cPanel in your server or VPS
- How to send emails via SSH?
- Manage screen session