Is it safe to open ports 80 and 443 in my home network?
Hi all, I'm running a small website off of a raspberry pi in my house. I have opened ports 80 and 443 and connected my IP to a domain. I'm pretty confident in my security for my raspberry pi (no password ssh, fail2ban, nginx. Shoutout networkchuck.). However, I am wondering if by exposing my ports to the raspberry pi, I am also exposing those same ports to other devices in my home network, for example, my PC. I'm just a bit unsure if port forwarding to an internal IP would also expose other internal IP's or if it only goes to the pi. If you are able to answer or have any other comments about my setup, I would appreciate your comment. Thanks!
I would suggest signing up for a free Cloudflare account and setting up any DNS for your Pi through there, using the Cache feature.
Once that is done, setup an automated script that will pull down Cloudflare IPs into a file (you can use a cronjob to run this daily):
#!/bin/bash
set -e
cf_ips() {
echo "# https://www.cloudflare.com/ips"
for type in v4 v6; do
echo "# IP$type"
curl -sL "https://www.cloudflare.com/ips-$type/" | sed "s|^|allow |g" | sed "s|\$|;|g"
echo
done
echo "# Generated at $(LC_ALL=C date)"
}
cf_ips > allow-cloudflare.conf
(cf_ips && echo "deny all; # deny all remaining ips") > allow-cloudflare-only.conf
Then in your web server config to only accept connections from Cloudflare IPs:
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name example.com;
root /var/www/html;
include /etc/nginx/allow-cloudflare-only.conf;
}
I prefer this method over UFW/iptables block as it allows you to control the IP block per web config, so if needed, you can make exceptions by not adding the include /etc/nginx/allow-cloudflare-only.conf; into that specific site's conf file.