Host file modification method: 1. Right-click the text editor icon and select Run as administrator; 2. Locate the path of the Host file and open the file; 3. In the opened Host file, find an empty line or a line starting with #. In a new line, enter the mapping relationship between the IP address and the host name, separated by spaces or tabs; 4. When saving the Host file, select "Save as administrator" to ensure modifications It will take effect; 5. Close the text editor and restart the browser to make the modified Host file take effect.
The host file is a text file in an operating system that is used to map domain names to corresponding IP addresses for network connection. When the user enters a domain name in the browser, the operating system will first check whether a record of the domain name exists in the host file. If it exists, it will directly resolve the domain name to the corresponding IP address and then connect.
The host file is usually located in the system directory of the operating system. The specific path is as follows:
- Windows system: C:\Windows\System32\Drivers\etc\hosts
- Mac system: /private/etc/hosts
- Linux system: /etc/hosts
However, accessing the host file may require administrator privileges, so you need to use administrator status when editing the host file Run the text editor. The following are the steps to edit the host file on different operating systems:
Edit the host file on the Windows system:
1. Open a text editor (such as Notepad), right-click the icon, and select "Run as administrator".
2. In a text editor, select File->Open and navigate to the C:\Windows\System32\Drivers\etc directory.
3. Select "All Files" in the drop-down file type list, and then select the hosts file.
4. Add or modify the required domain name and corresponding IP address at the end of the hosts file.
5. Save the file and close the text editor.
Edit the host file on Mac system:
The Host file is a text file on the local computer that is used to store the mapping relationship between IP addresses and host names. Modifying the Host file can be used to implement some useful functions, such as directed website access, blocking ads, etc. This article will introduce how to modify the Host file and its functions.
Part 1: What is a Host file
The Host file is a local file of the operating system, which stores the mapping relationships between some commonly used IP addresses and host names. When the computer accesses the website, it will first check whether the corresponding IP address exists in the Host file. If it exists, it will access the IP address directly; if it does not exist, it will obtain the corresponding IP address through the DNS server. The Host file is located in the system directory of the computer, and its path is as follows:
Windows system: C:\Windows\System32\drivers\etc\hosts
Mac system: /etc/hosts
Linux system:/etc/hosts
Part 2: How to modify the Host file
Modifying the Host file is very simple, just follow the following steps:
1 . First, run the text editor as administrator. In Windows, right-click the text editor icon and select "Run as administrator"; in Mac, open the terminal and enter sudo nano /etc/hosts command, and then enter the password.
2. Next, locate the path to the Host file and open the file.
3. In the opened Host file, find a blank line or a line starting with #. This is to write a new mapping relationship. Then, in a new line, enter the mapping relationship between the IP address and the host name, separated by spaces or tabs, example: 192.168.1.1 example.com
4. In Windows systems, you may need to select "Save as administrator" when saving the Host file to ensure that the modifications take effect.
5. Finally, close the text editor and restart the browser or other network application to make the modified Host file take effect.
Part 3: Modification of Host file
1. Targeted website access: By modifying the Host file, you can point the domain name of a certain website to other IP addresses, thereby achieving website redirection. For example, you can point the domain names of some advertising or spam websites to the local 127.0.0.1 to block or block access to these websites.
2. Block advertising: Add the mapping relationship between the IP address and host name of the advertising server in the Host file to block advertising content related to the advertising server. This is a simple and effective way to block ads.
3. Deployment within a LAN: In some cases, you may want to point a specific domain name to a local server within the LAN. By modifying the Host file, you can map the domain name to the server IP address in the LAN to access the internal website.
4. Development and debugging: When developing or debugging a website, you can modify the Host file to point a domain name to the development environment deployed on your local computer, thereby avoiding the trouble of accessing the online server.
in conclusion:
Host file is an important local configuration file, which is very useful for implementing some functions such as targeted access, blocking advertisements, and deployment within the local area network. By simply modifying the Host file, we can easily implement these functions. However, be careful when modifying the Host file to ensure that the modified content is correct to avoid unnecessary impact on the computer. .
1. Open the "Terminal" application.
2. Enter the following command and press Enter to open the hosts file:
sudo nano /private/etc/hosts
3. Enter the system administrator password and press Press the Enter key.
4. Add or modify the required domain name and corresponding IP address at the end of the hosts file.
5. Press the "Ctrl" "O" key combination to save the file, and press the "Ctrl" "X" key combination to exit the nano editor.
Edit the host file on a Linux system:
1. Open the terminal application.
2. Enter the following command and press Enter to open the hosts file:
sudo nano /etc/hosts
3. Enter the system administrator password and press Enter Car key.
4. Add or modify the required domain name and corresponding IP address at the end of the hosts file.
5. Press the "Ctrl" "O" key combination to save the file, and press the "Ctrl" "X" key combination to exit the nano editor.
No matter which operating system you edit the host file on, it is important to make sure you back up the file before modifying it. Be careful when editing the host file to avoid accidentally modifying system settings and causing network connection problems.
The above is the detailed content of How to modify the host file. For more information, please follow other related articles on the PHP Chinese website!