Subject: Re: usepeerdns
To: None <>
From: Georges Heinesch <>
List: netbsd-users
Date: 06/09/2001 11:11:14
Quoting Steven M. Bellovin (18-May-01 12:31:54):

> In message <>, "Georges
> Heinesch" writes:

>>But still, even if pppd is doing what it says on the man pages, the
>>/etc/resolv.conf DNS servers are used despite the fact that pppd
>>queries the remote for its DNS servers and that this one spits them
>>out (and pppd stores them in /etc/ppp/resolv.conf). Still, the
>>/etc/resolv.conf DNS servers are used, not the /etc/ppp/resolv.conf
>>How can I _easily_ change that?

> The easiest way, if you always want the PPP resolvers used, is to
> lin
> /etc/resolv.conf and /etc/ppp/resolv.conf together.  What I did was
> to  perform surgery on ip-up and ip-down from xisp.  Here they are,
> if you  want.  (I'm probably going to change this, since I want to
> have the  dhcp-added entries removed when I"m dialed up.)

> ---- ip-up
> #!/bin/sh

> # First setup all variables passed on from pppd
> #-----------------------------------------------

Your ideas brought me to this here.

The files concerned:

----- /etc/ppp/ip-up -----
# save original /etc/resolv.conf
# will be restored later by 'ip-down'
cp -p /etc/resolv.conf /etc/ppp/resolv.prev
# filter all lines in /etc/resolv.conf containing 'nameserver'
grep -iv > /etc/resolv.conf nameserver /etc/ppp/resolv.prev
# append /etc/ppp/resolv.conf to /etc/resolv.conf
cat /etc/ppp/resolv.conf >> /etc/resolv.conf
rm /etc/ppp/resolv.conf
----- cut here -----

----- /etc/ppp/ip-down
mv /etc/ppp/resolv.prev /etc/resolv.conf
----- cut here -----

----- /etc/resolv.conf -----
# DNS server(s) not included since set when pppd ist executed
----- cut here -----

----- /etc/ppp/peers/ATT.resolv.conf -----
# specific for ATT
# required since ATT doesn't negociate DNS server(s) via pppd
----- cut here -----

----- /etc/ppp/peers/EVERYDAY.resolv.conf -----
# specific for EVERYDAY
# not required since EVERYDAY negociates DNS server(s) via pppd
----- cut here -----

----- /root/.ATT-up -----
# copy /etc/ppp/peers/ATT.resolv.conf in case the DNS servers are not negiciated
cp -p /etc/ppp/peers/ATT.resolv.conf /etc/ppp/resolv.conf
# start pppd
pppd call ATT
----- cut here -----

----- /root/.EVERYDAY-up -----
# copy /etc/ppp/peers/EVERYDAY.resolv.conf in case the DNS servers are not negiciated
cp -p /etc/ppp/peers/EVERYDAY.resolv.conf /etc/ppp/resolv.conf
# start pppd
pppd call EVERYDAY
----- cut here -----

ISP 1: ATT, doesn't spit out the DNS server(s)
ISP 2: EVERYDAY, spits them out (2).

The login occurs when executing ~/ATT-up (or ~/EVERYDAY-up). It's not
yet known at this stage whether pppd will negociate DNS server(s).
Hence, the saved (and known) DNS server(s)
(/etc/ppp/peers/ATT.resolv.conf, /etc/ppp/peers/EVERYDAY.resolv.conf)
are copied to /etc/ppp/resolv.conf, the file used by pppd in case DNS
server(s) are negociated. If that's the case, the just copied file is
overwritten (in my case, this happens with ISP EVERYDAY).

    cp -p /etc/ppp/peers/ATT.resolv.conf /etc/ppp/resolv.conf
    cp -p /etc/ppp/peers/EVERYDAY.resolv.conf /etc/ppp/resolv.conf

Now /etc/ppp/ip-up is started. First, the original /etc/resolv.conf is
copied to /etc/ppp/resolv.prev. It's restored after the ISP session.

Next, /etc/resolv.conf is modified. All lines containing "nameserver"
are killed. All other lines remain untouched.

Next, /etc/ppp/resolv.conf is appended to /etc/resolv.conf.
/etc/ppp/resolv.conf is always the correct nameserver file for the
relevant ISP (see above).

Last, /etc/ppp/resolv.conf is deleted since not needed any more.

When saying ~/ppp-down, pppd is stopped and /etc/ppp/ip-down is
executed. This restores /etc/ppp/resolv.conf to /etc/resolv.conf.

Doing it that way, the original /etc/resolv.conf remains untouched
(before and after the ISP session).

/etc/resolv.conf is modified to contain the proper DNS servers during
the ISP session. All other entries inside /etc/resolv.conf are

I believe this is the optimal solution ;)

Cu  Georges Heinesch, Luxembourg
    PGP RSA & DH/DSS public key on request and on public servers

... N49.34.09 E006.09.01