If you add dns to the /etc/resolv.conf file to restart or switch the network, it will be overwritten;
Solution:
Modify /etc/network/interfaces
For example: vim /etc/network/interfaces
Add a rule: eg dns-nameservers 1.1.1.1
This method will automatically add nameserver 1.1.1.1 to resolv.conf after restarting