# dnsmasq, rp-pppoe, ppp, if-up stomping resolv.conf

## MarkDavies

Hi,

I've recently switched over from a basic DHCP setup to a PPPoE setup. Orginally my gentoo box would obtain its IP and DNS information from my ADSL modem (DLink DSL-300T) via DHCP. I recently switched my modem into Bridge mode and now obtain my IP and DSN information using rp-pppoe (adsl-start).

I'm running dnsmasq on my gentoo box. In the original configuration, my resolv.conf just contained "nameserver 127.0.0.1" and dnsmasq would pick up its DNS servers from a seperate, automatically generated file. Now that I've swicthed over to rp-pppoe, I have dnsmasq getting its DNS information from /etc/ppp/resolv.conf. All seems to work fine except for the fact that my /etc/resolv.conf file now gets stomped on when I run adsl-start.

I've tried to tweak a few settings in /etc/ppp/pppoe.conf but I either end up with /etc/resolv.conf being symbolically linked to /etc/ppp/resolv.conf or being rewritten with the same entries that can be found in /etc/ppp/resolv.conf.

From what I can gather both adsl-connect and /etc/ppp/if-up attempt to modify /etc/resolv.conf. All I'd like is for /etc/ppp/resolv.conf to be modified and /etc/reslov.conf to be left alone.

Does anybody have any ideas on how this can be done?

I'd prefer not to have to modify any scripts (adsl-connect, if-up) but its the only solution I can think of at the moment.

Any help would be appreciated.

----------

## MarkDavies

I've had a bit more of a chance to look around for some information on this problem.....

From http://ftp.axis.se/pub/users/cii/floppyfw/dnsmasq-1.18/setup.txt

 *Quote:*   

> Automatic DNS server configuration with PPP.
> 
>    Later versions of pppd have an option "usepeerdns" which instructs it
> 
>    to write a file containing the address(es) of the DNS severs in
> ...

 

From http://www.strw.leidenuniv.nl/cgi-bin/man?program=pppoe.conf&section=5

 *Quote:*   

>  DNSTYPE
> 
>               One  of NOCHANGE, SPECIFY or SERVER.  If set to NOCHANGE, adsl-
> 
>               connect will not adjust the DNS setup in any way.   If  set  to
> ...

 

I'm not at home at the moment but when I get back I'll try updating my configuration

```
/etc/ppp/rp-pppoe.conf:

 ....

 DNSTYPE=NOCHANGE

 PPPD_EXTRA=usepeerdns

 PEERDNS=no

 ....

```

Hopefully,

1. resolv.conf will be left alone

2. /etc/ppp/resolv.conf will be updated

----------

## MarkDavies

Nope, that didn't work.

From man pppd

 *Quote:*   

>        usepeerdns
> 
>               Ask the peer for up to 2 DNS server addresses.  The addresses supplied by  the  peer  (if  any)  are  passed  to  the
> 
>               /etc/ppp/ip-up script in the environment variables DNS1 and DNS2, and the environment variable USEPEERDNS will be set
> ...

 

I've ended up modifying ip-up and up-down to solve the problem.

```
# cat /etc/ppp/ip-up

#!/bin/sh

# this is a script which is executed after connecting the ppp interface.

# look at man pppd for details

# the followings parameters are available:

# $1 = interface-name

# $2 = tty-device

# $3 = speed

# $4 = local-IP-address

# $5 = remote-IP-address

# $6 = ipparam

# Added to stop /etc/resolv.conf from being modified

if [ "$6" = "nopeerdns" ]; then

        USEPEERDNS=""

fi

if [ "$USEPEERDNS" ]; then

        # add the server supplied DNS entries to /etc/resolv.conf

        # (taken from debian's 0000usepeerdns)

        # follow any symlink to find the real file

        REALRESOLVCONF=$(readlink --canonicalize /etc/resolv.conf)

        if [ "$REALRESOLVCONF" != "/etc/ppp/resolv.conf" ]; then

                # merge the new nameservers with the other options from the old configuration

                {

                        grep --invert-match '^nameserver[[:space:]]' $REALRESOLVCONF

                        cat /etc/ppp/resolv.conf

                } > $REALRESOLVCONF.tmp

                # backup the old configuration and install the new one

                cp -a $REALRESOLVCONF $REALRESOLVCONF.pppd-backup

                mv $REALRESOLVCONF.tmp $REALRESOLVCONF

                # correct permissions

                chmod 0644 /etc/resolv.conf

                chown root:root /etc/resolv.conf

        fi

fi
```

```
 # cat /etc/ppp/ip-down

#!/bin/sh

# this is a script which is executed after disconnecting the ppp interface.

# look at man pppd for details

# the followings parameters are available:

# $1 = interface-name

# $2 = tty-device

# $3 = speed

# $4 = local-IP-address

# $5 = remote-IP-address

# $6 = ipparam

# Added to stop /etc/resolv.conf from being modified

if [ "$6" = "nopeerdns" ]; then

        USEPEERDNS=""

fi

if [ "$USEPEERDNS" ]; then

        # taken from debian's 0000usepeerdns

        # follow any symlink to find the real file

        REALRESOLVCONF=$(readlink --canonicalize /etc/resolv.conf)

        if [ "$REALRESOLVCONF" != "/etc/ppp/resolv.conf" ]; then

                # if an old resolv.conf file exists, restore it

                if [ -e $REALRESOLVCONF.pppd-backup ]; then

                        mv $REALRESOLVCONF.pppd-backup $REALRESOLVCONF

                fi

        fi

fi

# Recreate the default route so autodial works

[ -s /etc/conf.d/net ] && . /etc/conf.d/net

if [ -n "${gateway}" ] && [ "${gateway%/*}" = "$1" ]; then

        /sbin/route add default dev ${gateway%/*}

fi

[ -f /etc/ppp/ip-down.local ] && . /etc/ppp/ip-down.local "$@"

```

I've modified the following entries in  /etc/ppp/pppoe.conf 

DNSTYPE=NOCHANGE

PEERDNS=no

PPPD_EXTRA="usepeerdns ipparam nopeerdns"

Does anybody know of a better way?

----------

