How to map my private ip which change dynamically onto my vps_ip? How to map my private ip which change dynamically onto my vps_ip? nginx nginx

How to map my private ip which change dynamically onto my vps_ip?


If you google "dyndns" you will find multiple providers that give you a "dynamic domain name" for free. You should sign up for one of those.

There are lots of clients that will keep the dynamic domain name in sync with your dynamic IP-address. The dyndns provider you choose will probably have all information you need about clients suitable for their service. Just run the client on your home computer, and viola, the dynamic doman name will always point to your dynamic IP! Even some home routers can update your dynamic domain name for you, and then you dont even have to run the client.

Then change your nginx configuration to point to your dynamic domain name (not your IP).


I'm using ddclient which on Debian based distros should be already available

apt-get install ddclient

Shouldn't be difficult to configure /etc/ddclient.conf:

protocol=dyndns2syslog=yesssl=yesuse=web, web=checkip.dynu.com/, web-skip='IP Address'server=api.dynu.comlogin=<your email>password='<your password>'<your subdomain>.dynu.com

It should support different protocols and dyndns providers, I personally used dynu.com for years, should be free (I'm not sure about new users).


  1. I would suggest you use proxy_pass and an upstream, instead of going with rewrite. This will make sure that your website is always available through your VPS provider, without revealing your dynamic IPv4 address, which may change from time to time (thus invalidating the bookmarks your users may make were you to use the redirects through the rewrite directive, as well as invalidating the search index generated by Google/Yandex and such).

    1. As others suggested, you could employ one of those Dynamic DNS providers to make sure to always have a domain name that resolves to your IPv4 address, and then use such domain name from within the nginx configuration. Just some most popular options:

      Note, however, that nginx will only attempt to resolve the domain name once upon startup, so, you'll have to keep restarting it in order to pick up any possible changes.

      Additionally, if your IPv4 address really does change every 30 minutes, not just once every couple of years or so, then however you do this updating (whether or not through Dynamic DNS), this approach will likely result not only in a likely downtime (which you could combat with proxy_cache in nginx), but would also allow your fellow subscribers at your home ISP to impersonate your web-site between the time your IPv4 address has changed, and the time the update has been applied on the VPS, or, also, in case your line or power goes down.

      As such, I would not recommend going with the Dynamic DNS route.

    2. Instead of trying to track your Dynamic IPv4 address, you might instead have some success in obtaining a free IPv6 tunnel and a static IPv6 allocation. In which case, you could instead decide to publish your IPv6 address directly to the world, and only use the VPS to proxy IPv4 clients.

      http://SixXS.net/

    3. Instead of having your VPS connect to your home machine, it would be a much better, reliable and robust approach to instead have your home machine phone back to the VPS instead. You could accomplish such phoning back with either a VPN or an IPsec solution, or even a plain old OpenSSH.

      In this case, you'd simply have, (0), the address of the VPS hardcoded on your home box, and, (1), the private IP address and port number of your home machine hardcoded within nginx on your VPS. This will ensure that not only can noone steal your connection (as it'll be fully encrypted and authenticated), but also that nowhere in any configuration files is your Dynamic IPv4 address will be hardcoded.

      If using ssh, you could either go with the tunnel interface in the newer version, or the plain old port forwarding.


On the VPS:

server {  listen *:80;  listen [::]:80;  server_name vps;  location / {      proxy_pass http://127.0.0.1:2280;  }}

On the home machine, provided you're running your webapp on port 8080:

sh -xc 'while (true); do ssh -v -N -C -R127.0.0.1:2280:127.0.0.1:8080 -oServerAliveInterval=20 -oServerAliveCountMax=1 user@vps; date; sleep 1; done'