Question

How to map my private ip which change dynamically onto my vps_ip in digitaloean's droplet?

  • Posted August 20, 2015
  • Nginx

I have create a droplet in digitalocean,there is a vps_ip i can use. In my home the way connected to the internet is: route+modem+adsl. I built a wordpress on the local pc on my home. The net status is as below when to connect to the web.

WAN: MAC:ommitted for privacy IP :public_ip PPPoE subnet mask:255.255.255.255 gateway:153.0.68.1 DNS:114.114.114.114 223.5.5.5

LAN MAC:ommitted for privacy IP :192.168.1.1 subnet mask:255.255.255.0 DHCP:active

ifconfig inet addr:192.168.1.100 Bcast:192.168.1.255 Mask:255.255.255.0

My goal: let the public access my wordpress site on the home pc with vps_ip digitalocean gave me.

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

In my local network:

On my router portforward port 80 and private ip 192.168.1.100  to the outside of your network.

In public droplet 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 who go to the vps_ip can browse my wordpress now. It is important that my ip address on the wan changes about every 30 minutes.How about 30 minutes later? The public_ip will change,the configurration file /etc/nginx/sites-available/default can’t work . I want to make improvements on the problem. It is my opinion to make the task done that : 1.in my home pc The command curl ipinfo.io/ip can get my public ip. Write it into crontab for every 30 minutes. 2.send the vps_ip and change the value of public_ip in /etc/nginx/sites-available/default ,and restart nginx.

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

Subscribe
Share

Submit an answer
You can type!ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

yes ssh and password to connect to my vps_ip at digitalocean.Do you need it to test the script?

I am anxious to waiting for your script.

dear CrypticDesigns , i have no script to make my target done,would you mind write it for me ?Both the client and server script?

In the client:

1.apt-get install -y curl 2.vim /home/get_public_ip.sh curl ipinfo.io/ip #That command can get my public ip such as 113.58.136.52 . vim /var/spool/cron/crontabs/root */30 * * * * /home/get_public_ip.sh The client in my home is only half done ,i don’t know how to send the public ip to server . Please fix the /home/get_public_ip.sh for me.

In the server: I have only a bit of thoughts 1.receive the message which carry public ip info 2.send to public ip as a argument parameter into /etc/nginx/sites-available/default 3.restart the /etc/nginx/sites-available/default I totally don’t know how to make my thoughs into executable codes.

You can write all the whole process with bash or php (i know a bit of it)

No CrypticDesigns , all the customers in my zone are treated this way , the isp change our public ip per 30 minutes for everyone, i have asked to get a static ip, isp don’t provider that ,i don’t know why. I really appreciate that you will write script for me to solve the problem. Thank you in advance.

No problem for that, but what do you mean?

It is important that my ip address on the wan changes about every 30 minutes.How about 30 minutes later? The publicip will change,the configurration file /etc/nginx/sites-available/default can’t work .

You mean your WAN IP at your home network changes every 30 minutes? That means you got a dynamic IP from your ISP. If you want to keep that static, you need to talk to your ISP and ask them if you can get a static WAN IP. (This is the easiest way atleast)

If this doesn’t help you, I will reply here with a script. If you want that, just reply on this answer and I will get a notification.