every time I connect to internet the DNS servers in /etc/resolv.conf were changed.
(for instance, I setup them by manual to 8.8.8.8, but will be auto-changed to 192.168.0.1 etc).
do you know how to stop this change?
I am using DSL router for connection to internet.
Thanks.
Comments
Just
chattr +i /etc/resolv.conf
?For domain registrations, create an account at Dynadot (ref) and spend $9.99 within 48 hours to receive $5 DynaDollars!
Looking for cost-effective Managed/Anycast/DDoS-Protected/Geo DNS Services? Try ClouDNS (aff).
Sorry, but this is not the appropriate or correct solution to change the DNS settings on a Mac. One major issue is that the "chattr" command is not installed by default on macOS. (macOS is based on freeBSD Unix, not Linux). Another major issue is that /etc/resolv.conf is rarely used for DNS on a Mac; there are other mechanisms. The /etc/resolv.conf file reads: "Mac OS X Notice - This file is not used by the host name and address resolution or the DNS query routing mechanisms used by most processes on this Mac OS X system. - This file is automatically generated."
The correct solution is to change the DNS setting in the GUI. Use the System Preferences - > Network panel. Here is the procedure.
PROCEDURE TO CHANGE DNS SETTINGS ON MAC
* You must be logged in with Administrator privileges or have the admin account name and password.
* Open the System Preferences application. It looks like a "control panel".
* Click on the Network icon.
* If you have more than one Location, choose the Location you want to change in the pulldown menu at the top. (NOTE: You may choose a different DNS configuration for each different Location.)
* Click the Advanced button in the lower right corner of the panel.
* A dialog box will appear.
* Click on the DNS tab.
* Add and remove DNS servers according to your own desired settings. Options vary slightly depending on which version of macOS you are running and whether you have a manually entered IP address or use DHCP.
NOTE: You can have multiple Locations. I have separate Location settings for many uses. Here are my location settings.
EXAMPLE LOCATIONS FOR MULTIPLE USES
* Automatic - the default. I kept it, but never use it.
* Disabled - When I want the Mac completely disconnected from the network.
* Home Dock Ethernet 231 - When the Mac is on my desk, connected to the dock, which has built-in Ethernet. The IP address ends in x.x.x.231. Keeping the IP address assignment in the Location name helps me remember.
* Home Dongle Ethernet 231 - When the Mac is connected to the home network via the Apple Ethernet dongle. The IP address ends in x.x.x.231. Keeping the IP address assignment in the Location name helps me remember.
* Home WiFi 241 - WiFi IP address ends in x.x.x.241. Keeping the IP address assignment in the Location name helps me remember.
* Initial Setup - When you need to talk directly to a network device to configure it. Typical IP address is set to 192.168.0.2.
* Phone USB (Cell Data) - When using cell data for an internet connection.
* Wired Dongle Ethernet DHCP - When at customer sites connected directly to their network. When at family and friends places, helping them configure or fix their network or equipment.
* Wireless WiFi DHCP - When at customer sites, visiting family or friends, coffee shop, etc. This is the typical way most people use laptops and phones.
Note: Having your WiFi and Ethernet IP address assignments 10 apart makes it easier to identify dual Ethernet and WiFi devices on the network. Like Wired Ethernet .230-.239 and WiFi .240-.249.
Yeah I don't use a Mac but locking the resolv.conf file was the first thing that came to mind when OP said that the file kept on updating.
Maybe it should've been chflags.
Anyways, maybe worth to just push out the desired NSes via the router through DHCP?
For domain registrations, create an account at Dynadot (ref) and spend $9.99 within 48 hours to receive $5 DynaDollars!
Looking for cost-effective Managed/Anycast/DDoS-Protected/Geo DNS Services? Try ClouDNS (aff).
Adding later:
I am currently running an older macOS on my computer. The /etc/resolv.conf file contains the text I posted above.
-> There is a command line tool for configuring DNS on a Mac. I did not know about it until now. I just checked the /etc/resolv.conf file in macOS 12 Monterey, and the text is slightly different:
#
# macOS Notice
#
# This file is not consulted for DNS hostname resolution, address
# resolution, or the DNS query routing mechanism used by most
# processes on this system.
#
# To view the DNS configuration used by this system, use:
# scutil --dns
#
# SEE ALSO
# dns-sd(1), scutil(8)
#
# This file is automatically generated.
The references to the "scutil --dns" command and the "dns-sd(1)" and "scutil(8)" man pages were not mentioned on my older macOS. The command and man pages exist on the older system, but nothing is said about them in /etc/resolv.conf.
Hello
regards.
So when you set the DNS server in System Preferences -> Network -> Wifi/Ethernet -> Advanced -> DNS, you're saying they change everytime you reconnect?
yes it changes to the default ones. but I want them to be custom ones such as google's.
Locking the file (setting
uchg
flag) didn't prevent GUI from overwriting/etc/resolv.conf
?If you add your own, they shouldn't be overwritten by DHCP ... 🤷
yes this setting can't stop it be changed again.
-rw-r--r-- 1 root daemon schg 372 4 5 15:10 /var/run/resolv.conf
schg != uchg ...
I have changed to this one:
-rw-r--r-- 1 root daemon uchg 372 4 5 15:10 /var/run/resolv.conf
hope it get good result. Thank you.