# dns problem with wireless and cable connection

## mkay

Hi,

i'm using my laptop in several networks. some of them i achieve by wireless card and some by cable. eg: i've got wireless network at home with router (and dns server) 192.168.11.1. i'm getting dns via dhcp - everything is just fine.

then i hibernate my laptop and take it to diffrent location, where i've got cable network 192.168.169.0/24 with 2 dns server configured. i'm also getting those servers via dhcp, so it's fine again.

what's the problem? after some time (few minutes) sudenly 192.168.11.1 appears in my /etc/resolv.conf. it's on the first place (after it, i've also get ip of servers from cable connection). it seems like wireless card sets the last dns server, which was used when it can't connect to any AP (when i'm using wireless connection in diffrent place than my home and then move to cable network, i get dns servers from last wireless one). how can i fix it?

here's my network configuration:

```

# i need to set mac adress of my card, couse it's random by default;/

mac_eth0="xx:xx:xx:xx:xx:xx"

modules=( "dhcpcd" ) 

config_eth0=( "dhcp" )

dhcpcd_eth0="-t 3"

modules=( "wpa_supplicant" )

config_ath0=( "dhcp" )

wpa_supplicant_ath0="-Dmadwifi"

```

and wpa_supplicant:

```

ctrl_interface_group=0

ap_scan=1

network={

   ssid="xxxxxxxxx"

   psk="********"

   priority=9

}

```

(and few more networks defied as the one above)

----------

## erik258

Are you using a resolv.conf auto-configurer?

----------

## mkay

 *erik258 wrote:*   

> Are you using a resolv.conf auto-configurer?

 

I'm not sure what are you asking about;/ if you mean something like openresolv or resolvconf-gentoo, than the answer is no.

all soft i'm using for network devices:

- gentoo init scripts

- wpa_supplicant for wireless

- ifplugd for detection cable connection

i do not use any graphical wizards or anything like that - just pure config files

----------

## krinn

workaround, not a real solve, but will correct your issue

dhcpcd_eth0=("-t 3 -R")

dhcpcd_ath0=("-R")

then 2 choices:

1/ common dns for everyone, a free one...

2/ using the 3 dns you use for your both connection as nameserver (i would put my home dns first in list, so i would just have "a little lag" while it fail resolving that nameserver when i'm at work before it try and success with next one in list that is your primary dns from work)

----------

## mkay

what does -R option mean? i do not have it described in man pages.

actually if i move to wired network i got dns servers from dhcp. after some time the last seen dns from wireless net appears at the begining of resolv.conf (but the rests of servers aren't deleted) so i have a 'small lag' you're writing about (it's not so small anyway.;>)

i've changed my configuration to use dhclient instead of dhcpcd, but i'm not able to test it before tuesday...

----------

## krinn

-> http://www.phystech.com/download/dhcpcd_man.html

```
-R

    Prevents dhcpcd from replacing existing /etc/resolv.conf file. 
```

sorry should have told it before, it's just to prevent dhcpcd changing your /etc/resolv.conf file, so you set your own with the 3 nameserver in it, and told dhcpcd to stop play with it (as i suppose it's dhcpcd that play with it)

edit: and to further explain my mind

-> Once nameserver are set, and dhcpcd is told to stop handle /etc/resolv.conf you'll end with

when at home: first nameserver is your home dns -> will be resolv normally

when at work: first nameserver will fail (the little lag) -> 2nd will be use (normally so your 1st dns from work) it should resolv at that point -> if fail 3rd is your 2nd work dns

in the two case, dhcpcd shouldn't change /etc/resolv.conf so no surprising new dns add...

(told you before it's a workaround)

-> that's why if you could use a public/common/free dns it would be really better (you might not, if for example at work they filters everything and don't want you to use another dns...)

if you can, then 1 nameserver for both case (at home or work) should be the real nice solve.

----------

## UberLord

 *krinn wrote:*   

> -> http://www.phystech.com/download/dhcpcd_man.html
> 
> ```
> -R
> 
> ...

 

-R is only valid up to dhcpcd-3

dhcpcd-4.0 supports it when emerged with the compat USE flag

dhcpcd-4.99 doesn't support it

To stop dhcpcd-4 from playing with resolv.conf you need to use this instead

-C resolv.conf

But seriously, you should not need to do that at all.

Instead you should use resolvconf (openresolv is in portage) to manage resolv.conf for you. dhcpcd will talk to resolvconf if installed.

----------

## monsm

openresolv looks like a good solution.

A different one that I use, is djbdns.  I have set it up as a dns cache (there is a howto on the wiki I think).  I have then pointed it to http://www.opendns.com/.  I guess you could just have set the dns servers e.g. from opendns in the /etc/conf.d/net script.

But have a look at http://roy.marples.name/projects/openresolv.  Looks like the thing if you e.g. put this laptop behind a corporate firewall from time to time. Might not be appropriate to go to opendns in those cases.

Mons

----------

## mkay

hmm - openresolv could help in this situation, but is it really needed? 

i do not have problem with diffrent dns servers from wired and wireless net (or vpn) running on the same time. my problem is: the wireless connection always set the last seen dns server if it can't find any network to connect.

i've changed my net configuration in /etc/conf.d/net to use dhclient instead of dhcpcd and it seems to work perfectly (well in fact - i have another problem with dhclient, but its not related with that topic). does it mean bug in dhcpcd?

----------

## UberLord

dhcpcd-4 has a mini resolvconf built. You're probably seeing this in action. Yes, it could be a dhcpcd bug.

So, to help diagnose so I can provide a fix or workaround, you should state the contents of /var/run/dhcpcd/resolv.conf with the wireless link active, then inactive, so /etc/resolv.conf for each state and how you think it's incorrect.

----------

## mkay

sorry for the latency in answers, but i'm not able to check wired networks every day.

anyway: i've checked that dir. 

when i'm on wireless connection i've got one file there (named ath0) with proper dns configuration.

when i move to wired network, file eth0 appears, but file ath0 is not deleted (and i'm not connected to any AP!) - in my opinion this is a bug - i shouldn't have dns configuration from ath0 when it's not connected to any network. 

what's strange - file ath0 is still present in that directory even if i turn off wireless connection (/etc/init.d/net.ath stop)

----------

## meyerm

Hello together,

I'm encountering a very similar problem. The DNS-config of my VPNc-connection is reappearing even when my WiFi (over which the VPN is always started) is switched off. No matter if I'm online with an external UMTS/3G-stick, with the internal wired ethernet card or even with the wifi-card but with no vpnc.

```
yavin ~ # eix -ncI openrc

[I] sys-apps/openrc (0.4.3-r1@24.02.2009): OpenRC manages the services, startup and shutdown of a host

yavin ~ # eix -ncI resolv

[I] net-dns/openresolv (3.1.1@22.03.2009): A framework for managing DNS information

yavin ~ # eix -ncI dhcp

[I] net-misc/dhcpcd (4.0.12@02.03.2009): A fully featured, yet light weight RFC2131 compliant DHCP client

yavin ~ # eix -ncI vpnc

[I] net-misc/vpnc (0.5.3@26.01.2009): Free client for Cisco VPN routing software
```

This breaks the normal online work, of course. Established connections work, but whenever a DNS lookup is needed, all those now not reachable DNS servers are queried first. A ping has a RTT of 20 ms, but a latency of several seconds  :Wink: 

Any news on your problem here or even a suggestion what I should do?

Thanks,

M

----------

## meyerm

I just decided to take the more offensive approach  :Wink: 

```
yavin resolvconf # find

.

./interfaces

./interfaces/ppp0

./interfaces/tun0

./metrics

yavin resolvconf # cat interfaces/tun0

nameserver IP-ADDRESS-OF-SOME-DNS?

nameserver IP-ADDRESS-OF-THE-VPN-DNS

domain DOMAIN-WHILE-IN-VPN

yavin resolvconf # rm interfaces/tun0
```

So I hope I have no more problems for today. Of course this isn't the solution for the long run...

EDIT: the tun0-interface is of course not active since vpnc has been shut down a long time ago

----------

