Say I have a public server with a service (email, web server, etc) that’s accessible through https://myservice.example.com, and I would like to restrict that service with a VPN. How do I do that?

I know how to setup a VPN. I know how to use some of the services through that VPN. But see, if I want to use that VPN, I connect my client to that VPN, then I get the subnet of that VPN, say 10.10.100.0, through which I can access the devices by address.

But I see some services offer things like https://myservice.example.com, and they only work when that VPN is connected. How does that work? Is it just some DNS setting at the domain level or there’s more to it?

  • pe1uca
    link
    fedilink
    English
    arrow-up
    1
    ·
    1 year ago

    About the DNS, you can use an internal DNS and find some way for your VPN to configure it in all the machines connected to it.
    DNS usually has a fall back if the name is not found, so you can always have your custom DNS on and it’ll first check its own records then check for some level up (I’m basing this off of my experience with with pihole https://docs.pi-hole.net/ftldns/ )

    About your ports question: you just need to change the ip to the VPN one.
    For example, I have a VPS which has a public IP and I have tailscale installed.
    If I were to make my service listen to all interfaces I could use 1.2.3.4:1194 or 100.100.100.100:1194 (this being the tailscale ip)
    But I usually only configure them to listen to tailscale0, so I can no longer reach them with 1.2.3.4:1194, only with the tailscale ip.
    In your DNS you need to configure this new IP to be served.

    I’m guessing you can also do some configuration with a firewall.
    Probably ufw add allow from 10.0.0.0/8 could work if this was the IP range of your VPN, then any one can still use your public IP and only your VPN will be able to connect (But don’t quote me on this, I haven’t done it).
    (Just be sure to check the configuration of your service, docker can bypass ufw :/ )

    • TheQuantumPhysicist@lemmy.worldOP
      link
      fedilink
      English
      arrow-up
      2
      ·
      1 year ago

      Thank you, but my question was specifically about DNS. Another person pointed out that setting the DNS record to the VPN destination is the right answer. I appreciate the details you wrote and I’ll look into them.