this post was submitted on 01 Dec 2023
93 points (94.3% liked)

Selfhosted

40006 readers
767 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 1 year ago
MODERATORS
 

Hi, I know this topic has been talked about 70 thousand times but I’m still not sure.

I have home server on an intel NUC behind the ISP router. On it I have the standard arr apps, jellyfin, pi-hole etc etc. I would like to access them through a domain rather than an IP. So I set them up in docker, behind traefik, behind authelia and behind cloudflare. I am the only one that uses it.

Now, I’m worried about the security of it all. I’ve been searching here and there and I’ve read about cf tunnels, wireguard server, vps, vlan, OPNsense etc etc. I still don’t know what would be the most secure. Should I just stay with what I have?

EDIT: I'm not behind CGNAT

you are viewing a single comment's thread
view the rest of the comments
[–] TCB13@lemmy.world 36 points 11 months ago* (last edited 11 months ago) (1 children)

Yes, you can use a Cloudflare tunnel but why? Since you're into self-hosting why should you depend on some random company to tunnel your traffic when you most likely don't need it? You also have all the potential tracking, spyware, risks and "being hostage" scenarios that may come with that choice.

The following assumes your use case is a simple home server for "standard arr apps, jellyfin, pi-hole" for personal usage that sits inside your network and your objetive is to be able to access those services. If you're instead trying to host a game server / few services for friends (that doesn't really need to be "inside" your home network) there's a more complete comment with other security considerations and recommendations here.

Your basic requirements are:

  • Some kind of domain / subdomain payed or free;
  • Preferably Home ISP that has provides public IP addresses - no CGNAT BS;
  • Ideally a static IP at home, but you can do just fine with a dynamic DNS service such as https://freedns.afraid.org/.

Quick setup guide and checklist:

  1. Create your subdomain for the dynamic DNS service https://freedns.afraid.org/ and install the daemon on the server - will update your domain with your dynamic IP when it changes;
  2. List what ports you need to access remote;
  3. Setup Wireguard VPN on the server. There's also this nice UI that can be used to do most of the setup and create client config files;
  4. For the VPN use custom ports with 5 digits - something like 23901 (up to 65535) to make your service harder to find;
  5. Configure your ISP router to assign a static local IP to the server and port forward the VPN port to the server IP;
  6. Only expose absolutely required services (the VPN port in this case) to the Internet. Any service the server provides, SSH, configuration interfaces and whatnot can accessed through the WireGuard VPN;
  7. In the server consider setting up nftables / iptables / another firewall 10 minute guide;
  8. Configure nftables to only allow traffic coming from public IP addresses (IPs outside your home network IP / VPN range) to the Wireguard port - this will protect your server if by some mistake the router starts forwarding more traffic from the internet to the server than it should;
  9. Configure nftables to restrict what countries are allowed to access your server. Most likely you only need to allow incoming connection from your country (https://wiki.nftables.org/wiki-nftables/index.php/GeoIP_matching).

Since you're only allowing access to your services through the VPN and you've heavily restricted access to the VPN port you'll be safe. Just a side note, don't be afraid to expose the Wireguard port because if someone tried to connect and they don't authenticate with the right key the server will silently drop the packets.

Now if your ISP doesn't provide you with a public IP / port forwarding abilities you may want to read this in order to find why you should avoid Cloudflare and how to setup and alternative / more private solution.

[–] jaykay@lemmy.zip 3 points 11 months ago (2 children)

Thanks for this awesome write-up.

Yeah, that's what I'm kind of thinking about Cloudflare, so I'm trying to set up WireGuard right now. I don't know if I'm shooting myself in the foot by trying to do in docker for now or not, but I'd rather do that before I do it on bare metal. It seems to work already, as I can see that my IP changes on my phone when I access it. Hell, I can even access my routers' dashboard. However, I still can't access the services on the server (by IP, like 192.x.x.x:8989), so I'm trying to figure that out.

May I ask, why do I need a domain if I'm going through WireGuard, which goes through the IP and port, anyway?

[–] theit8514@lemmy.world 3 points 11 months ago (1 children)

If your home ip changes a lot a dynamic dns provider will keep up with it so you don't constantly have to change your phone's wireguard configuration

[–] jaykay@lemmy.zip 1 points 11 months ago

Ohhhhh, that makes sense. I might consider it in the future. I don't think it changed once so far. If it does, I'll come back to that, thanks :)

[–] lemmyvore@feddit.nl 0 points 11 months ago* (last edited 11 months ago) (1 children)

Before you invest a lot of time into this just wanted to say that it's a 2m job with Tailscale. You install it on the server and on your phone (or laptop whatever), you start it, and you can access anything on the server at a short name you can customize fully, or at a long name you can pick from randomly generated choices generated by Tailscale. (The long name is usually only relevant if you're going to expose your server to the internet or in unusual DNS setups, if you just want to access the server from your phone the short name will do.)

OP's list is great for learning and for full control but if you just want to solve your problem fast, you can.

[–] jaykay@lemmy.zip 3 points 11 months ago (2 children)

I’m either lucky or it’s stupid easy to install wireguard. I put basic config in docker compose, downloaded the app, port forwarded and I’m good. Even pihole works. It’d haven taken me 5 mins if it wasn’t for the firewall

[–] thedeadwalking4242@lemmy.world 1 points 11 months ago (1 children)

Dont listen to people about tailscale. This is self hosting! Do it yourself it's part of the fun. I don't know why people are shilling corporate entities so hard here.

[–] jaykay@lemmy.zip 1 points 11 months ago

Exactly what I did haha

[–] yasn77@lemm.ee 1 points 11 months ago

One of the other benefits of Tailscale is device management. Wireguard is an awesome tool (Tailscale uses it under the hood), but adding new devices is more work with Wireguard, as you have to generate keys and share the public keys (and do some IP management). With Tailscale it's pretty much install the app and allow the device with a click.