Map domain name to public IP

Mapping to static IP addresses

1) Find the IPv4 address of your router

dig +short myip.opendns.com @resolver1.opendns.com

2) Log in to your domain name provider (say, google domains) and navigate to DNS settings of your registered domain

3) Edit the following records (minimal configuration)

A ---> Public IPv4 (if IPv4 is static)

CNAME ---> maps one name to another. By default, domain names are not appended with www. Therefore, we have to set this record to map www.mlr2d.com to mlr2d.com

Mapping to dynamic IP addresses

1) Since there is an acute shortage of Ipv4 address, most ISP do not provide static ip.

2) Fortunately, google domain allows us to manage dynamic DNS settings

3) Edit the following,

Synthetic records --> Dynamic DNS(from drop down) --> Subdomain=@ --> Add (Note down username and password)

Custom resource records --> CNAME --> (same as static)

4) Update google name server from your host machine at regular intervals after starting your server. The following script can be used to update IP address in your DNS settings

yml
    USERNAME="FROM_DYNAMIC_DNS"
    PASSWORD="FROM_DYNAMIC_DNS"
    HOSTNAME="mlr2d.com"

    # Resolve current public IP
    IP=$( dig +short myip.opendns.com @resolver1.opendns.com )
    # Update Google DNS Record
    URL="https://${USERNAME}:${PASSWORD}@domains.google.com/nic/update?hostname=${HOSTNAME}&myip=${IP}"
    curl -s $URL

NOTE: It may take up to 1m for changes to reflect after updating (because DDNS TTL was set to 1m, which means it refreshes cache every 1m)