Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
MRDGH2821 opened this issue Sep 9, 2024 · 4 comments

Comments

@MRDGH2821
Copy link

MRDGH2821 commented 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
@primez
Copy link

primez commented 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 #839

@MRDGH2821
Copy link
Author

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 #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
Copy link

primez commented Oct 12, 2024

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

@gorucci
Copy link

gorucci commented Nov 15, 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants