Hey fellow selfhosters! Hope you’re doing well, today I would like to have some help to know how I could make this project a reality. So I would like to give to friends and family a VPN access to my homelab (probably with Wireguard).

I also have a VPS in the cloud and I can VPN to it to anonimize outgoing connections.

So basically in the case that a friend ask a local service I want the request to come to my home with his VPN connection and then comeback directly from my home.

In the case that a friend request google[dot]com I want the request to come to my house and then go trough the VPS to make the request from it and not from my home. Then comeback from google to the VPS to my home to the client.

The principal issue I have is how can I route my services directly trough my home without going into the regular WWW, but make all other requests to go trough the VPS and to the WWW

If you need some more explanations or infos, feel free to ask.

PS : I also self host PiHole so all the DNS requests should go trough it (and maybe I could use it to route requests where I want by tweaking my domain request to local IPs?)

diagramm of the network

  • Brkdncr@lemmy.world
    link
    fedilink
    English
    arrow-up
    12
    arrow-down
    1
    ·
    5 days ago

    Install Tailscale on your vps and your homelab server.

    Share the Tailscale dns of your server with guests.

    Use your vps as your exit node.

    • foremanguy@lemmy.mlOP
      link
      fedilink
      English
      arrow-up
      2
      arrow-down
      1
      ·
      5 days ago

      But if I correctly understand how Tailscale works I would need to install tailscale on all machines I wish to give access to friends?

      • Brkdncr@lemmy.world
        link
        fedilink
        English
        arrow-up
        3
        ·
        edit-2
        5 days ago

        Yes.

        Otherwise, just open up ports on your network firewall and set up DNS to point to your external ip.

        There might be a way to do this with cloudfare that is more secure.

        Edit: you might want to create a network diagram to help explain what you have and what you want to do. The way you describe the problem is confusing.

          • Brkdncr@lemmy.world
            link
            fedilink
            English
            arrow-up
            1
            ·
            5 days ago

            From the diagram you just want to put everything within a vpn so they are on the same network.

            You can choose whatever vpn solution you want but I like Tailscale since you don’t need to set up any inbound nat or firewall.

            From the diagram it looks like you want your outside clients to use vpn as well.

            • foremanguy@lemmy.mlOP
              link
              fedilink
              English
              arrow-up
              1
              ·
              5 days ago

              Nah it’s not what I want to do.

              The request from client for local services goes trough the first VPN and are resolved in my home and then comeback.

              The request from client to outside services goes trought my home with the first VPN, are resolved here and then go to the internet trough the second VPN and then comeback to the client

              • Brkdncr@lemmy.world
                link
                fedilink
                English
                arrow-up
                2
                ·
                5 days ago

                What you’re describing is overly complex routing, and split DNS.

                Join all clients to a single network.

                • foremanguy@lemmy.mlOP
                  link
                  fedilink
                  English
                  arrow-up
                  1
                  ·
                  5 days ago

                  I want to protect my home services, so when accessing my domain it goes trough the vps and you only knows its IP (a datacenter IP) but for my friends and family I don’t need this protection so they are accessing my home with a VPN connection and btw they are using the vps to make requests and so protect their privacy.

                  The simple solution (since my services are publicly available), would be to route all traffic coming from my friends trough my home and then through the vps. But I don’t like this idea since it would add a lot of latency and useless traffic since the client is already going trough my home…

                  So my question is how could I route directly to the client the local services and let go through the vps the rest of the traffic?

        • foremanguy@lemmy.mlOP
          link
          fedilink
          English
          arrow-up
          1
          ·
          5 days ago

          Right will try to make you a diagram, but I dont think tailscale would be a good solution…

  • thelittleblackbird@lemmy.world
    link
    fedilink
    English
    arrow-up
    4
    ·
    5 days ago

    I don’t have time now so I will sketch the solution

    You need a proxy server in your vps that will redirect the traffic to your home. Caddy is usually recommended here and I am planning to migrate to it (current is nginx)

    For your dns you need something is called zone name resolution, it will resolve different ip depending where the request came from

    Good luck

    • foremanguy@lemmy.mlOP
      link
      fedilink
      English
      arrow-up
      2
      ·
      5 days ago

      Didn’t know if I explained it bad, but it’s not exactly what I want to do. All the request goes trough my home (since people are VPNed to it), if they are requesting outside stuff it goes trough the VPS using VPN connection. But they request inside services it should go directly to them.

      Basically I want to know a way of routing everything trough VPS (basically a wire guard connection) but home services to avoid doing a useless journey to the internet

      • curiouschipmunk@lemmy.world
        link
        fedilink
        English
        arrow-up
        2
        ·
        5 days ago

        If all traffic is going through your homelab you can make the vpn clients use a vpn specific DNS server or the one suggested with resolving per origin, you then make the external names to your services to resolve to the servsrs’ internal IP addresses, avoiding going out. Another way is to add rules to your gateway to redirect internal traffic going to your external IP addresses to DNAT to the internal addresses but in order for that to work you need to masquerade them which means server logs will have gateway’s IP.

        • foremanguy@lemmy.mlOP
          link
          fedilink
          English
          arrow-up
          1
          ·
          5 days ago

          Yeah that’s what I was thinking thank you. But how can I restrict the access of my local network to my friends and family connecting to the VPN provided (is tailscale something to consider?)

  • DecentM@lemmy.blahaj.zone
    link
    fedilink
    English
    arrow-up
    3
    ·
    edit-2
    5 days ago

    You’re pretty much describing Tailscale with an exit node on the VPS. If the purpose of the VPS is to make their traffic not come from your home, you can omit the VPS entirely as Tailscale only routes through the VPN when reaching services also on the VPN.

    Edit: to self host it, look into Headscale, but the default, hosted control server works well too.

  • Gravitywell@sh.itjust.works
    link
    fedilink
    English
    arrow-up
    2
    ·
    edit-2
    5 days ago

    A central wireguard peer on your vps, connect home to vps and direct the wireguard. Add friends as peers on the VPS like such:

    [Interface]
    Address = 10.0.0.1/24
    ListenPort = 51820
    PrivateKey = <VPS_PRIVKEY>
    
    # Home
    [Peer]
    PublicKey = <HOME_PUBKEY>
    AllowedIPs = 10.0.0.2/32
    
    # Friend
    [Peer]
    PublicKey = <CLIENT_PUBKEY>
    AllowedIPs = 10.0.0.3/32
    

    Use iptables to Split tunnel traffic

    For the home network ip route add 192.168.1.0/24 via 1. 0.2 dev wg0

    And for the vpn To route google a .d such

    Enable NAT for clients

    iptables -t natw POSTROUTING -s 10.0.0.0/24 -o eth0 -j MASQUERADE

    You can set the iptables rules to run wjen it comes up

    Forgive my formatting. Mobile clients being janky

    • MysteriousSophon21@lemmy.world
      link
      fedilink
      English
      arrow-up
      1
      ·
      4 days ago

      This is almost right, but you’ll need more specific iptables rules for the split tunneling - try something like ip route add YOUR.HOME.SUBNET.0/24 via 10.0.0.2 on the VPS and then on the homelab add iptables -t nat -A POSTROUTING -d YOUR.HOME.SUBNET.0/24 -j ACCEPT followed by iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE to route evreything else through the VPS connection.

    • foremanguy@lemmy.mlOP
      link
      fedilink
      English
      arrow-up
      2
      ·
      5 days ago

      This is not what I exactly want to do. Requests to my home services are protected by not going directly to my home and rather going trough VPS, but since I know my friends I can let them go directly to my home without at any time go trough the VPS (expect to make up the out request).

      • Gravitywell@sh.itjust.works
        link
        fedilink
        English
        arrow-up
        2
        ·
        edit-2
        5 days ago

        In that case you would need to add the peers to the wireguard node you have running in the home lab as well. Wireguard can route peer to peer and will take the shortest path available to it.

        That said, i highly recommend first getting things working in a “spoke and hub” style wireguard configuration with either your homelab or the vps as a central peer, then add peers as endpoints after you have everyone with working connections to the central peer. Its just a heck of a lot easier to trouble shoot and get your head around thatway.

  • ohshit604@sh.itjust.works
    link
    fedilink
    English
    arrow-up
    2
    arrow-down
    1
    ·
    edit-2
    5 days ago

    This is absolutely possible as I do it myself however, executed entirely differently, my ASUS WRT Router with Merlin firmware handles the VPN server and it routes the IP range through my VPN provider (Proton), on the clients end their device see a Proton IP.

    Didn’t have to mess with config files or anything, install the custom firmware and created a rule for the routing in the VPN Director.