# Manually edit /etc/resolv.conf

## donjames

Hi,

I have noticed that something in the system automatically resets the /etc/resolv.conf file.

Can someone tell me how to turn off the automatic reset so that I can enter the nameservers of my choice and not have them over written by the system?

I may have found the answer:

Add to the end of /etc/dhcpcd.conf

nohook resolv.conf

Thanks,

Don JamesLast edited by donjames on Thu Sep 03, 2020 11:50 pm; edited 1 time in total

----------

## mike155

Do you use DHCP? DHCP clients overwrite /etc/resolv.conf - unless you tell them not to do that.

----------

## Ionen

Some init scripts have support to add wanted nameservers in their configs and then will edit resolv.conf using those. Some other stuff will use things like /etc/resolv.conf.head for merging.. well there's a lot of network management systems / dhcp implementation and it's hard to tell without more info.

Personally I use static entries only (with openrc's newnet) and no dhcp, so resolv.conf never changes and only uses local nameserver (dnsmasq). Not that it means you should do the same.

----------

## donjames

 *mike155 wrote:*   

> Do you use DHCP? DHCP clients overwrite /etc/resolv.conf - unless you tell them not to do that.

 

Yes, I use dhcp.

----------

## Tony0945

/etc/resolv.conf get overwritten, but with the namerservers I want:

```
$ cat  /etc/conf.d/net

# copied from central server, DHCP version

#config_eth0="dhcp"

dhcp_eth0="nodns"

config_eth0="192.168.0.104 netmask 255.255.255.0 "

mtu_eth0="1500"

dns_servers="127.0.0.1 192.168.0.102 1.1.1.1 198.192.0.1"

#dns_domain_lo="workgroup"

routes_eth0="default via 192.168.0.1"

```

```
 $ cat /etc/resolv.conf

# Generated by net-scripts for interface eth0

nameserver 127.0.0.1

nameserver 192.168.0.102

nameserver 1.1.1.1

nameserver 198.192.0.1

```

----------

## UberLord

Many things try to control /etc/resolv.conf - DHCP, PPP, VPN, etc.

Most well behaved applications do this via resolvconf(8).

openresolv is a resolvconf implementation in portage which allows a fine graned control of how updates to this file should be handled.

If don't want resolvconf and just want a never changing file, then just make it immutable and nothing can ever change it.

----------

## donjames

 *UberLord wrote:*   

> Many things try to control /etc/resolv.conf - DHCP, PPP, VPN, etc.
> 
> Most well behaved applications do this via resolvconf(.
> 
> openresolv is a resolvconf implementation in portage which allows a fine graned control of how updates to this file should be handled.
> ...

 

Hi,

openresolv is not installed on my system.  It is using udev.  Should I install openresolv?

Where would resolvconf be located?

donjames

----------

## UberLord

resolvconf is normally in /sbin

udev has nothing to do with resolv.conf to the best of my knowledge.

----------

## figueroa

If you want to override everything without undoing all those other things and ensure your /etc/resolv.conf doesn't get changed, make it immutable:

```
chattr +i /etc/resolv.conf
```

If and when you need to reverse that, do:

```
chattr -i /etc/resolv.conf
```

----------

