Redirect a subdomain on my home (dynamic) IP

Discussion in 'Server Operation' started by MicioMax, Jun 27, 2022.

  1. MicioMax

    MicioMax New Member

    Hi,
    I have a server in a server farm, static IP, managed by ISPConfig, and some registered domains on it.
    Let's say, for example I have mydomain.com up and running; the nameserver is NOT on my server but I let on my provider's one.
    I can of course manage all records from there.
    Now I'd like to add a 2nd level, let's say home.mydomain.com, and all requests on it redirected to my home (dynamic) IP.
    I know that this could be done by a dyndns service, but I'd prefere handle it on my server; no problem to run a script to keep my dynamic IP updated to my server (I guess it could be done from inside my fritzbox router, using dynamic dns tools...).
    In short :
    - I browse https://home.mydomain.com
    - request goes to my remote server, as usual
    - remote server has my (current) dynamic IP and redirects the request on it. Redirects shall follow my dynamic IP changes, of course.
    My home server is simply a NAS on a raspberry PI device (openmediavault) with owncloud server; I'll use it for less important but big data (photos, videos) which are usint too much space on my remote server, and I would like to use it as I'm doing now, so with nextcloud.mydomain.com.

    I searched in many places, but I found only "confusing" (at least for me...) instructions.

    Thank you

    Max
     
  2. Jesse Norell

    Jesse Norell Well-Known Member Staff Member Howtoforge Staff

    What part are you needing help with? Also, what do you mean by 'redirect'? An actual http redirect, or to reverse proxy the request?
     
  3. ahrasis

    ahrasis Well-Known Member HowtoForge Supporter

    Actually you can run a lot from home even with dynamic dns. Try googling:
     
  4. MicioMax

    MicioMax New Member

    Probably some kind of reverse proxy over a dynamic IP destination.
    I googled for reverse proxy setup, but didn't find anything about having it transfer on dynamic IP...
    The alternative (which I don't like too much) would be to setup a dynamic dns service on my server.
     
  5. ahrasis

    ahrasis Well-Known Member HowtoForge Supporter

    To me you still need dynamic dns for your home server though you may think you need not because how else can your external server gonna link to it, right?

    Reverse proxy is quite straight forward with ISPConfig at least with apache2 but nginx is a little bit more tougher, so it seems. If you already have the former, try the default first, then modify according to your need.

    I am sure there are several topics in howtoforge discussing about this already but I am not keeping tab on them but may be @Jesse Norell and others know them better.
     
  6. MicioMax

    MicioMax New Member

    My idea is :
    - my homeserver sends its IP to my remote one in some way (cron job - dyndns stuffs directly from router, etc)
    - my server updates the destination IP internally
    - from outside I should see home.mydomain.com pointing to my REMOTE host, not my home dynamic IP
    - the redirect stuff should be handled transparently by my remote server

    So it's not a dynamic dns but a reverse proxy on dynamic IP.
     
  7. ahrasis

    ahrasis Well-Known Member HowtoForge Supporter

    Weird as it may sound but that is actually how dynamic dns functions. It checks and updates its current IP and send it to other server.

    You might want to note that your reverse proxy need that IP to pass that domain to, so, other than a script to pass that IP from home server to that remote server, that remote server also have to change IP in the ISPConfig database, resync so that the reverse proxy vhost will be updated with that new IP.

    That kinda like a very long process but you want it that way, right? Or... tell us more, please.
     
  8. MicioMax

    MicioMax New Member

    As far as I know, that's NOT the way of dynamic dns.
    On dynamic dns the host name get translated to current IP, so if you ping, for example, home.mydomain.com you get he HOME dynamic IP, not the remote server's one. You even don't need the remote server, but just any service that offer dynamic dns.
    What I want to achieve is quite different.
     
  9. Taleman

    Taleman Well-Known Member HowtoForge Supporter

  10. ahrasis

    ahrasis Well-Known Member HowtoForge Supporter

    That is only one way of looking how it works, so google and read yourself all about dynamic dns because the second one, the non traditional one, is mentioned in the wiki referred to @Taleman above as well, and your plan fell into it.

    Besides, I already described how you may want to achieve it your own long way as well, so it is all up you.

    I bet there is no instructions about such scripts both at your home server and your remote server and you have to figure that out, since it's your preferred way, but as said there are a lot of discussions on how to do the reverse proxy in ISPConfig.

    Good luck!
     
  11. ahrasis

    ahrasis Well-Known Member HowtoForge Supporter

    I forgot to share my solution which is using the traditional dynamic dns and giving your home server another FQDN and using that instead of using dynamic IP in the reverse proxy vhost on your remote server.

    Good luck!
     
  12. Jesse Norell

    Jesse Norell Well-Known Member Staff Member Howtoforge Staff

    There are numerous ways you could pull that off, the first that comes to mind is to setup a wireguard VPN between your home and remote server and configure the reverse proxy to use the VPN tunnel ip (or other ip at your home if more appropriate). Any time your home changes ip addrs, the VPN reconnects and things continue as normal.
     
    MicioMax likes this.
  13. MicioMax

    MicioMax New Member

    Yep... the link you posted is for DDNS. I'd like a different approach, which doesn't involve DNS record updates.
     
  14. MicioMax

    MicioMax New Member

    This is an interesting approach... but I have no idea on how to build such a VPN.
    I mean... I guess that the tunnel must be created by home side, with the dynamic IP. On server side what happens ?
     
  15. Jesse Norell

    Jesse Norell Well-Known Member Staff Member Howtoforge Staff

    "Google" it.
    The "server" receives a connection from the "client" (everyone is a "peer" in wireguard, there isn't actually a server/client definition, but you can make them act that way). Wireguard is pretty simple, in that regard you simply specify the "server's" ip address in the "client" config, but do not specify a "client" ip in the "server" config.
     
    MicioMax likes this.
  16. MicioMax

    MicioMax New Member

    So, if I did understand correctly, I open from (dynamic) IP client the VPN to the server. Ok. And from what I got (quickly) from google, on both server and client sides I've a network card named wg0.
    I've got a couple of questions:
    1) If my (dynamic) peer changes its IP (it happens without advice, of course, a couple of times each day) I can reconnect to the server, but what will do the server side if a connection was already established with former IP and never closed ?
    2) can I use a port forwarding of 51820 port (or wathever port is used) from router to my internal network, keeping the stuff working ?
    3) The AllowedIPs stuff on server is needed, right ? So I must list all possible IP from my home provider ?
     
  17. MicioMax

    MicioMax New Member

    Thank you, your method with VPN works perfectly... just a small problem with browser url rewrite, but that's a nextcloud problem.
    That's exactly what I wanted to have, non dns changes, not exposing my home ip directly and automatical update on ip change.
     

Share This Page