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

Open
opened 2025-11-20 04:24:01 -05:00 by saavagebueno · 5 comments
Owner

Originally created by @MRDGH2821 on GitHub (Sep 9, 2024).

  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
#!/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
Originally created by @MRDGH2821 on GitHub (Sep 9, 2024). 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. <details> <summary> Bash DDNS updater </summary> ```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 ``` </details>
Author
Owner

@primez commented on GitHub (Oct 12, 2024):

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

@primez commented on GitHub (Oct 12, 2024): 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
Author
Owner

@MRDGH2821 commented on GitHub (Oct 12, 2024):

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!

@MRDGH2821 commented on GitHub (Oct 12, 2024): > 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!
Author
Owner

@primez commented on GitHub (Oct 12, 2024):

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

@primez commented on GitHub (Oct 12, 2024): My implementation will also retrieve the IP of a container because the app thinks it is the host.
Author
Owner

@gorucci commented on GitHub (Nov 14, 2024):

+1 for the feature. While one can (in case of static local IPs) manage this type of records at dns hoster UI, it's not very convenient.

To be more specific, I want to manage my local service's dns at docker-compose. Thus it can be easily transferred to another machine/VM.

@gorucci commented on GitHub (Nov 14, 2024): +1 for the feature. While one can (in case of static local IPs) manage this type of records at dns hoster UI, it's not very convenient. To be more specific, I want to manage my local service's dns at docker-compose. Thus it can be easily transferred to another machine/VM.
Author
Owner

@Neustradamus commented on GitHub (Mar 15, 2025):

@qdm12: What do you think?

Linked to:

@Neustradamus commented on GitHub (Mar 15, 2025): @qdm12: What do you think? Linked to: - https://github.com/qdm12/ddns-updater/pull/839
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/ddns-updater#435