Why GCP overrides my /etc/resolv.conf file and how to avoid it?
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.
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
.Remove the
/etc/resolv.conf
file:# rm /etc/resolv.conf
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
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:
-
Edit "/etc/dhcp/dhclient.conf"
-
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.
-
Save the file
-
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.