How to use the "hosts" file?
1. hosts file
The hosts file is a file that is available on Windows, Linux, and Mac OS operating systems. It is used to map a domain name to an IP address. But it only works on that computer.
To be easy to understand, we give a situation. You have a website and are deploying it on a server that has an IP address of 1.2.3.4, and you can access it via IP:
You want to use abc.com domain name (or any) to access your website instead of IP. You need only to configure the hosts file and you will get what you want. Of course it only works on your computer.
2. Windows
No ADS
On the Windows, open the file:
- C:\Windows\System32\drivers\etc\hosts
Add a Configuration Snippet :
C:\Windows\System32\drivers\etc\hosts
1.2.3.4 abc.com
1.2.3.4 mydomain.com
In case, your website is being deployed on the computer you are working on, you can access it via localhost or configure the hosts file as follows:
C:\Windows\System32\drivers\etc\hosts
127.0.0.1 localhost
127.0.0.1 abc.com
3. Linux (Ubuntu,...)
For the Linux operating system, the hosts file has the full path:
- /etc/hosts
Way of configuring the hosts file in this operating system is the same as that in Windows. However, you need to know commands to edit the contents of the file.
1- Open Terminal window.
2- Execute the following command:
2- Execute the following command:
sudo nano /etc/hosts
3 - Add the configuration snippet:
1.2.3.4 abc.com
1.2.3.4 mydomain.com
4 - Click Ctrl + X to save changes.
4. Mac OS
No ADS
For the Mac OS operating system, the hosts file has the full path:
- /private/etc/hosts
Way of configuring the hosts file in this operating system is the same as that in Windows. However, you need to know commands to edit the contents of the file.
1- Open Terminal window (Applications -> Utilities -> Terminal).
2- Execute the following command:
2- Execute the following command:
sudo nano /private/etc/hosts
3 - Add the following configuration snippet to the end of the file:
1.2.3.4 abc.com
1.2.3.4 mydomain.com
4 - Click Ctrl + X to save changes
No ADS
Mac OS Tutorials
- Install Mac OS X 10.11 El Capitan in VMWare
- Install Mac OS Virtual Machine in VirtualBox
- Upgrade Mac Operating System
- Install Java on Mac OS
- Install VirtualBox on Mac OS
- How to use Windows-like shortcuts in Mac OS Virtual Machine
- Lightshot - Screenshot tool for Mac and Windows
- How do I take a MacOS Retina screenshot and get the image at its actual size?
- Microsoft Remote Desktop for Mac OS
- Transfer files between computers using Cyberduck on Mac OS
- Connect to the Server with Terminal on Mac OS
- How to use the "hosts" file?
- Are There Ways to Improve Gaming Experience on a Macbook?
- Mac Keyboard Shortcut List to Improve Efficiency
- Install FFmpeg on Mac OS
- How to open Terminal on Mac OS
- Setup environment variables on Mac Os
- Create executable files for Terminal scripts on Mac OS
Show More
Ubuntu Tutorials
- Install GParted hard drive partition software on Ubuntu
- Install Ubuntu Desktop in VmWare
- Install Ubuntu Desktop on VirtualBox
- Create a Launcher (Shortcut) for a program in Ubuntu
- Install Ubuntu Server in VmWare
- Install GUI and VNC for Ubuntu Server
- Install OpenSSH Server on Ubuntu
- The softwares create note windows on Desktop for Ubuntu
- Install TeamViewer on Ubuntu
- Peek: Animated GIF Screen Recorder Software for Ubuntu
- Install GUI and Remote Desktop for Ubuntu Server
- Transfer files between computers using Cyberduck on Mac OS
- How to use the "hosts" file?
- Install Firefox Browser on Ubuntu
- Redirect port 80, 443 on Ubuntu using iptables
- Use WinSCP to transfer files between Computers
- Use Top Command - Task Manager for Ubuntu
- Check Internet Speed with speedtest-cli on Ubuntu
- Install Winrar on Ubuntu
- Install xChm Viewer to read the CHM file on Ubuntu
- Install FFmpeg on Ubuntu
- Setup environment variables on Ubuntu
Show More