beoordelingen

Hoe te Employ Raspberry Pi Firewall

Are you looking for a way to create a Raspberry Pi Firewall for a longer time? If you could not perform it using OpenWRT and Pfsense, then this blog is definitely for you. The Raspberry Pi features a single ethernet socket, which is why it is not possible to create a genuine Firewall on Raspberry Pi. Echter, one can produce a router having Firewall capabilities. For performing this task, you require installing some software blocks on Pi. Before we dive into details, let’s discuss some basic things!

PS: here is everything about the SMB Ports Firewall en de importance of firewall, as well as all Types of Firewall voor uw referentie.


What is a Router Firewall?

To understand this, you should know what a router and Firewall mean. A router refers to a network gadget that adjoins two networks with one another. If your computer features two or more ethernet ports, while having diverse networks, then it can behave like a router. Dan, you will have two networks sharing a connection to a router, 2.0 en 1.0. If there’s a well-configured router, then it enables X and Y to view each other, whereas working on a diverse network.

Raspberry Pi features a single ethernet card. Echter, users can employ a WiFi card to create another network. Hier, you will know how you can connect a WiFi network to an ethernet network. Aan de andere kant, Firewall refers to a kind of software. This software enables users to insert security policies into the router. As stated in the above example, we mentioned that X could ping Y, but cannot access its HTTP server. Hier, we will use “iptables” software for this. You can go with other software when it comes to Firewalls depending on your preference.

For creating wireless access and other software for monitoring the network, users have to go through some instructions. Using this, you can even filter some traffic. Zo, if you like to do this, then keep on following.

Here is my current network:

And I want to turn it like this:

  • Install Raspberry Pi Firewall on your network
  • Allow WiFi access point using a diverse network subnet
  • Build a bridge among two networks
  • Set some Firewall rules and regulations
  • Install other software

Hier, we are going to discuss these steps in detail one by one. Zo, let’s begin with this procedure’s first step.

behalve, zul je meer leren over Firewall basics, en how to turn off Firewall as well as the full comparison of stateful vs. stateless firewal hier.


Installeren Raspberry Pi Firewall

eerste, you have to install the Raspberry Pi Firewall on your network. Voor deze, follow:

  • Install Raspbian
  • No requirement of the desktop model, except if users like to employ Raspbian for other tasks
  • Plugin Raspberry Pi using an RJ45 cable on the network.
  • It is not compulsory to use static IP addresses, but it could help.
  • Na dit, update the system using: sudo apt update, sudo apt upgrade, en sudo reboot.
  • Allow SSH by navigating to raspi-config, then Interfacing options, en dan sudo raspi-config.

Dat is het, en nu, it is time to install the router. Zo, let’s know how to perform router installation.

Ook, hier zijn de Mikrotik Firewall rules en de benefits of virtualization voor uw referentie.


Install Wireless Router

It is quite possible for configuring the Raspberry Pi Firewall manually as a WiFi router. Echter, it is a bit time consuming and complex. For making it easier for you, we are presenting you with a script for the same.

  • This script is available on GitHub. ten eerste, you require installing git for downloading this program. Bijvoorbeeld, sudo apt install git
  • Switch to a new folder for downloading this program,

cd/opt

git clone https://github.com/unixabg/RPI-Wireless-Hotspot/git

  • Switch to the subdirectory, dat is cd RPI-Wireless-Hotspot/
  • Begin the installation process by sudo./install

Nu, the script asks a few questions. Once you have answered them, Raspberry Pi reboots for applying the changes. After completing this process, you can employ the Raspberry Pi Firewall as a router. In the network list of WiFi, you will see the apt SSID. After connecting to the server, check everything is functioning fine or not. Zo, there’s nothing more to the configuration of the network.


Firewall Theory

The main role of the Firewall is basically to allow or block access from particular IP addresses to another. Meestal, we often employ a port for setting precise permission. In Firewall configurations, there are two basic rules, which are the Blacklist that follows the rule ‘Allow all except…‘ and Whitelist that follows the rule ‘Deny all except…

