# dhcpcd blowing out DNS settings [SOLVED]

## Gentree

Hi,

I currently have two connections , a pppoe and a new wifi I am trying to set up. 

I have the wifi link established but each time I connect the wifi device dhcpcd blows out my correctly configured DNS settings in /etc/resolv.conf. It removes the symlink to /etc/ppp/resolv.conf and replaces it with the following.

nameserver 192.168.1.1

The router is not a dns so nothing resolves anymore. 

man dhcpcd is not much help and does not seem to have an option to impede this broken behaviour.

How can ensure my manual dns settings don't get blown out?

TIA, Gentree.   :Cool: 

----------

## theotherjoe

try the following in your /etc/conf.d/net

```
dhcp_eth0="nodns"

```

edit:

BTW, have a look at /etc/conf.d/net.example

for the other options that are available

----------

## Gentree

Thanks, that looks like the right place to go. Shame man dhcpcd did not mention it. 

would that be 

dhcpcd_eth0="nodns" ?

The router seems to be down right now so I don't know if it worked or not. Looks good though.

Thanks for the help.   :Cool: 

----------

## gentoo_ram

No,

```

dhcp_eth0="nodns" 

```

is correct.  The one you mentioned will not work.

----------

## Hu

 *Gentree wrote:*   

> Thanks, that looks like the right place to go. Shame man dhcpcd did not mention it.

 

The man page does not mention it because nodns is not a dhcpcd feature.  The dhcpcd command line option to disable the behavior is -R, and is documented in the man page.  The nodns directive tells baselayout to add -R to the dhcpcd options.  If you used some other DHCP client, baselayout would respond to nodns by adding an option appropriate to that DHCP client.

----------

## Gentree

Thanks,

 *man wrote:*   

> NAME
> 
>      dhcpcd -- an RFC 2131 compliant DHCP client
> 
> SYNOPSIS
> ...

 

well I can't see your -R in my man page. Unless my eyes a just very tired....

 *man wrote:*   

> DESCRIPTION
> 
>      dhcpcd is an implementation of the DHCP client specified in RFC 2131.
> 
>      dhcpcd gets the host information (IP address, routes, etc) from a DHCP
> ...

 

 "dhcpcd then runs the configuration script which writes DNS information" 

That's what I meant by not very helpful. Like I'm supposed to start ploughing through dhcpcd code to find out what the script is and maybe do something about it.  :Rolling Eyes: 

----------

## Gentree

```
# For passing custom options to dhcpcd use something like the following.  This

# example reduces the timeout for retrieving an address from 60 seconds (the

# default) to 10 seconds.  Note that this might be too short for some servers,

# so the default is encouraged unless you know what you're doing.

#dhcpcd_eth0="-t 10"

dhcpcd_wlan0="-t 10"

dhcp_wlan0="nodns"

```

Well that had no effect. Is this -R feature more than a day old?

----------

## cyrillic

 *Gentree wrote:*   

> each time I connect the wifi device dhcpcd blows out my correctly configured DNS settings in /etc/resolv.conf. It removes the symlink to /etc/ppp/resolv.conf and replaces it with the following.
> 
> nameserver 192.168.1.1
> 
> The router is not a dns so nothing resolves anymore. 

 

Can the router be reconfigured to not hand out invalid DNS settings ?

----------

## doctork

I have this in my /etc/conf.d/net:

```
dhcpcd_eth0=( "-t 120 -R" )

```

/etc/resolv.conf is not wiped out when the network restarts, and I see this:

```

jkorpi@fino /etc/conf.d $ ps -fC dhcpcd

UID        PID  PPID  C STIME TTY          TIME CMD

root      5014     1  0 Mar16 ?        00:00:00 /sbin/dhcpcd -h fino -t 120 -R eth0

```

--

doc

----------

## UberLord

 *Gentree wrote:*   

> Well that had no effect. Is this -R feature more than a day old?

 

Actually the -R option was in dhcpcd-1.x through dhcpd-3.x

In 4.x it was deprecated and moved to a compat build.

It won't exist at all in dhcpcd-5.

In other works, baselayout needs to be fixed to support -C resolv.conf instead of -R for the nodns option.

And probably the other options also.

Basically it needs these two fixes

http://roy.marples.name/projects/openrc/changeset/1251/trunk/net/dhcpcd.sh

http://roy.marples.name/projects/openrc/changeset/1269/trunk/net/dhcpcd.sh

----------

## Gentree

Uber, thanks for the update on what's going on here.

That explains the missing options , I'm using 4.0.12 . Maybe the man page should include what is actually available in the package rather that what will be in the next release. At least document -R with a deprecation warning.

This continual moving the goalposts and lack of compatibility is becoming a major headache on linux.

so man page covers command line use but how should dhcpcd -C be used in this context? Should I add a line to /etc/conf.d/net ?? Where is this documented? Is this documented?

thx.

----------

## doctork

I couldn't find any documentation on the deprecatation of -R.  The -C/--nohook resolv.conf does appear in the man page.  I found that this works as well with the stable rev 4.07.

