this post was submitted on 23 Jun 2023
17 points (94.7% liked)

Selfhosted

40677 readers
310 users here now

A place to share alternatives to popular online services that can be self-hosted without giving up privacy or locking you into a service you don't control.

Rules:

  1. Be civil: we're here to support and learn from one another. Insults won't be tolerated. Flame wars are frowned upon.

  2. No spam posting.

  3. Posts have to be centered around self-hosting. There are other communities for discussing hardware or home computing. If it's not obvious why your post topic revolves around selfhosting, please include details to make it clear.

  4. Don't duplicate the full text of your blog or github here. Just post the link for folks to click.

  5. Submission headline should match the article title (don’t cherry-pick information from the title to fit your agenda).

  6. No trolling.

Resources:

Any issues on the community? Report it using the report flag.

Questions? DM the mods!

founded 2 years ago
MODERATORS
 

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!

you are viewing a single comment's thread
view the rest of the comments
[–] [email protected] 3 points 2 years ago* (last edited 2 years ago) (1 children)

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.

[–] [email protected] 2 points 2 years ago

And with Cloudflare you could also only open up port 443, because Cloudflare will do HTTP ➡ HTTPS if you enable that in their settings.