1

My Pi will connect to different routers. They all provide the same network with the same SSID.

Now I would like to set up the dns server of my Pi with the IP of those routers, (there's a dns server running on them). The challenge is that they don't have the same IP.

From the search that I've done I found that I need to edit /etc/dhcp/dhclient.conf and add something like:

prepend domain-name-servers

Is there a way that I can get the IP of the router and set it in this file?

EDIT: here you have the output of cat /etc/resolv.conf:

domain lan                                                       
nameserver 10.44.55.1 //my router's IP                                            
nameserver 8.8.8.8                                               
nameserver 8.8.4.4 
  • Post the output of route -n into your question, and also ifconfig and cat /etc/resolv.conf See the "Find the Settings of your local Network" section of How do I set up networking/WiFi/Static IP – Milliways Apr 30 '17 at 11:13
  • @Milliways I've just added some screenshots to my question. Looking at the output of the /etc/resolv.conf I would say that everything is as expected since the first nameserver to be used is my router's IP so I don't understand why my PI is not using it. – lmbcerqueira May 8 '17 at 18:20
  • @Milliways I saw that post in the past (the one you mentioned in your comment about "set up networking/WiFI/..) but I didn't get it. It says to not to change /etc/network/interfaces but I do not want to have something like iface wlan0 inet manual because I want to use dhcp. – lmbcerqueira May 8 '17 at 19:01
  • The default setting in the link DOES use DHCP. Do not post links to images, include TEXT in your question. I do not know what you have done, because the cat /etc/resolv.conf is non standard. You appear to have fiddled different contradictory settings. Put your Pi BACK TO STANDARD and it should work. No one can resolve this if you change things without understanding what they do. – Milliways May 8 '17 at 23:46
1

If you are running a network with multiple DHCP servers you will have problems. You should have a single DHCP server.

You could run multiple DHCP servers, if you had some reason to do so (although I find it difficult to think of a reason) provided they run non-overlapping ranges.

You DO NOT need to tell the Pi which DNS server to use, your network DHCP server/s should provide the appropriate settings, including DNS (this is what DHCP is for).

  • just to clarify the scenario: imagine that my PI is moving from room to room and in each room it will connect to a different router. So if I am in a room where there is a router with the IP of 10.22.27.0 I want my dns server to be 10.22.27.0. If later on I move to a different room where there is a router with the IP 10.22.45.0 I want my dns server to be 10.22.45.0, ... Given this scenario, do your advice remain the same, that I do not need to tell my PI which DNS server to use? – lmbcerqueira Apr 30 '17 at 10:19
  • @MarianaFerreira DHCP tells the Pi which server to use. I use multiple routers, but only 1 operates as DHCP server. In fact NONE work as DNS server, which is provided by my ISP, but the DHCP server tells the Pi which DNS to use. The Gateway acts as a DNS forwarder. – Milliways Apr 30 '17 at 10:35
  • I noticed that my PI is not using the desired dns server because it is not able to translate a specific server name in its IP. It should be able to to that if the PI was using the dns server running on the router. I am not using this PI since the beggining, there were different people working on it previously, so maybe they hardcoded a dns server somewhere. Is there a way that I can figure out which dns server is my PI using at a given moment? – lmbcerqueira Apr 30 '17 at 10:54
1

Slightly off-topic, but since it answers the question:

$ sudo cat > /etc/resolv.conf <<-"EOF"
lookup file bind
nameserver 8.8.8.8
nameserver 8.8.4.4
EOF

then

$ sudo chattr +i /etc/resolv.conf

The last bit prevents automagic modification of the resolv.conf file. Those google DNS servers are never down, never have issues with latency. dhcpcd or dhclient may complain in logfiles, just ignore that.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.