Reasons and solutions for MacOS using SwitchHosts to modify hosts does not take effect

Reasons and solutions for MacOS using SwitchHosts to modify hosts does not take effect

After using the switch host to modify the mac hosts, cat found that the hosts have been modified successfully. 

 

 But when I pinged, I found that the ip of domain name resolution is still old.

After reading a lot of information, this is not the case under Windows.

Finally, I found the following consultation on stackoverflow:

This is because macOS Catalina has another thing going; it will only make changes in the hosts file effective if you change them as the root user  !!

my system is

In other words, the modification of the root user is not the default under mac, and may not take effect immediately.

This also explains why the hosts modification is successful, but the local dns still reads the old IP.

 You can see that the modification authority of the hosts file is a local user.

So there are two solutions.

1. Execute sudo killall mDNSResponder to manually refresh the local dns cache.

2. Use the sudo vim hosts command to modify the hosts file.

Guess you like

Origin blog.csdn.net/songkai558919/article/details/127286732