Raspberry Pi – build your own DMZ

If you are using a computer, you should always think about security! Linux systems are quite secure instead of Windows System, which are more in danger about viruses. Security is a topic that you should consider, because no system is 100 percent save. Systems with a always up internet connection (file server, mail server, web server, …) are in danger of attacks. For this it is a good idea to build a de militarized zone, which is between your internal network and the router to the internet. There you will connect your servers and you should install 1 or 2 firewalls to allow or deny certain connections.


For your Raspberry Pi this means the following. We want to reduce traffic, so that only port 80 and 442 communicate. If your Raspberry Pi is used as web server that can reached from outside over HTTP and HTTPS. If you need to connect through SSH to your Pi from outside, we also have to give permissions to port 22. A better idea would be to change the SSH port to something you only know (for example 22356 or so).


If you want to get control of your network traffic, we need to use iptables. For this we need to do the following. The first thing is to get the current version of CA (certifivate authorities):

Next, we need to get the IP address of our router and to find out how our Raspberry Pi communicates with it. This can be done with one simple command:

You will see, that your Raspberry Pi uses wlan0 or eth0. So we use ether a WLAN stick or an ethernet cable. With this in mind we can create rules for our iptable:

We also have to create a new line in our network interfaces configuration file, so that all settings are use also after a reboot:

At the end of the file we add following line:

Now it is time to set the rules for our firewall:

A possible configuration for the example I described above would be:

As you can see, my Raspberry Pi connected with an ethernet cable to the router (eth0). This configuration only allows HTTP and HTTPS connections. If you are connected to SSH with your Raspberry Pi over your router, this will not be possible any more. If you need SSH, this configuration would be better:

Here I use my WLAN connection, so please consider that you have to change the configuration to fits your network. The following things need to be changed:

  • wlan0 or lan0
  • IP addresses of own network. is my router.

The last step is to upload our configuration to the firewall:

With the following command you can test your firewall settings:

You should get the actual configuration of your firewall.


If you are connected to your Raspberry Pi over SSH you may lock yourself out of your own system. If this happens, you need to plug in keyboard and screen to your Pi and change the firewall manually.

(Visited 2,167 times, 2 visits today)

Leave a Reply

Your email address will not be published. Required fields are marked *