Black Lives Matter - Action and Equality. ... Adafruit joins the Stop Hate for Profit campaign.
0

resolv.conf & Raspberry Pi as an Ad Blocking Access Point
Moderators: adafruit_support_bill, adafruit

Forum rules
Talk about Adafruit Raspberry Pi® accessories! Please do not ask for Linux support, this is for Adafruit products only! For Raspberry Pi help please visit: http://www.raspberrypi.org/phpBB3/
Please be positive and constructive with your questions and comments.

resolv.conf & Raspberry Pi as an Ad Blocking Access Point

by ericgus on Mon Sep 16, 2013 1:31 pm

Hi .. just a quick question on the tutorial "Raspberry Pi as an Ad Blocking Access Point" http://learn.adafruit.com/raspberry-pi- ... t/overview
(great tutorial btw)

everything works great .. except one small problem I am trying to fix ..

when the Pi is rebooted the /etc/resolv.conf is wiped out and replaced (presumably by DHCP for eth0) with my routers default.. this naturally breaks the whole ad-blocking setup .. manually redoing the /etc/resolv.conf file temporarily fixes the problem but this isnt really a great long-term solution.

I was wondering if anyone else had seen this behavior where /etc/resolv.conf is erased and replaced after rebooting ..?

I am using "New Out of Box Software (NOOBS)" and choosing Raspbian as the install option (presumably this provides the freshest Raspian and its the recommended install on the RaspberryPi site http://www.raspberrypi.org/downloads ).. I have done a sudo apt-get update to ensure that everything is fresh.

would love to hear anyones thoughts on this issue and/or if you hit this problem and what you did to fix it.. I am guessing its probably something in the DHCP client for eth0 config on the Pi but I am not skilled enough to know where to look and what to change to disable this refreshing behavior.

Thanks!

ericgus
 
Posts: 33
Joined: Mon Mar 01, 2010 11:10 am

Re: resolv.conf & Raspberry Pi as an Ad Blocking Access Point

by adafruit_support_rick on Mon Sep 16, 2013 3:31 pm

DHCP will rewrite resolv.conf.
The easiest thing to do it to give your pi a static IP instead of using DHCP.
Change the eth0 stanza in /etc/network/interfaces to a static assignment.

adafruit_support_rick
 
Posts: 35095
Joined: Tue Mar 15, 2011 11:42 am
Location: Buffalo, NY

Re: resolv.conf & Raspberry Pi as an Ad Blocking Access Point

by ericgus on Mon Sep 16, 2013 4:10 pm

Yea thats what I was thinking of doing as my long term fix .. You might want to update the tutorial to make a note of that for other folks following it to make that change as well to work around the resolve.conf issue ..

Thanks!

ericgus
 
Posts: 33
Joined: Mon Mar 01, 2010 11:10 am

Re: resolv.conf & Raspberry Pi as an Ad Blocking Access Point

by adafruit_support_rick on Mon Sep 16, 2013 4:37 pm

I passed a note to the author...

adafruit_support_rick
 
Posts: 35095
Joined: Tue Mar 15, 2011 11:42 am
Location: Buffalo, NY

Re: resolv.conf & Raspberry Pi as an Ad Blocking Access Point

by jthawk on Sat Sep 21, 2013 3:51 am

REF: Raspberry Pi as an Ad Blocking Access Point

FYI my fix for:

Steps to resolve the issue of dhcp chamging /etc/resolv.conf.
This version allows for iface eth0 inet dhcp to remain intact.

1) sudo nano /etc/resolv.conf.ab
add below text:
Code: Select all | TOGGLE FULL SIZE
   nameserver 192.168.42.49
   nameserver 8.8.8.8
   nameserver 8.8.4.4

Ctrl-X | y (save file)

2) sudo nano /etc/network/interfaces

edit and remove all wlan0 and replace with
Code: Select all | TOGGLE FULL SIZE
   allow-hotplug wlan0
   iface wlan0 inet static
     address 192.168.42.1
     netmask 255.255.255.0
     post-up /etc/network/if-up.d/resolv_fix.sh

   up iptables-restore < /etc/iptables.ipv4.nat

Ctrl-X | y (save file)

3) sudo nano /etc/network/if-up.d/resolv_fix.sh

add below text:
Code: Select all | TOGGLE FULL SIZE
   #!/bin/sh
   # allow /etc/resolv.conf to be updated
   sleep 6
   # copy fixed resolv.conf
   cp /etc/resolv.conf.ab /etc/resolv.conf

Ctrl-X | y (save file)

4) sudo reboot
jthawk
 
Posts: 1
Joined: Sat Sep 21, 2013 3:45 am

Re: resolv.conf & Raspberry Pi as an Ad Blocking Access Point

by adafruit_support_rick on Sat Sep 21, 2013 7:22 am

Wouldn't your post-up script also work with DHCP?

adafruit_support_rick
 
Posts: 35095
Joined: Tue Mar 15, 2011 11:42 am
Location: Buffalo, NY

Re: resolv.conf & Raspberry Pi as an Ad Blocking Access Poin

by ashwin009 on Sun May 10, 2015 11:22 pm

Hi

I would like to know if I can still use my RPI as a NAS and host my webpage in local network if I configure it as a Ad blocker

ashwin009
 
Posts: 1
Joined: Sun May 10, 2015 11:21 pm

Re: resolv.conf & Raspberry Pi as an Ad Blocking Access Poin

by adafruit2 on Mon May 11, 2015 11:05 am

i think so? but we dont know for sure

adafruit2
Site Admin
 
Posts: 19222
Joined: Fri Mar 11, 2005 7:36 pm

Re: resolv.conf & Raspberry Pi as an Ad Blocking Access Poin

by CrimsonSmear on Thu Feb 04, 2016 12:06 am

The easiest thing to do is to address the DHCP.
I would suggest OpenDNS, as not all countries are Google friendly.

1) sudo nano /etc/dhcp/dhclient.conf
add below text:
Code: Select all | TOGGLE FULL SIZE
   supersede domain-name-servers 208.67.222.222, 208.67.220.220;
   prepend domain-name-servers 127.0.0.1;
Ctrl-X | y (save file)

CrimsonSmear
 
Posts: 1
Joined: Wed Feb 03, 2016 11:30 pm

Re: resolv.conf & Raspberry Pi as an Ad Blocking Access Poin

by lennok on Wed Oct 18, 2017 7:12 pm

instead of messing with dhcp client and/or constantly over wiriting the resolv.conf file i just added two additional lines to /etc/network/interfaces, which now looks for the wlan0 like this:

Code: Select all | TOGGLE FULL SIZE
allow-hotplug wlan0
iface wlan0 inet static
  address 192.168.42.1
  netmask 255.255.255.0
  post-up ip addr add dev wlan0 192.168.42.49/24
  pre-down ip addr del dev wlan0 192.168.42.49/24
  dns-search 192.168.42.1
  dns-nameservers 192.168.42.1

lennok
 
Posts: 1
Joined: Wed Oct 18, 2017 7:03 pm

Please be positive and constructive with your questions and comments.