Hosting servers on premise or within your home does require some additional setup such as pointing your DNS to your premise and setting up firewalls, reverse proxies, VLANS if required, and the list goes on. But what happens if your isp doesn’t provide you with a static IP address? In this case, your public IP address can change when your DHCP lease expires or if you disconnect and reconnect to your service. I’ve even had cases, where I need to point a DNS to a server connected over a 4G network where static IP addresses aren’t even possible and the IP address can change at any moment. This is where Dynamic DNS comes in.
Dynamic DNS is where DNS records are updated when your public IP address changes or is updated periodically. There are paid services and some free services which are easy to set up and do work quite well but a lot of control is taken out of your hands such as query response times. When dealing with production workloads this can be far from ideal.
Amazon Web Services provides an affordable DNS service (Route 53) with APIs to allow your to update DNS zone records. To create our own Dynamic DNS service you can either create a
To check for the public IP address we are going to use AWS’ check IP endpoint (http://checkip.amazonaws.com)
import java.net.*; import java.io.*; URL whatismyip = new URL("http://checkip.amazonaws.com"); BufferedReader in = new BufferedReader(new InputStreamReader( whatismyip.openStream())); String ip = in.readLine(); //you get the IP as a String System.out.println(ip);
After this use the AWS SDK (https://aws.amazon.com/tools/#SDK) to update your DNS record.
- Faster loading times
- Control over costing
- High availability
- DNS caching. DNS works by caching the results of a query allowing subsequent queries to use the cache improving speed and reducing the load on a DNS service. If your server’s external IP address changes it may take some time for the DNS update to propagate leading to a potential loss in service. One way to reduce this is to make the TTL shorter so that it won’t be cached for too long.