0

On Google Cloud Platform /etc/resolv.conf file being overridden every time I do sudo systemctl restart NetworkManager.service or I restart the machine.

Is there a "correct" way to avoid it? or shall I write a script on startup which overrides it back?

Boppity Bop
  • 722
  • 3
  • 11
  • 29
  • Does this answer your question? [Why my local DNS is not used?](https://serverfault.com/questions/1051179/why-my-local-dns-is-not-used) – Adil Jan 25 '21 at 20:53
  • no adil it is my question but it is different. thanks for reading it before trying to close this one NOT – Boppity Bop Jan 25 '21 at 20:55
  • 1
    Probably relevant: https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/8/html/configuring_and_managing_networking/manually-configuring-the-etc-resolv-conf-file_configuring-and-managing-networking – Håkan Lindqvist Jan 26 '21 at 01:15
  • @HåkanLindqvist this is it! i fixed it :) please write it as an answer – Boppity Bop Jan 26 '21 at 15:28

3 Answers3

2

Following Håkan Lindqvist comment I used symbolic link from paragraph 29.2

https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/8/html/configuring_and_managing_networking/manually-configuring-the-etc-resolv-conf-file_configuring-and-managing-networking

NetworkManager does not automatically update the DNS configuration if /etc/resolv.conf is a symbolic link. This section describes how to replace /etc/resolv.conf with a symbolic link to an alternative file with the DNS configuration.

  1. Create a file, such as /etc/resolv.conf.manually-configured, and add the DNS configuration for your environment to it. Use the same parameters and syntax as in the original /etc/resolv.conf.

  2. Remove the /etc/resolv.conf file:

    # rm /etc/resolv.conf
    
  3. Create a symbolic link named /etc/resolv.conf that refers to /etc/resolv.conf.manually-configured:

    # ln -s /etc/resolv.conf.manually-configured /etc/resolv.conf
    
Michael Hampton
  • 237,123
  • 42
  • 477
  • 940
Boppity Bop
  • 722
  • 3
  • 11
  • 29
1

The resolv.conf options are renewed every 24 hours for global DNS, as per this official documentation. It is also possible to modify the values, by editing the DHCP Policy.

For Debian 10, Here are the steps:

  1. Edit "/etc/dhcp/dhclient.conf"

  2. Uncomment the line "supersede domain name", and modify the values of it: supersede domain-name "asdf.v1.com";

    NOTE: supersede will use only your provided details, prepend will use first your values then the server-provided ones, and append will use first the server-provided values, and then your custom ones.

  3. Save the file

  4. Restart the DHCP client with the command "sudo dhclient -v -r"

Please keep in mind that these steps might not work for other distributions, make sure to backup and review the steps before performing them.

Alex G
  • 315
  • 1
  • 7
  • why are you talking about dhcp? i use static address. question is - why the file is overriden by GCP. nothing to do with 24hrs. – Boppity Bop Jan 26 '21 at 15:18
  • @BoppityBop - even though you are using static IP addresses, DHCP is how Google Cloud sets up items like DNS. Note: for Zonal DNS, resolv.conf is overwritten every hour. So yes, 24 hours is correct and applies even to static IP address configurations. This answers recommendation to modify `/etc/dhclient.conf` is correct. – John Hanley Jan 26 '21 at 21:41
  • The issue has been resolved following Hackan link. – Boppity Bop Jan 26 '21 at 23:57
1

You can tell NetworkManager not to modify some of the /etc/resolv.conf entries by making changes to the file /etc/NetworkManager/NetworkManager.conf.

For instance, GCP uses the metadata sever, IP address 169.254.169.254 as the default name sever. You can override the nameserver entry of resolv.conf by following below steps -

  1. Add dns=none entry to /etc/NetworkManager/NetworkManager.conf file as below -
 [main]
 #plugins=ifcfg-rh
 dns=none
  1. Restart NetworkManager service
sudo systemctl restart NetworkManager.service
  1. Modify /etc/resolv.conf with your custom nameserver
nameserver 127.0.0.1

After making these changes, restarting NetworkManger should not override your custom entry.

Daniel t.
  • 9,061
  • 1
  • 32
  • 36