Codementor Events

Cloud servers and IP addresses

Published Feb 25, 2020

A number of cloud providers - aws, google, azume etc.
All of these give us the ability to start up a server very quickly.

How to access these servers? Everytime we start the servers, the ip address will change.
Wouldn't it be good to be able to access the machine without knowing the ip address.

noip.com comes to the rescue. Here you can create a host name and assign it to your cloud instance's ip address.

Here is how the typical screen shot looks like once the updates are made in noip website.

image.png

Now we are left with one more issue to resolve.
How to update the noip site if the ip of the cloud instance changes ( this happens when you reboot the instance).

Thankfully, noip gives us an easy way to change the ip.

We just have to call this url with the right userid, password and ip address:

http://" + username + ":" + password + "@dynupdate.no-ip.com/nic/update?hostname=" + myurl + "&myip=" + myip

There is a python script that we do the updation. This script can be scheduled at start up. The script is a python 2.7 script.

!/usr/bin/python
import urllib
myurl = "stratfitqawebic.ddns.net"
username = "<yournoipuserid>"
password = "<yourpnoipPassword>"
web_page = urllib.urlopen("http://iptools.bizhat.com/ipv4.php")
myip = web_page.read()
print "Your IP is " + myip + "\n"
update_url = "http://" + username + ":" + password + "@dynupdate.no-ip.com/nic/update?hostname=" + myurl + "&myip=" + myip
print update_url + "\n"
print urllib.urlopen(update_url).read()

We need to schedule the above script.
To schedule the script, login to your instance as root
crontab -e
add the following entry at the end:

@reboot sleep 60 && python /home/rajaram_class_gmail_com/updatenoip.py

Why did we add sleep to the above command.
We added it so that that the startup processes / services can complete running.

Discover and read more posts from Rajaram K
get started