```

In /etc/conf.d/net

dhcpcd_eth0=( "-t 120 -C resolv.conf" )

resulting in 

jkorpi@fino /etc/conf.d $ ps -fC dhcpcd

UID        PID  PPID  C STIME TTY          TIME CMD

root      4989     1  0 12:11 ?        00:00:00 /sbin/dhcpcd -h fino -t 120 -C resolv.conf eth0
```

Once again, /etc/resolv.conf lived through a reboot.

--

doc

----------

## Gentree

thanks, I'll give that a try.

But the big question remains : "WHERE'S THE DOC"?

Sure -C is in the man page for command line usage but t  :Confused:  his rather arcane syntax to be added to resolv.conf does not seem to be documented at all.

----------

## doctork

?Well, you are a "Veteran", while I'm a mere "Tux's lil helper", so all I can say is are you surprised?  Despite the label, I've been doing LInux/Unix for 25+ years. and I'm not.  Maybe the documentation gets better with baselayeout-2 and openrc, but I don't have a lot of hope for that.  As it has always been, what documentation there is, is opaque, at best.

--

doc

----------

## UberLord

 *Gentree wrote:*   

> Uber, thanks for the update on what's going on here.
> 
> That explains the missing options , I'm using 4.0.12 . Maybe the man page should include what is actually available in the package rather that what will be in the next release. At least document -R with a deprecation warning.

 

Eh?

-R is not documented in that man page, -C resolv.conf is

So the man page is quite explicit on how to configure dhcpcd-4 regardless of build options.

 *Quote:*   

> This continual moving the goalposts and lack of compatibility is becoming a major headache on linux.

 

This is why dhcpcd-4 has the compat USE flag and it's on by default.

If you change the default, tough  :Smile: 

You could of course upgrade to OpenRC from baselayout-1 where this already works

 *Quote:*   

> 
> 
> so man page covers command line use but how should dhcpcd -C be used in this context? Should I add a line to /etc/conf.d/net ?? Where is this documented? Is this documented?
> 
> thx.

 

http://www.gentoo.org/doc/en/handbook/handbook-x86.xml?part=4&chap=3#doc_chap3

There's an example which shows passing a custom option to dhcpcd.

----------

## Gentree

OK , let's summarise.

-R still works (?) but is not in man page.

-C is in man page but does not work on baselayout-1*

dhcpcd_eth0 is mentioned in an example in the handbook but this also shows nodns et al which no longer work.

It also has:

 *Quote:*   

> config_eth0=( "dhcp" )
> 
> dhcpcd_eth0="-t 10" # Timeout after 10 seconds

 

So why the different syntax, what does this mean, and again where is it documented. An example can help guess what to try , it is not documentation.

I did rebuild my whole system with openRC a few months back. After several days of compiling, fixing googling forums and revdepping I still had such a broken unfixable mess that I decided to ditch the whole partition and switch back to my backup.

I assume progress has been made on some of the issues since then but I'm in no hurry to waste that much time again. I'll probably wait until it goes stable.

```
Calculating dependencies... done!

[ebuild   R   ] sys-apps/baselayout-1.12.12  USE="unicode -bootstrap -build -static" 0 kB

[ebuild   R   ] net-misc/dhcpcd-4.0.12  USE="compat zeroconf" 0 kB

```

Can you advice on what incantation to use to prevent dhcpcd from blowing my resolv.conf with these versions?

Thanks for your help.

 :Cool: 

----------

## Gentree

BTW both the following lines in conf.d/net fail to stop dhcpcd stomping on my config.

```
#dhcpcd_wlan0=( "-t 10 -C resov.conf" )

dhcpcd_wlan0= "-t 10 -R"

```

Thx

----------

## UberLord

 *Gentree wrote:*   

> BTW both the following lines in conf.d/net fail to stop dhcpcd stomping on my config.
> 
> ```
> #dhcpcd_wlan0=( "-t 10 -C resov.conf" )
> 
> ...

 

1) dhcpcd_* is not a bash array

2) You didn't spell resolv.conf correctly

Try this

```
dhcpcd_wlan0= "-t 10 -C resolv.conf"
```

If you care that much about documentation, suggest better documentation and submit your changes to bugs.gentoo.org  :Smile: 

----------

## TheAbu

Hum, I fear what I will say is a bit off-topic but still trying   :Razz: 

I'am in a similar situation, I have two internet connection, one ethernet and one wifi. Since I wanted to be able to switch at will from one to the other without ever bringing them down I wrote a little script (WARNING: Gurus of all sort, don't look at it, I'm one month into Linux so my bash isn't exactly great   :Embarassed:  )

Anyway, if it can help, here it is:

```
#!/bin/sh

#

# File to modify

dns_conf=/etc/resolv.conf

# Use the argument passed to the command line to set the right default route and dns.

if [ "$1" = "isp1" ]