Zo, choose the one according to what you like to perform with the Raspberry Pi’s router. If at home, it is best to go with the first one, where you can block several things such as particular IP addresses. At work, go with the other one, where you can prohibit everything except what’s permitted.

In, Out, and Forward

It is an easier program, where one can create several rules in just three directions. These three directions are:

  • Input: Packets of the network that comes into your Firewall
  • uitgang: Packets that go out from your Firewall
  • Forward: Packets that go through your Firewall

When using a hosted web server, one can block everything in input, excluding HTTPS and HTTP. Echter, in output, it does not matter what the server does on the internet. Hier, we will be using Forward rules as there’s not much on Raspberry Pi Firewall. Dus, there’s no point in protecting it.


Raspberry Pi Firewall Configuration

Users who like can add a Firewall to their router for filtering the traffic. If working at home, it is not quite significant. Echter, it is mandatory for a public area or company.

IPTables

For Raspbian, there are various Firewall packages present, such as UFW or IPTables. OpenWRT is also there, which is the Raspberry Pi distribution for creating a Firewall. IPTables is installed on the Raspberry Pi.

Examine the Present Configuration

Prior to adding rules, it is better to examine the present configuration. Om dit te doen, employ the command as ‘sudo iptables – L.’ The GitHub script adds basic rules into the Forward section for enabling forwarding. One can employ this command for checking if the rules that you have added recently correspond to your preferences.

Insert the Forward rule

Each network is diverse, en daarom, every Raspberry Pi Firewall table of rules is diverse too. Here’s an entire syntax for adding particular rules in an environment.

  • Reset the IPTables configuration

Voor deze, toevoegen sudo iptables – F. The order is significant, where the router accepts everything. Dus, we are unable to block particular connections.

  • Add the DROP rule

Use the command iptables – A FORWARD – p tcp – dport 80 – j DROP. The command explains that:

(-EEN) for adding a new rule

(FORWARD) for using in the forward part

(-p tcp) for using the tcp protocol

(-dport 80) for using the HTTP port

(DROP) for dropping everything, which is a timeout connection.

Nu, check if the connection is working. Om dit te doen, make a connection with the WiFi router. For removing a rule, users need to employ IPTables -F. Or use a similar command having a -D operator in place of -A.

Iptables -D FORWARD -p tcp –dport 80 -j DROP

This command allows users to remove a particular rule and, daarom, not all the rules as the case with -F.

Iptables Command Syntax

For creating the Raspberry Pi Firewall rules, one can use the similar command templates. Om deze actie uit te voeren, follow the template as:

Iptables -<operation> <direction> -p <protocol> – -dport <port> -j <action>

Operations:

  • -F: remove, flush all rules that require no parameters
  • -EEN: toevoegen, append a new rule
  • -D: remove, delete a current rule

Directions:

FORWARD, OUTPUT, or INPUT

Protocols:

Mainly udp or tcp

Haven:

The number of ports that you like to build the rule.

Actie:

Make a choice for making the conforming traffic. ACCEPT allows access in the whitelist mode. REJECT denies access and tells senders what’s not permitted. DROP denies access however, does not tell senders.

Switch to Whitelist

Users who are being in a strict environment, then shift to whitelist mode. For performing this action, they have to produce a line of ports. The easiest method to produce a script is to run all the commands at one time. Voor deze, you can download a DNS forwarder on Raspberry Pi. volgende, employ the same for answering DNS requests.

  • Download Bind (DNS server package)

sudo apt install bind9
  • Backup the configuration

sudo mv /etc/bind/named.conf.options/etc/bind/named.conf.options

Nu, paste the lines as:

Acl “localnetwork” {127.0.0.1/32; 192.168.42.0/24;};
opties {directory “/var/cache/bind”;
forwarders {208.67.222.222;};
allow-query {localnetwork;};
dnssec – validation auto;
auth-nxdomain no;
listen-on-v6 {any;};
};

