4️⃣ Get IPv4 address
6️⃣ Get IPv6 address
Get IPv6 address via eth0
$ curl -s --interface eth0 https://ipv6.ippei.uk/ip/
Get IPv4 address via specified local IP address and write to the file
$ wget -O addr.txt --bind-address=192.168.1.64 https://ipv4.ippei.uk/ip/
Update Lightsail DNS record if the IP address is changed
#!/usr/bin/bash
MYDOMAIN=your_domain.tld
MYHOST=hostname.your_domain.tld
all=`aws lightsail get-domain --domain-name "${MYDOMAIN}" --region us-east-1`
now=`echo $all | jq '.domain.domainEntries[] | select(.name == "'${MYHOST}'" and .type=="AAAA")'`
now_ip=`echo $now | jq -r '.target'`
new_ip=`curl -s --interface eth0 https://ipv6.ippei.uk/ip/`
if [ $now_ip != $new_ip ]; then
new=`echo $now | jq '.target|="'$new_ip'"'`
aws lightsail update-domain-entry --domain-name "${MYDOMAIN}" --region us-east-1 --domain-entry "$new"
echo "$now_ip -> $new_ip"
else
echo "$now_ip"
fi
now=`echo $all | jq '.domain.domainEntries[] | select(.name == "'${MYHOST}'" and .type=="A")'`
now_ip=`echo $now | jq -r '.target'`
new_ip=`curl -s --interface eth0 https://ipv4.ippei.uk/ip/`
if [ $now_ip != $new_ip ]; then
new=`echo $now | jq '.target|="'$new_ip'"'`
aws lightsail update-domain-entry --domain-name "${MYDOMAIN}" --region us-east-1 --domain-entry "$new"
echo "$now_ip -> $new_ip"
else
echo "$now_ip"
fi