then

    echo "---> Switching to provider-name"

    echo "# Provider-name" DNS-Servers set by dns_conf" > "$dns_conf" 

    echo "nameserver xxx.xxx.xxx.xxx" >> "$dns_conf"

    route del default gw 192.168.0.1

    route add default gw 192.168.10.254

elif [ $1 = "isp2" ]

then

    echo "---> Switching to provider-name"

    echo "# Provider-name" DNS-Servers set by dns_conf" > "$dns_conf" 

    echo "nameserver xxx.xxx.xxx.xxx" >> "$dns_conf"

    route del default gw 192.168.10.254

    route add default gw 192.168.0.1

else

    echo "Argument must be provider-name 1 or provider-name 2

    exit 

fi

echo "------------------------------------------------------------------------------"

cat "$dns_conf"

echo "------------------------------------------------------------------------------"

route

```

It's not a direct answer to your problem, but maybe it can help (works great for me)

Mistakes fixed, thanks to UberLord  :Smile: 

----------

## UberLord

Not too bad really

#!/bin/bash should be #!/bin/sh

$1 should be quoted "$1"

elif [ needs a space after the [

elif [ "$1"

$dns_conf should be quoted as well - "$dnsconf"

----------

## TheAbu

Thank you UberLord, fixing in my little script  :Smile: 

----------

## Gentree

 *UberLord wrote:*   

>  *Gentree wrote:*   BTW both the following lines in conf.d/net fail to stop dhcpcd stomping on my config.
> 
> ```
> #dhcpcd_wlan0=( "-t 10 -C resov.conf" )
> 
> ...

 

Well I could not know that because it's not documented , that's the whole point. That one was a result of copying examples and suggestions on forums in the absence of proper documentation.

 *Quote:*   

> 
> 
> 2) You didn't spell resolv.conf correctly
> 
> 

   :Embarassed:   *Quote:*   

> 
> 
> Try this
> 
> ```
> ...

 

Thanks for the suggestion but that fails too. I get repeated errors each time the file is read.

```
-t 10 -C resolv.conf command not found
```

 *Quote:*   

> 
> 
> If you care that much about documentation, suggest better documentation and submit your changes to bugs.gentoo.org 

 

Well I dont think writing doc without any understanding of how the package works would be a very useful endeavour. My experience of the way user suggestions are received on bugs.gentoo.org varies between dismissive and abusive. I sadly concluded that was a waste of effort long ago.

Surely the best person to write the doc is the one who wrote the code.  Especially if there are complications of dependency versions and features added and removed.

I've written a script to restore the damaged file but it would be better if this worked.

thx   :Cool: 

----------

## UberLord

 *Gentree wrote:*   

>  *UberLord wrote:*    *Gentree wrote:*   BTW both the following lines in conf.d/net fail to stop dhcpcd stomping on my config.
> 
> ```
> #dhcpcd_wlan0=( "-t 10 -C resov.conf" )
> 
> ...

 

dhcpcd_* examples are never written as bash arrays

config_* examples ARE written as bash arrays (for baselayout-1)

If you can't derive this from the examples and require explicit documentation of what variables are and aren't bash arrays then please file a documentation bug at bugs.gentoo.org preferably with a patch for this.

 *Quote:*   

>  *Quote:*   
> 
> 2) You didn't spell resolv.conf correctly
> 
>     *Quote:*   
> ...

 

There should not be a space after the equals sign, that was my fault sorry.

```
dhcpcd_wlan0="-t 10 -C resolv.conf"
```

 *Quote:*   

>  *Quote:*   
> 
> If you care that much about documentation, suggest better documentation and submit your changes to bugs.gentoo.org  
> 
> Well I dont think writing doc without any understanding of how the package works would be a very useful endeavour. My experience of the way user suggestions are received on bugs.gentoo.org varies between dismissive and abusive. I sadly concluded that was a waste of effort long ago.

 

Do you expect better or users from this forum? Very few developers post here and I'm an ex dev.

 *Quote:*   

> Surely the best person to write the doc is the one who wrote the code.  Especially if there are complications of dependency versions and features added and removed.

 

I wrote the code.

I also wrote the documentation. However since I left the documentation has been changed by overs, but the code hasn't.

I also write the code and documentation for OpenRC. To make things easier, it doesn't use bash so the complication of what is and what isn't a bash array is moot as they no longer exist.

----------

## Gentree

OK many thanks. Without the space it now works!

I think this points out the problem. To you it's obvious what is and isn't a bash array and what the syntax of this line should be. But from the user's point of view this is just a configuration file . It is not a bash script so there's no reason to think of any line as being bash syntax or any other undocumented format that may apply.

Indeed it seems that it's further complicated by what the bash code in dhcpcd is doing. Without disecting the code the only way to know what is required in this config file it by reading the doc (?) or by following examples like the handbook and elsewhere. Following examples is prone to error because it lacks understanding. 

It's unfortunate if others have undone your careful work since you left maintaining this one.

Thanks for your time and persistence in helping sort this out. 

 :Cool: 

----------

