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

August 20, 2015 1.8k views

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.

MAC:ommitted for privacy
IP :public_ip PPPoE
subnet mask:

MAC:ommitted for privacy
IP :
subnet mask:

inet addr: Bcast: Mask:

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  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 vpsip 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 vpsip and change the value of publicip in /etc/nginx/sites-available/default
,and restart nginx.

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

6 Answers

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.

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.

In the client:

1.apt-get install -y curl
2.vim /home/getpublicip.sh
curl ipinfo.io/ip #That command can get my public ip such as .
vim /var/spool/cron/crontabs/root
*/30 * * * * /home/getpublicip.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/getpublicip.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)

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

  • Hello elearn,
    I didn't see your messages lately because I didn't get notified. Next time just click on "Reply" underneath one of my answers.
    I just got home, I will write you a script asap.

I am anxious to waiting for your script.

  • Hello, I am currently making a script for you.
    Are you using plan text passwords over your linux servers or SSH keys?
    SSH keys should be best to use since its more secure and easier for the script.

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

Have another answer? Share your knowledge.