The reliable solution to your problem is to periodically restart your Bitcoin Core client.
That's what I do with OpenBazaar because they store IPs instead of hostnames in the DHT and I have the exact same problem when my IP changes.
I made this little script for it (in case someone wants to modify it for their bitcoin client):
#!/bin/sh
# Create log file
LOG="/tmp/ip-check.log"
touch $LOG
IP="$(dig +short myip.opendns.com @resolver1.opendns.com)"
LAST_IP="$(cat $LOG)"
if [ "$IP" != "$LAST_IP" ]; then
# Save the new IP
echo "test"
echo $IP > $LOG
# Restart OB
sudo service openbazaar restart
fi
I check for the change every 5 minutes via crontab:
*/5 * * * * sh /home/user/bin/check.sh >/dev/null 2>&1
The other possibility is to see if your ISP may be supporting mixed IPv4/IPv6 deployment
I checked and my ISP doesn't support IPv6 AFAIK. I'll be restarting my client then.
Thanks!