Any guides on how to host at home? I’m always afraid that opening ports in my home router means taking the heavy risk of being hacked. Does using something like CloudFlare help? I am a complete beginner.

  • terribleplan@lemmy.nrd.li
    link
    fedilink
    English
    arrow-up
    4
    ·
    edit-2
    1 year ago

    There are ways to host things from home without opening ports in your router at all, this usually involves running something that calls/tunnels out of your network and back to some service and accepts incoming connections and sends them “baskward” over that connection. Cloudflare offers something called Tunnel, ngrok does something similar (though mainly aimed at development and not production hosting), and you can even host something yourself using something like frp (which is what I use, even for the Lemmy instance I am writing this from).

    I haven’t looked too closely at it, but there is an awesome-tunneling page someone put together that goes over these options and more.

    Let me know if you want a bit more details on these options or specifics of how I’ve set up frp.

    • Spezi@feddit.de
      link
      fedilink
      English
      arrow-up
      0
      ·
      edit-2
      1 year ago

      Not OP and I don’t have any specific questions right now, but if you got any general advice on frp you want to share, I’d be happy to read it :-)

      Very basically, I set up a frps on the public server, and one frpc per service I want to have publicly accessible - where the frpc.ini defines all the specifics, so I don’t have to touch the server regularly. Is that correct so far?

      Edit: After typing it out, I came up with a question - what happens when the frpcs go offline? Will the server return an error, fallback, or just deny the connection?

      • terribleplan@lemmy.nrd.li
        link
        fedilink
        English
        arrow-up
        2
        ·
        1 year ago

        Yeah, you’re basically on the right track. I do a couple things in a possibly interesting way that you may find useful:

        1. I run multiple frpss on different servers. Haven’t gotten around to setting up a LB in front or automatically removing them from DNS, but doing that sort of thing is the eventual plan. This means running as many frpcs as I have frpss. I also haven’t gotten to the point of figuring out what to do if e.g. one service exposed via frps is healthy but another is not. It may make sense to run HAProxy in front of it or something… sounds terrible…
        2. I have multiple frpc.inis, they define all of the connection details for a particular frps then use includes = /conf.d/*.ini to load up whatever services that frpc exposes.
        3. I run frpc in docker and use volumes to manage e.g. putting the right frpc.ini and /conf.d/<service>.ini files in there.
        4. I use QUIC for the communication layer between frpc and frps using certificates for client authentication.
        5. I run my frpcs (one container per frps, I’m considering ways to combine them to make it less annoying to deploy) right alongside the service I am exposing remotely, so I run e.g. one for Traefik, one for gogs gitea forgejo ssh, etc. If you are using docker-compose I would put one (set of) frpc in that compose file to expose whatever services it has. Similar thought for k8s, I would do sidecar containers as part of your podspec.
        6. If I have more than one instance of a service, such as e.g. running multiple Traefik “ingress” stacks, I run a set of frpcs per deployment of that service.
        7. Where possible I use proxy protocol via proxy_protocol_version = v2 to easily preserve incoming IP address. Traefik supports this natively, which is the most important service to me as most of what I run connects over HTTP(s).
        8. I choose to terminate end-user SSL using Traefik within my homelab, so the full TLS session gets sent as a plain TCP stream. There is support for HTTPS within frp using plugin = https2http, but I like my setup better.

        As to your question of “what happens when the frpcs go offline?”, it depends on service type. I only use services of type = tcp and type = udp, so can’t speak to anything beyond that with experience.

        In the case of type = tcp your frps you can run multiple frpcs and the frps will load-balance to them, meaning if you run multiple you should get some level of HA because if one connection breaks it should just use the other, killing any still-open connections to the failed frpc. Same thought there as how e.g. cloudflared using their Tunnels feature makes two connections to two of their datacenters. If there is nothing to handle a particular TCP service on an frps I think the connection gets refused, it may even stop listening on the port, but I’m not sure of that.

        Sadly in the case of type = udp the frps will only accept one frpc connection. I still run multiple frpcs, but those particular connections just fail and keep retrying until the “active” frpc for that udp service dies. I believe this means that if there is nothing to handle a particular UDP service on an frps it just drops the packets since there isn’t really a “connection” to kill/refuse/reset, the same thing about stopping listening may apply here as well but I am also unsure in this case.

        My wishlist for frp is, in no particular order:

        • frpc making multiple connections to a server
        • frpc being able to connect to multiple servers
        • Some sort of native ALPN handling in frps, and ability to use a custom ALPN protocol for frp traffic (so I can run client traffic and frp traffic on the same port)
        • frps support for loadbalancing to multiple UDP via some sort of session tracking, triple-based routing, or something else
        • frps support for clustering or something, so even if one frps didn’t have a way to route a service it could talk to another frps nearby that did
          • or even support for tiering the idea of “locality”, first it tries on the local machine, then it tries in the same zone/region/etc
        • It’d be super neat if there were a way to do something like Cloudflare’s “Keyless SSL”

        Overall I am pretty happy with frp, but it seems like it is trying to solve too much (e.g “secret” services, p2p, HTTP, TCP multiplexing). I would love to see something more focused purely TCP/UDP (and maybe TLS/QUIC) edge-ingress emerge and solve a narrower problem space even better. Maybe there is some sort of complex network-level solution with a VPN and routing daemons (BGP?) and firewall/NAT stuff that could do this better, but I really just want a tiny executable and/or container I can run on both ends and have things “just work”.

        <pipedream> I want the technology to build something similar to Cloudflare incredibly simply, and for more providers to be able to offer something similar. Maybe there is something that could be built to solve this if they open source Oxy. </pipedream>

        • Spezi@feddit.de
          link
          fedilink
          English
          arrow-up
          1
          ·
          1 year ago

          Wow, what a rich response. I’ll be able to learn from that for days! Thank you very much!

          Especially love the hints about integrating with docker. I often struggle understanding why people like to use it, but this bit about integrating frp here really gave me a little new perspective.

  • Invalid@kbin.social
    link
    fedilink
    arrow-up
    3
    ·
    1 year ago

    Cloudflare yes. Even if you aren’t using tunnels it will help obfuscate your real ip. If you are hosting personal services you can also block access from countries you don’t expect to access them from.

    Also it seems most bots scanning domains are checking www and the base domain url. I recommend pointing those at a vps or something like GitHub or substack if you don’t need it for something else.

    Use a reverse proxy that 404s anything besides the subdomains you are actually using. Always use wildcard certs to avoid exposing subdomains and obfuscate your subdomains for common services to make them hard to guess.

    Isolate your servers from the rest of your network with vlans if possible.

    You will never be fully immune so all you can do is add more layers and roadblocks.

  • zebus@kbin.social
    link
    fedilink
    arrow-up
    2
    ·
    1 year ago

    Tailscale, super easy install, sets up a VPN into your services, no port opening needed

  • dustojnikhummer@lemmy.world
    link
    fedilink
    English
    arrow-up
    2
    ·
    1 year ago

    The most secure one would be not opening anything out, and using Tailscale to VPN into your home network.

    If you want to open stuff, Cloudflare + letsEncrypt + good router/firewall will be a start.

  • slashzero@hakbox.social
    link
    fedilink
    English
    arrow-up
    1
    ·
    1 year ago

    I think the safest option is to not host from your home network. If you aren’t up to date on security patches, you could potentially expose a lot of data from an insecure server running inside your network.

    There are precautions you can take, like isolating any external facing servers from the rest of your network, for example, but I generally recommend using a hosted service instead.

  • jadedctrl@sopuli.xyz
    link
    fedilink
    English
    arrow-up
    1
    ·
    edit-2
    1 year ago

    From what I understand, opening a port isn’t a risk in and of itself — it’s only a risk if the software using the port is insecure! So long as you use reliable software and take care to configure things properly (following through with instructions from a site like ArchWiki or the official documentation helps), you’re good.

    CloudFlare is more for DDOS protection, which you almost certainly don’t need . You could always set up DDOS protection later on, if the need ever arises.

    • i_am_not_a_robot@discuss.tchncs.de
      link
      fedilink
      English
      arrow-up
      0
      arrow-down
      1
      ·
      1 year ago

      Yeah, unless you’re worried about people targeting your IP specifically, using a reverse proxy service seems like more complexity without more security. Not opening ports, and especially not opening well known ports, is just superstition. It just changes where somebody connects to the service without limiting access to or securing the service.

  • fedorafan@iusearchlinux.fyi
    link
    fedilink
    English
    arrow-up
    1
    ·
    1 year ago

    This is very much a choose your own adventure that depends on a number of factors such as the services you’re hosting, ease of access for other household members, your hosting setup, additional privacy concerns, ect.

    Here a couple of resources for different methods:

    Techno Tim’s overview, reverse proxy through cloudflare https://www.youtube.com/watch?v=Cs8yOmTJNYQ

    Cloudflare proxy straight to the hosted service https://www.cloudflare.com/products/tunnel/

    Create a peer to peer vpn sidestepping opening ports: https://tailscale.com/blog/how-tailscale-works/

  • Midas@ymmel.nl
    link
    fedilink
    English
    arrow-up
    1
    ·
    edit-2
    1 year ago

    First you’ve got to determine where threats can come from, then which surfaces are vulnerable and eventually the reach. In short what I mean:

    SSH port (default 22) is high on the threat encounter level. Lots of bots try to scan every host they can find for an open SSH port. The risk is high because this is a doorway to your network. There’s honestly no good reason to have port 22 open to your home. Get tailscale vpn. There are alternatives, I use tailscale, it’s great.

    When youre hosting apps, they can also be vulnerable. Keep them updated and you’ll mostly be fine. There are levels of security. Super super secure is creating seperate networks for these apps so they can’t access others. Bit much imo. Use non-rooted docker, enough of a sandbox.

    In the end you’re a small fish in a big pond, not saying you should be a cowboy but with a few decent measures you should be OK.

    Tl;dr

    • don’t open port 22
    • use a VPN (tailscale)
    • update apps
    • non-rooted docker
    • iliketurtles@lemmy.world
      link
      fedilink
      English
      arrow-up
      0
      ·
      1 year ago

      What’s wrong with exposing port 22? I have password authentication disabled, ssh keys only. Isn’t that secure enough?

      • macgregor@lemmy.world
        link
        fedilink
        English
        arrow-up
        0
        ·
        1 year ago

        I do as well on a non-standard port, although that doesn’t really provide any extra security. I found ssh only login acceptably secure personally, but it’s definitely less secure than tailscale which can operate with 0 open ports. The risk would be from os/sshd vulnerabilities that can be exploited. As long as you keep the router up to date it should be safe enough.

        • easeKItMAn@lemmy.world
          link
          fedilink
          English
          arrow-up
          1
          ·
          edit-2
          1 year ago

          Why would you expose SSH on a home production server?
          Hosting several dockerized apps for friends since years. Only 80/443 proxy ports are open. Apps are secured with 2FA and monitored by fail2ban + kept up-to-date. Never had any issue.

          • macgregor@lemmy.world
            link
            fedilink
            English
            arrow-up
            0
            ·
            1 year ago

            It’s for the chance that I need to administer my cluster when I am not on my LAN. I can set up a port forward to the externally accessible port and everything works as normal like I’m on my LAN. Non-default port, password auth disabled, ssh with root disabled (so you have to have my user and ssh key) and limited ssh connection attempts before ban. I can toggle it on or off with a check box on my router. Yes, I understand there are other ways that are even more secure, yes I understand the risks, but for my circumstances this was a good balance of convenience and security. I’ve also never had an issue :).

          • ShortN0te@lemmy.ml
            link
            fedilink
            English
            arrow-up
            0
            ·
            1 year ago

            Why not? Openssh has proven itself to be reasonable secure. Porbably more research went into its security then most apps you are hosting.

            • easeKItMAn@lemmy.world
              link
              fedilink
              English
              arrow-up
              0
              arrow-down
              1
              ·
              1 year ago

              I think it’s not so much “insecure” as that it’s that external SSH access is less secure than no access. And for home-managed systems exposed externally, I would recommend a smaller attack area.

  • x4740N@lemmy.world
    link
    fedilink
    English
    arrow-up
    1
    ·
    1 year ago

    One way to think of being secure is “how can this be abused”

    Its a good way to think of how you can secure stuff

  • passepartout@feddit.de
    link
    fedilink
    English
    arrow-up
    1
    arrow-down
    1
    ·
    edit-2
    1 year ago

    As an addition to the options the others have given you, you could achieve a really secure setup with a VPN either on your home router, or on a Raspberry pi / VM / Container / Whatever using e.g. PiVPN. You would have to open a port on your router and forward it to the PiVPN. When logging into the pivpn, your device will behave just like you’re inside your home network (if you want it to). If you use wireguard and secure the machine with fail2ban you should be good. Wireguard uses UDP only, this means malicious packets coming to your VPN will simply be disregarded. This means the attacker won’t see / recognise any open ports at all. I did the same in the past and configured my raspberry pi to check if my IP has changed (global IPv6, b.c. my ISP doesn’t hand out native/routable IPv4 adresses) and then update a DNS entry pointing to my pi.