# PBM: dhcpcd periodically overwrites /etc/resolv.conf

## VinzC

Hi.

I think dhcpcd interacts with pptpclient in that it overwites /etc/resolv.conf periodically (probably each time it renews the lease from the local network). This creates a side effect when I'm running a VPN client with option usepeerdns. Actually I'm using pon to start my VPN client... because I've always done that way.

Is there a way to have dhcpcd and pptp VPN coexist nicely? Will it do the trick if I move my VPN definitions into /etc/conf.d/net?

Thanks in advance.

----------

## geowapa

You can change dhcpcd parameters in the network definition by including the following line into the /etc/conf.d/net configuration:

dhcpcd_eth<n>=""

Add the following:

    -R, --nodns

             Don't send DNS information to resolvconf or touch /etc/resolv.conf.

For example, to cause eth2 to 

 - wait 10 seconds for DHCP

 - Don't touch NTP configuration

 - Don't touch DNS config

 - Don't use IPv4 local addressing  (169.x.x.x addresses)

include:

dhcpcd_eth2="-t 10 -N -R -L"

----------

## VinzC

 *geowapa wrote:*   

> You can change dhcpcd parameters in the network definition by including the following line into the /etc/conf.d/net configuration:
> 
> dhcpcd_eth<n>=""
> 
> Add the following:
> ...

 

Yes, I know that but (I didn't say) my computer is a laptop so I need the DNS server information gathered from DHCP when I roam around different sites and networks.

----------

## UberLord

Sounds sounds you need resolvconf - more specifically, openresolv. Find it in a portage near you  :Wink: 

----------

## VinzC

 *UberLord wrote:*   

> Sounds sounds you need resolvconf - more specifically, openresolv. Find it in a portage near you 

 

Oh, great, I remember we've already talked about resolvconf. At that time it gave me a hard time but it's an excellent opportunity to tell it who's the master  :Wink:  .

----------

## UberLord

With my help we can make it your willing slave   :Twisted Evil: 

----------

## VinzC

 *UberLord wrote:*   

> With my help we can make it your willing slave  

 

Rhoooo...  :Embarassed: 

----------

## VinzC

I've installed openresolv and I've seen it immediately adds remote name server addresses when I start a new VPN connection, which is perfect. However it doesn't seem to remove them when I close the connection, is it normal? I haven't changed nor added any custom script or variable, perhaps should I?

----------

## UberLord

Does "resolvconf -l" still list the VPN resolv.conf?

----------

## VinzC

 *UberLord wrote:*   

> Does "resolvconf -l" still list the VPN resolv.conf?

 

Yes, it does. But I realize now that once I rebooted everything went to normal. Now openresolv removes the entries it added for the remote nameservers once the VPN connection is over. Great tool, thanks  :Smile:  .

(Maybe it messed up a little since I installed it while my network link was already active. I suppose it had to somewhat «learn» about my existing networks, right?)

----------

## VinzC

Well I'm just curious as to know how openresolv intercepts changes made to the flat file. It looks like it can be done with only a single shell script, does it?

----------

## depontius

Extra question about openresolv...

Do VPN applications have to be "openresolv aware" in order for openresolv to work?

I tried resolvconf a while back, and for some reason it never worked for me.  As a result, I've been using dnsmasq and some of my own scripts to do what resolvconf was supposed to do.  I haven't tried openresolv yet, but it seems like a good idea, for a rainy day.

In the meantime, my employer has migrated us to a different VPN, and this one doesn't give me the ability to hook my own scripts in, like the old one did.  If openresolv can do its magic without a hook from the VPN side, maybe it's now the easier solution to my problems.

----------

## VinzC

 *depontius wrote:*   

> Do VPN applications have to be "openresolv aware" in order for openresolv to work?

 

No, it just works  :Smile:  . I've checked it right now -- or a couple of minutes ago as you can see. Note that openresolv is different from resolvconf-gentoo.

----------

## UberLord

They both work the same way, openresolv just has less bugs.

Things do have to be resolvconf aware though - it's like this.

```

interface="eth0"

conf="nameserver 1.2.3.4\n"

if type resolvconf >/dev/null 2>/dev/null; then

   printf "${conf}" | resolvconf -a "${interface}"

else

   printf "${conf}" >/etc/resolv.conf

fi
```

You get the idea.

Most things in Gentoo "just work" with resolvconf though, which is why you get that impression  :Smile: 

----------

## VinzC

I suppose the code you wrote is pseudo-code or something like that. And since you also wrote dhcpcd, it's naturally aware of resolvconf. Is net-dialup/ppp also aware of resolvconf the same way?

EDIT: Found the answer! through ip-up and ip-down scripts. Well, it's just as if all developers of network utilities were one...

----------

## UberLord

 *VinzC wrote:*   

> I suppose the code you wrote is pseudo-code or something like that.

 

shell code  :Smile: 

 *Quote:*   

>  And since you also wrote dhcpcd, it's naturally aware of resolvconf. Is net-dialup/ppp also aware of resolvconf the same way?
> 
> EDIT: Found the answer! through ip-up and ip-down scripts. Well, it's just as if all developers of network utilities were one...

 

And that is why open is good  :Smile: 

Sadly closed products don't normally allow scripting like so, and cannot work with resolvconf. Well, they could, but it's not in their interests.

----------

