# prevent /etc/resolv.conf from overwritten by dhcpcd

## yufw

I use pptpclient to connect to VPN, since I have enabled the 'usepeerdns' option for pptpclient, when the ppp0 interface is on, it will copy /etc/ppp/resolv.conf to /etc/resolv.conf. However, every several hours or so, /etc/resolv.conf gets overwritten by dhcpcd.

I want to use the peer supplied DNS when I connect to VPN, so how to prevent /etc/resolv.conf from overwritten by dhcpcd?

----------

## saivinoba

I don't know if I understand the problem but will disabling dhcpcd help?

----------

## ulenrich

 *yufw wrote:*   

> , /etc/resolv.conf gets overwritten by dhcpcd.

  Create an /etc/resolv.conf.head with entries you want to keep staying!

----------

## Jaglover

DHCP clients can be configured to do certain tasks only. Disable pulling DNS and it will not overwrite your resolv.conf.

----------

## szatox

If you're happy with completly static resolv.conf, you can `chattr +i /etc/resolv.conf`

I don't say this solution is perfect, but it's fast, generic, and contents of that file will not change, no matter what, until you remove this flag.

----------

## khayyam

yufw ....

simply configure dhcpcd to not run the resolv.conf 'hook'

/etc/dhcpcd.conf

```
nohook resolv.conf
```

or add the following to /etc/conf.d/net (openrc)

```
dhcpcd_ppp0="--nohook resolv.conf"
```

or similarly via the cmdline ...

```
# dhcpcd --nohook resolv.conf <iface>
```

see 'man dhcpcd' '-C, --nohook'

best ... khay

----------

## yufw

Thank you all for so many replies. I think I will take khay's advice because it is the most natural solution to me.

----------

## UberLord

I propose another solution - resolvconf to manage this for you, assuming your VPN supports it.

openresolv is an implementation in Gentoo.

----------

