qdm12 / ddns-updater

Container to update DNS records periodically with WebUI for many DNS providers
https://hub.docker.com/r/qmcgaw/ddns-updater/
MIT License
1.7k stars 161 forks source link

Feature request: Allow updating to Private IP address instead of Public IP address #809

Open MRDGH2821 opened 1 month ago

MRDGH2821 commented 1 month ago
  1. What's the feature? As the title says, please add an option to allow for DDNS updates with private IP instead of public IP.

  2. Extra information? My network is under double NAT system, and thus nothing is accessible. So in DuckDNS I have put my device's private network local IP address (192.168.1.80).

I have made a DuckDNS updater bash script which can check if the public IP is pingable or not. If yes update to that, else use private IP. So I was thinking that if such functionality can come in DDNS-Updater too, that would be nice.

Bash DDNS updater ```bash #!/usr/bin/env bash set -e # Logging configuration LOG_FILE="./duckdns_update.log" # Function to log messages log() { local message="$1" local log_message="$(date '+%Y-%m-%d %H:%M:%S') - $message" echo $message echo $log_message >>"$LOG_FILE" } # Function to get the private IP address get_private_ip() { hostname -i | awk '{print $3}' } # Function to get the public IP address get_public_ip() { curl -s https://api.ipify.org } # Function to check if an IP address is reachable is_ip_reachable() { ping -c 1 "$1" &>/dev/null return $? } # Function to update DuckDNS update_duckdns() { local ip="$1" local url="https://www.duckdns.org/update?domains=${DUCKDNS_DOMAIN}&token=${DUCKDNS_TOKEN}&ip=${ip}" response=$(curl -s "$url") log "DuckDNS update response: $response" } # Main script logic public_ip=$(get_public_ip) if [ -n "$public_ip" ] && is_ip_reachable "$public_ip"; then log "Public IP $public_ip is reachable. Updating DuckDNS..." update_duckdns "$public_ip" else private_ip=$(get_private_ip) log "Public IP ($public_ip) not reachable. Updating DuckDNS with private IP $private_ip..." update_duckdns "$private_ip" fi ```
primez commented 3 days ago

Hello @MRDGH2821,

I am not a maintainer of this project, but I also needed this feature and decided to implement it myself. I am not sure if it will be accepted but you can download the code and use my version - it has been verified in a container and a Linux env. Here is a PR https://github.com/qdm12/ddns-updater/pull/839

MRDGH2821 commented 3 days ago

Hello @MRDGH2821,

I am not a maintainer of this project, but I also needed this feature and decided to implement it myself. I am not sure if it will be accepted but you can download the code and use my version - it has been verified in a container and a Linux env. Here is a PR https://github.com/qdm12/ddns-updater/pull/839

Thanks for the implementation!

There was one limitation I faced in my bash script. If I run it on host, private IP is correct. But if run inside container, it either gives docker container's private ip or fails to find any IP.

I haven't run your code, but I'll check it out soon!

primez commented 3 days ago

My implementation will also retrieve the IP of a container because the app thinks it is the host.