It is a typical configuration. One can use OpenDNS for sending DNS queries received on Raspberry Pi to it.

  • Save and Exit (CTRL+O, CTRL+X)
  • Restart Bind by following sudo service bind9 restart
  • Edit DNS Servers present in the DHCP, sudo nano/etc/udhcpd.conf
  • Change the line, opt dns 208.67.222.222.208.67.220.220
  • Restart DHCP Server by sudo service udhcp restart

Nu, reconnect the device and see if everything is running fine.

Build the Raspberry Pi Firewall Script

  • Make a file having nano

Nano / usr/local/bin/firewall.sh
  • Paste the lines as:
#!/bin/sh
#Clear all rules
Iptables -F
#Whitelist mode
iptables -P INPUT ACCEPT
iptables -P FORWARD DROP
iptables -P OUTPUT ACCEPT
#Allow PING for everyone
iptables -A FORWARD -p icmp -j ACCEPT
#Allow HTTP/HTTPS for WiFi clients
iptables -A FORWARD -p tcp –dport 80 -j ACCEPT
iptables -A FORWARD -p tcp –dport 443 -j ACCEPT
#Allow POP/IMAP/SMTP for WiFi clients
iptables -A FORWARD -p tcp –dport 25 -j ACCEPT
iptables -A FORWARD -p tcp –dport 110 -j ACCEPT
iptables -A FORWARD -p tcp –dport 993 -j ACCEPT
#Allow PING for WiFi clients
iptables -A FORWARD -p icmp -j ACCEPT
Users can make amendments to this command as per their preference. Nu, you can add executive right to it by “sudo chmod +x firewall.sh” and now, run it by “sudo /usr/local/bin/firewall.sh.” If something is not right, you can reboot the Raspberry Pi Firewall for recovering all access.

Make a persistent configuration

The script employs the command “file/etc/iptables.ipv4.nat” for saving the configuration. If it is working, then save the present configuration inside as:

sudo iptables – save>/etc/iptables/ipv4.nat

Door het zo te doen, this will upload the file and will apply the changes directly.


Network Monitoring

If the Raspberry Pi Firewall is working fine, then you can add some packages for improving the Raspbian capabilities. To add a web interface, you can monitor what occurs on the network. Voor deze, you can use Webmin, which is a web interface. Download the recent version and route the setup. Nu, set a passcode and select if you like to employ SSL.


Websites and Proxy Filter

Hier, we are installing Squid as the proxy as well as SquidGuard as the filter for the Raspberry Pi Firewall. For installing Squid, follow “sudo apt install squid” and back up the file with “cd/ etc/ squid sudo mv squid.conf squid.conf.old“. Nu, switch to the user and eliminate all comments with “sudo su

Cat squid.conf.old | egrep -v -e ‘^[[:blank:]]*#|^“.

You have to add the lines at the opening as:

acl LocalNet src 192.168.42.0/24
http access allow LocalNet

Nu, restart Squid for applying changes with “sudo systemct1 restart squid.”

After the configuration of Squid, there are two choices, eerste, as to employ the Raspberry Pi Firewall as HTTP Proxy by configuring the web browser. The other one is to redirect all the HTTP traffic automatically to Squid.

Installation of SquidGuard

Nu, it is time to install SquidGuard by “sudo apt install squidguard.” Download the website list by category and extract the archive files. When extracting, users can view blacklist categories on the screen. Select one and employ the same for the configuration of SquidGuard. Shift files to this folder and archive the SquidGuard configuration. volgende, build a configuration file and paste the following lines:

Dbhome /var/lib/squidguard/db logdir /var/log/squidguard dest
violence {
domainlist blacklists/violence/domains
urllist blacklists/violence/urls
log violenceaccess
}
ac1 {
standaard
{
Slagen voor !violence
redirect http://localhost/block.html
}
}
Make changes if you want any and then save and depart (CTRL + O, CTRL + X). Nu, create the database and restart Squid for applying changes by following the “sudo service squid restart.” Now, try accessing the URLs from the domain’s list and examine if SquidGuard has blocked you or not.

Zo, this is how to create the Raspberry Pi Firewall. Nu, you have a piece of complete knowledge on building up the Firewall router using a proxy on Raspberry Pi.

Tags
Dichtbij
Dichtbij