Giter Club home page Giter Club logo

building-a-firewall's Introduction

Caching DNS on a Raspberry PI

Note: I've modified the goal of this project. I just want a caching DNS server in order to speed up the network at my home.

The artice I found https://www.instructables.com/id/Raspberry-Pi-Firewall-and-Intrusion-Detection-Syst/ is rather old. I worked through the process myself. Here's the record of what I did.

The interesting thing about the process used is it doesn't require a second Ethernet connection. That's a good solution for me.

MicroSD Card

NOOBS would not work on the latest Raspberry PI 3B+, so I downloaded headless Raspbian.

Power Requirements

The Raspberry PI is sensitive to power supplies. I tried 5V 1.6A but just got the flashing red light. Then I tried to plug into a powered USB hub connected to my iMac, but I still had a power problem. I am not sure why this solution won't work. I should take my MicroUSB cable back to the store, I guess.

I got a 3 A power supply for the PI 3B+ and it works just fine. Someone gave me a 2, so I'm going to get a 2.5 A power supply for it and configure it as the firewall. The 2 doesn't have WiFi, and that's just fine.

Use /etc/rc.local on Ubuntu and Raspbian

We have to use /etc/rc.local. Edit the file in the etc directory and change the interface, address, netmask, broadcast address, and gateway for your router. I'm using a box provided by my cable company, so I logged into the device and got this information. I also set the PI 2 so it has a static IP address. Go ahead and do this now.

Edit /etc/hosts

Put the static address in the hosts file.

Copy rc.local and hosts to /etc

Make sure you have backup copies of these files. You need to use sudo for this step to copy everything in the etc directory to /etc. I did not keep my IP address or other networking information in GitHub. I edited manually and then did a git checkout -- <file>.

Restart the PI. Note - do not use ifconfig <interface> down if you are logged in via ssh. If you are using the console, use

ifconfig <interface> down
ifconfig <interface> up

Otherwise, just use

sudo shutdown -r now

This will close your ssh connection and restart the PI.

Package Installation

Install tcpdump.

Changes to /etc/sysctl.conf to Harden the System

I made the following changes

  • Spoof protection
net.ipv4.conf.default.rp_filter=1
net.ipv4.conf.all.rp_filter=1
  • TCP/IP SYN cookies
net.ipv4.tcp_syncookies=1
  • Ignore ICMP broadcasts
net.ipv4.icmp_echo_ignore_broadcasts=1
  • Ignore bogus ICMP errors
net.ipv4.icmp_ignore_bogus_error_responses=1
  • Do not accept ICMP redirects (put your own interface name for eth0)
net.ipv4.conf.all.accept_redirects = 0
net.ipv4.conf.eth0.accept_redirects = 0
  • Do not send ICMP redirects
net.ipv4.conf.all.send_redirects = 0
net.ipv4.conf.default.send_redirects = 0
net.ipv4.conf.eth0.send_redirects = 0
  • Do not accept IP source route packets
net.ipv4.conf.all.accept_source_route = 0
net.ipv4.conf.all.log_martians = 1
  • Router functionality
net.ipv4.ip_forward = 1
  • Minimum free kb
vm.min_free_kbytes=8192

Make sure you use your own interface name for eth0. Apply changes using sudo sysctl -p.

Set up DHCP and DNS

Having a DNS cache server on the PI 2 will speed up DNS queries, as they will be cached locally in the house. We will deny incomplete or bad DNS requests, which increases security. Install the package dnsmasq.

Here's how I configured it (following the original article).

interface=eth0
listen-address=<my_ip_address>
bind-interfaces
domain-needed
dns-forward-max=150
cache-size=300

I turned off DHCP since I have a mesh routing system, and I can't turn off DHCP in that system.

Also, I tried to use tcpdump to see if DNS was being handled properly. dig reports the correct DNS address - the PI 2 - from my iMac, but no packet information is displayed.

building-a-firewall's People

Contributors

dtsmith2001 avatar

Watchers

 avatar  avatar

Forkers

lkapt

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.