Dynamic DNS for SMBs
Generated using AI

Dynamic DNS for SMBs

You are an in-the-garage entrepreneur wanting to host your own servers and services. You have an internet service that assigns a random IP to your WiFi modem. Your ISP refuses to give you a static IP. What can you do?

Buy services from companies like dyn.com that'll cost you $55 per year as of this writing. On top of it you will be spending to buy a domain too (about $20/year). Why spend that extra $55? Continue reading to know how.

Choose a domain registrar like ionos.com that allow you to update DNS records through APIs. You can get your domain (e.g. example.com) to be resolving to your home IP. All you need is a spare computer running Linux. It can even be a Raspberry Pi Zero W. Use their API to update the IP assigned to your router by your ISP.

#!/bin/bash

IP=$(curl https://myexternalip.com/raw 2>/dev/null)
currentIP=$(getent hosts example.com| awk '{print $1}')
if [[ $currentIP == $IP ]]
then
    echo "$currentIP == $IP"
    exit;
fi;

curl -v https://ipv4.api.hosting.ionos.com/dns/v1/dyndns?q=[A long string you'd get from using ionos to update your DNS]

        

The above script gets your external ip - the IP assigned to your Wifi router at home by your ISP. It also gets the current IP that is configured in your DNS. If they match, there is nothing to do - may be just print the IPs are matching. If they don't match, then use the ISP's APIs to update your external IP.

I've created a cronjob on my server to call this script every 10 minutes. When the IPs are updated at the DNS, it'll take some time to be propagated. So, your service will see some downtime. However, if most of your clientele are from the US, you can manage that by changing your IP in the wee hours of the morning.

How do you change your external IP? When your WiFi router restarts, it requests IP from your ISP. The ISP assigns you an IP based on their policy. Since we don't know how long you're allowed to keep that IP, we force their hand by scheduling to restart your router at 3AM local time.

要查看或添加评论,请登录

社区洞察

其他会员也浏览了