FarrowStrange / hetzner-api-dyndns

A small script to dynamically update DNS records using the Hetzner DNS-API.
GNU General Public License v3.0
139 stars 38 forks source link

Find alternatives to determine the public ip address #6

Closed FarrowStrange closed 3 years ago

FarrowStrange commented 4 years ago

It should be checked whether there are alternatives to external services with which the public IP address can be determined. At the current time "ifconfig.co" is used to determine the public IPv4 and IPv6 addresses.

Maybe there is a solution which can be mapped via the Hetzner services.

chrgm commented 3 years ago

Would be great if Hetzner would host an own https://ifconfig.co instance. With this they could add a dynamic IP option which updates the DNS entry with just one request.

Otherwise I think there are this options:

FarrowStrange commented 3 years ago

I think I have found an acceptable solution - Some DNS providers like Cloudflare, Google, OpenDNS (Cisco) or Akamai provide services to query the public ip address via DNS. In case of those resolvers the DNS infrastructure is more reliable and faster than a single service like ifconfig.co.

Google:

Nameservers:

- ns1.google.com
- ns2.google.com
- ns3.google.com
- ns4.google.com

IPv4:

$ dig -4 TXT +short o-o.myaddr.l.google.com @ns1.google.com | awk -F'"' '{print $2}'

IPv6:

$ dig -6 TXT +short o-o.myaddr.l.google.com @ns1.google.com | awk -F'"' '{print $2}'

Cloudflare:

Nameservers:

- 1.1.1.1
- 2606:4700:4700::1111

IPv4:

$ dig -4 ch TXT +short whoami.cloudflare @1.1.1.1 | awk -F'"' '{print $2}'

IPv6:

$ dig -6 ch TXT +short whoami.cloudflare @2606:4700:4700::1111 | awk -F'"' '{print $2}'

OpenDNS:

Nameservers:

- resolver1.opendns.com | resolver1.ipv6-sandbox.opendns.com
- resolver2.opendns.com | resolver2.ipv6-sandbox.opendns.com
- resolver3.opendns.com | resolver3.ipv6-sandbox.opendns.com
- resolver4.opendns.com | resolver4.ipv6-sandbox.opendns.com

IPv4:

dig -4 A +short myip.opendns.com @resolver1.opendns.com

IPv6:

dig -6 AAAA +short myip.opendns.com @resolver1.ipv6-sandbox.opendns.com
chrgm commented 3 years ago

Sounds like a good idea and I also tried that. Only thing is that it creates another dependency, which in my case also created a new Linux user (tested under Manjaro).

FarrowStrange commented 3 years ago

Can you tell me what additional dependency you mean? Why do you need an additional user? The binares of dig and awk should be available in most operating systems.

chrgm commented 3 years ago

At least for Manjaro it dig comes with the bind package and this creates an user. But seems like it's just special thing in that case. But then let's go for this approach!

FarrowStrange commented 3 years ago

Under Debian/Ubuntu, dig is part of the dnsutils package. This provides various client programs related to dns, like dig, nslookup and nsupdate. Maybe there is such a tool / utils package under Manjaro / Arch as well.