How to map my private ip, which dynamically changes to my vps_ip?

I created a drop in digitalocean, I can use vps_ip.
In my house, the way to connect to the Internet: route + modem + advertising.
I built wordpress on a local computer in my house.
The network status is shown below when you connect to the network.

WAN: MACommitted for privacy IPpublic_ip PPPoE subnet mask:255.255.255.255 gateway:153.0.68.1 DNS:114.114.114.114 223.5.5.5 LAN MACommitted for privacy IP :192.168.1.1 subnet mask:255.255.255.0 DHCPactive ifconfig inet addr:192.168.1.100 Bcast:192.168.1.255 Mask:255.255.255.0 

My goal: to give the public access to my wordpress site on my home computer using vps_ip digitalocean.

Thanks CrypticDesigns.
https://www.digitalocean.com/community/questions/how-to-map-my-local-ip-192-168-1-100-with-my-vps_ip ?
I solved the problem using CrypticDesigns.

In my local network:
On my port 80, portorward port and private ip 192.168.1.100 to the outside of your network.

In a public drip system:

 sudo apt-get install nginx sudo nano /etc/nginx/sites-available/default server { listen *:80; server_name vps_ip; rewrite .* http://publlic_ip$request_uri permanent; } sudo service nginx restart 

Anyone posting to vpsip can now view my wordpress. It is important that my IP address on wan changes approximately every 30 minutes. After about 30 minutes?
The publication will change, the configuration file / etc / nginx / sites -available / default will not work.
I want to improve this problem.
My opinion is to make sure: 1. on my home computer
The curl ipinfo.io/ip command can get my public ip.
Write it to crontab every 30 minutes.
2.send vpsip and change the publicip value in / etc / nginx / sites -available / default
, and restart nginx.

How to express two steps with a shell command to make the process automatic?

+6
source share
4 answers

There are many ways to counter this. For me, this is the easiest, without the need to install additional software or subscribe to dynamic DNS sites.

I do not know if there was a temporary problem, but ipinfo.io did not work for me, so I use a different service in the solution. Change it if you want.

First, on the local PC, write the IP address that you have on the remote / etc / nginx / sites -available / default (the one you called publlic_ip) to / tmp / oldIP. Just IP, for example:

 20.20.20.20 

This needs to be done only once. Then save the script wherever you want, grant it execute permissions and add it to cron:

 #!/bin/bash VPS_IP= #fill this VPS_USER= #fill this MyOldIP=$(cat /tmp/oldIP) MyIP=$(curl http://bot.whatismyipaddress.com) if [ $MyOldIP != $MyIP ] ; then ssh $VPS_USER@ $VPS_IP "sudo sed -i 's/$MyOldIP/$MyIP/' /etc/nginx/sites-available/default" \ && ssh $VPS_USER@ $VPS_IP sudo service nginx restart fi 
+1
source

If you google "dyndns", you will find several providers that give you a "dynamic domain name" for free. You must subscribe to one of them.

There are many clients that will keep the dynamic domain name in sync with your dynamic IP address. The dyndns provider you choose is likely to get all the necessary information about customers suitable for their service. Just run the client on your home computer and alt, the dynamic name doman will always point to your dynamic IP! Even some home routers can update your dynamic domain name for you, and then you don’t even have to start the client.

Then change the nginx configuration by pointing to the dynamic domain name (and not your IP address).

+1
source

I am using ddclient which should already be available on Debian distributions

 apt-get install ddclient 

Unable to configure /etc/ddclient.conf :

 protocol=dyndns2 syslog=yes ssl=yes use=web, web=checkip.dynu.com/, web-skip='IP Address' server=api.dynu.com login=<your email> password='<your password>' <your subdomain>.dynu.com 

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

+1
source
  • I suggest you use proxy_pass and upstream , instead of switching from rewrite . This ensures that your website is always accessible through your VPS provider, without showing your dynamic IPv4 address, which may change from time to time (thus disabling bookmarks that your users can do is use redirects through the rewrite directive, as well as the cancellation of the search index created by Google / Yandex, etc.).

    • Like other recommendations, you can use one of these dynamic DNS providers to always have a domain name that resolves your IPv4 address, and then use that domain name from the nginx configuration. Only some of the most popular options:

      Note, however, that nginx will only try to resolve the domain name once at startup, so you will have to restart it to get any possible changes.

      Also, if your IPv4 address does change every 30 minutes, and not once every couple of years or so, then you are doing this update (regardless of Dynamic DNS or not), this approach is most likely It’s not only likely to result in downtime (which you could deal with proxy_cache in nginx), but it will also allow your subscribers in your home Internet service provider to impersonate your web, while your IPv4 address has changed, and the time when the update was applied to the VPS, or if your line or power went down.

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

    • Instead of trying to track your dynamic IPv4 address, you can instead succeed in getting a free IPv6 tunnel and static IPv6 distribution. In this case, you could instead publish your IPv6 address directly to the world and use only the VPS clients for the IPv4 proxy.

      http://SixXS.net/

    • Instead of having your VPS connected to your home machine, this would be a much better, reliable and reliable approach, instead, instead, instead of your home phone, phone back to VPS. You can make such a call using a VPN or IPsec solution or even a simple old OpenSSH .

      In this case, you just have to have (0), the VPS hard drive address in your home field and (1), the private IP address and port number of your home computer, hard-coded into nginx on your VPS. This ensures that not only nobody can steal your connection (since it will be completely encrypted and authenticated), but also anywhere in any configuration files your dynamic IPv4 address will not be hard-coded.

      If you use ssh , you can either upgrade to a newer version of the tunnel interface or use normal port forwarding.


On VPS:

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

On a home machine, if you are using 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'

+1
source

All Articles