# dhcdpcd overwrites /etc/resolv.conf generated by openvpn

## n3bul4

Hey guys,

this is kinda annoying.

I configured openvpn to connect to my office.

Everything is working as expected and the server pushes DNS, DOMAIN etc to my openvpn client.

However every time openvpn generates the new /etc/resolv.conf file it is immediately overwritten by dhcpcd.

I verified that by doing a 

```

tail -f /etc/resolv.conf

```

I also tried with /sbin/resolvconf and installed it as I thought, that maybe then this behaviour will stop. Sadly with no avail.

Is there a way to prevent dhcpcd from overwriting the /etc/resolv.conf file?

Maybe it should be mentioned that I am using systemd and because of lack of init script for openvpn I issue the openvpn command manually like this:

```

/usr/sbin/openvpn --up ./up.sh --script-security 3 --config rup.conf

```

I also would like to state that using "nodns" in /etc/conf.d/net is no option for me as I would like to have the functionality of dhcpcd to generate the resolv.conf file.

Any help would be appreciated.

Regards,

Alex

----------

## UberLord

dhcpcd will always use resolvconf when available.

OpenVPN should do as well.

I suggest you look at the resolvconf (or resolvconf.conf) man page and find out how to set it up to your liking.

----------

## Anon-E-moose

 *n3bul4 wrote:*   

> Is there a way to prevent dhcpcd from overwriting the /etc/resolv.conf file?

 

 *Quote:*   

> I also would like to state that using "nodns" in /etc/conf.d/net is no option for me as I would like to have the functionality of dhcpcd to generate the resolv.conf file.

 

You want dhcpcd to do two contradictory things?

Either set it up yourself, and tell dhcpcd to leave it alone or let dhcpcd write it every time it starts.

----------

## n3bul4

Thanks for the replies, I will give the manpage of resolvconf a try.

@Anon-E-moose:

I think you misunderstood me. Of course I would like dhcpd to overwrite /etc/resolv.conf when starting.

But only when starting and not every time another process (like openvpn) is generating the file again.

Seems like there is some kind of watchdog process implemented that monitors file changes.

This is really annoying.

Regards,

Alex

----------

## Anon-E-moose

 *n3bul4 wrote:*   

> Thanks for the replies, I will give the manpage of resolvconf a try.
> 
> @Anon-E-moose:
> 
> I think you misunderstood me. Of course I would like dhcpd to overwrite /etc/resolv.conf when starting.
> ...

 

I didn't misunderstand, but AFAIK there is no way to have it write once then not rewrite it.

Well, other than letting it write the first time and then turn it off after it does it that once.

But there's no way to automatically tell it to do that.

I don't run dhcpcd as I went to static addys for my system, but even when I did, I turned off it writing resolv.conf.

It is relatively easy to create one, or look at what's there and modify it as you need. 

Basically it's a list of nameservers (4 max) to check for dns resolving.

Good luck.

----------

## szatox

easy, fast and ugly hack is to define your dns servers and then  run `chattr +i /etc/resolv.conf`

Also, afair dhcpcd can include dns servers from different file in resolv.conf. If you can make your vpn write it's info in different location it should do the trick.

On the other hand, why do you even bother? what's the difference who provides you with DNS data?

----------

## toralf

You might have a look into /lib/dhcpcd/dhcpcd-hooks/20-resolv.conf

----------

