anaganisk / digitalocean-dynamic-dns-ip

A simple script to automatically update Digital ocean DNS records with dynamic IP
Other
104 stars 22 forks source link

connect: cannot assign requested address #17

Closed tonydm closed 3 years ago

tonydm commented 3 years ago

I am trying to understand why I cannot remedy this error msg.

Thank you in advance!

TD

Get https://ipv6bot.whatismyipaddress.com: dial tcp [2606:6e00:c000:1000::501]:443: connect: cannot assign requested address

My config file does not contain https://ipv6bot.whatismyipaddress.com as the lookup URL for IPV4

Config

{
  "apikey": "MY_DO_API_KEY",
  "doPageSize": 20,
  "useIPv4": true,
  "useIPv6": false,
  "allowIPv4InIPv6": false,
  "ipv4CheckUrl": "http://ipecho.net/plain",
  "domains": [
    {
      "domain": "mydomain.com",
      "records": [
        {
          "name": "my_subdomain",
          "type": "A"
        }
      ]
    }
  ]
}

I am running this in a docker container built with a Linuxserver.io base image.

services-admin@docker3:[10.10.0.5:67.61.xx.xx]~/DockerServices/dynamic_dns_updater$ docker run -it --rm -v "${PWD}/data":/data lsiobase/alpine:3.11 ash
[s6-init] making user provided files available at /var/run/s6/etc...exited 0.
[s6-init] ensuring user provided files have correct perms...exited 0.
[fix-attrs.d] applying ownership & permissions fixes...
[fix-attrs.d] done.
[cont-init.d] executing container initialization scripts...
[cont-init.d] 01-envfile: executing... 
[cont-init.d] 01-envfile: exited 0.
[cont-init.d] 10-adduser: executing... 
usermod: no changes

-------------------------------------
          _         ()
         | |  ___   _    __
         | | / __| | |  /  \ 
         | | \__ \ | | | () |
         |_| |___/ |_|  \__/

Brought to you by linuxserver.io
-------------------------------------

To support LSIO projects visit:
https://www.linuxserver.io/donate/
-------------------------------------
GID/UID
-------------------------------------

User uid:    911
User gid:    911
-------------------------------------

[cont-init.d] 10-adduser: exited 0.
[cont-init.d] 90-custom-folders: executing... 
[cont-init.d] 90-custom-folders: exited 0.
[cont-init.d] 99-custom-files: executing... 
[custom-init] no custom files found exiting...
[cont-init.d] 99-custom-files: exited 0.
[cont-init.d] done.
[services.d] starting services
[services.d] done.
root@b8e3ee12893b:/#
root@b8e3ee12893b:/#
root@b8e3ee12893b:/# apk update && apk upgrade
fetch http://dl-cdn.alpinelinux.org/alpine/v3.11/main/x86_64/APKINDEX.tar.gz
fetch http://dl-cdn.alpinelinux.org/alpine/v3.11/community/x86_64/APKINDEX.tar.gz
v3.11.12-27-g76291da1fc [http://dl-cdn.alpinelinux.org/alpine/v3.11/main]
v3.11.11-124-gf2729ece5a [http://dl-cdn.alpinelinux.org/alpine/v3.11/community]
OK: 11275 distinct packages available
OK: 16 MiB in 30 packages
root@b8e3ee12893b:/#
root@b8e3ee12893b:/#
root@b8e3ee12893b:/# apk add build-base git curl go --no-cache
fetch http://dl-cdn.alpinelinux.org/alpine/v3.11/main/x86_64/APKINDEX.tar.gz
fetch http://dl-cdn.alpinelinux.org/alpine/v3.11/community/x86_64/APKINDEX.tar.gz
(1/25) Installing libgcc (9.3.0-r0)
(2/25) Installing libstdc++ (9.3.0-r0)
(3/25) Installing binutils (2.33.1-r1)
(4/25) Installing libmagic (5.37-r1)
(5/25) Installing file (5.37-r1)
(6/25) Installing gmp (6.1.2-r1)
(7/25) Installing isl (0.18-r0)
(8/25) Installing libgomp (9.3.0-r0)
(9/25) Installing libatomic (9.3.0-r0)
(10/25) Installing mpfr4 (4.0.2-r1)
(11/25) Installing mpc1 (1.1.0-r1)
(12/25) Installing gcc (9.3.0-r0)
(13/25) Installing musl-dev (1.1.24-r3)
(14/25) Installing libc-dev (0.7.2-r0)
(15/25) Installing g++ (9.3.0-r0)
(16/25) Installing make (4.2.1-r2)
(17/25) Installing fortify-headers (1.1-r0)
(18/25) Installing build-base (0.5-r1)
(19/25) Installing nghttp2-libs (1.40.0-r1)
(20/25) Installing libcurl (7.79.1-r0)
(21/25) Installing curl (7.79.1-r0)
(22/25) Installing expat (2.2.9-r1)
(23/25) Installing pcre2 (10.34-r1)
(24/25) Installing git (2.24.4-r0)
(25/25) Installing go (1.13.13-r0)
Executing busybox-1.31.1-r10.trigger
OK: 506 MiB in 55 packages
root@b8e3ee12893b:/#
root@b8e3ee12893b:/#
root@b8e3ee12893b:/# git clone https://github.com/anaganisk/digitalocean-dynamic-dns-ip.git
Cloning into 'digitalocean-dynamic-dns-ip'...
remote: Enumerating objects: 114, done.
remote: Counting objects: 100% (9/9), done.
remote: Compressing objects: 100% (7/7), done.
remote: Total 114 (delta 1), reused 4 (delta 1), pack-reused 105
Receiving objects: 100% (114/114), 30.53 KiB | 512.00 KiB/s, done.
Resolving deltas: 100% (55/55), done.
root@b8e3ee12893b:/#
root@b8e3ee12893b:/#
root@b8e3ee12893b:/# cd digitalocean-dynamic-dns-ip/
root@b8e3ee12893b:/digitalocean-dynamic-dns-ip#
root@b8e3ee12893b:/digitalocean-dynamic-dns-ip#
root@b8e3ee12893b:/digitalocean-dynamic-dns-ip# go get github.com/mitchellh/go-homedir
go: finding github.com/mitchellh/go-homedir v1.1.0
go: downloading github.com/mitchellh/go-homedir v1.1.0
go: extracting github.com/mitchellh/go-homedir v1.1.0
root@b8e3ee12893b:/digitalocean-dynamic-dns-ip#
root@b8e3ee12893b:/digitalocean-dynamic-dns-ip#
root@b8e3ee12893b:/digitalocean-dynamic-dns-ip# go build
root@b8e3ee12893b:/digitalocean-dynamic-dns-ip# cp digitalocean-dynamic-dns-ip /usr/bin/
root@b8e3ee12893b:/digitalocean-dynamic-dns-ip# chmod +x /usr/bin/digitalocean-dynamic-dns-ip
root@b8e3ee12893b:/digitalocean-dynamic-dns-ip# apk del build-base curl git
(1/13) Purging build-base (0.5-r1)
(2/13) Purging file (5.37-r1)
(3/13) Purging g++ (9.3.0-r0)
(4/13) Purging make (4.2.1-r2)
(5/13) Purging libc-dev (0.7.2-r0)
(6/13) Purging fortify-headers (1.1-r0)
(7/13) Purging curl (7.79.1-r0)
(8/13) Purging git (2.24.4-r0)
(9/13) Purging libmagic (5.37-r1)
(10/13) Purging libcurl (7.79.1-r0)
(11/13) Purging nghttp2-libs (1.40.0-r1)
(12/13) Purging expat (2.2.9-r1)
(13/13) Purging pcre2 (10.34-r1)
Executing busybox-1.31.1-r10.trigger
OK: 424 MiB in 42 packages
root@b8e3ee12893b:/digitalocean-dynamic-dns-ip# ll /data/
ash: ll: not found
root@b8e3ee12893b:/digitalocean-dynamic-dns-ip# cd ..
root@b8e3ee12893b:/#
root@b8e3ee12893b:/# rm -rf digitalocean-dynamic-dns-ip/
root@b8e3ee12893b:/#
root@b8e3ee12893b:/# digitalocean-dynamic-dns-ip /data/digitalocean-dynamic-ip.json 
2021/10/20 18:36:43 Discovered IPv4 address `67.61.xx.xx`   <------- THIS IS CORRECT
2021/10/20 18:36:43 Get https://ipv6bot.whatismyipaddress.com: dial tcp [2606:6e00:c000:1000::501]:443: connect: cannot assign requested address
root@b8e3ee12893b:/#
root@b8e3ee12893b:/#
root@b8e3ee12893b:/# ls /data/
digitalocean-dynamic-ip.json
root@b8e3ee12893b:/#
root@b8e3ee12893b:/#
root@b8e3ee12893b:/# cat /data/digitalocean-dynamic-ip.json 
{
  "apikey": "MY_DO_API_KEY",
  "doPageSize": 20,
  "useIPv4": true,
  "useIPv6": false,
  "allowIPv4InIPv6": false,
  "ipv4CheckUrl": "http://ipecho.net/plain",
  "domains": [
    {
      "domain": "mydomain.com",
      "records": [
        {
          "name": "my_subdomain",
          "type": "A"
        }
      ]
    }
  ]
}
johnjaylward commented 3 years ago

usually an error like that occurs when either the config isn't found, or there is some issue processing the config and it ends up using defaults.

johnjaylward commented 3 years ago

@tonydm given that the unmarshall call was not having it's error checked, my assumption is that you have invalid JSON on your config. if you can either run against my latest PR (#18) or just run your config though a JSON validator, you should be able to confirm the problem.

tonydm commented 3 years ago

@johnjaylward Thanks... ok... The issue info I posted shows that the config file exists and is in the path I passed to digitalocean-dynamic-dns-ip. While the json file is tiny, I checked the config using a linter and it's valid. Do you see a problem with the json config values? Aside from the obfuscated API Key, and domains. I'm not sure how to run against your PR. I see you committed it about 30min ago.

johnjaylward commented 3 years ago

it looks like you are doing a git clone and the a fresh go build

assuming you can modify the startup script, you can change the git clone to point to my fork and then add an addition step after the clone to switch to the addMoreLogs branch.

git clone https://github.com/johnjaylward/digitalocean-dynamic-dns-ip.git
cd digitalocean-dynamic-dns-ip
git checkout -b addMoreLogs
go get github.com/mitchellh/go-homedir
go build
...
tonydm commented 3 years ago

I appreciate the coach... thank you. I built digitalocean-dynamic-dns-ip using the testing branch you committed. If I built it and running correctly, I'm missing the logging. I see the same output to the console as before and I can't find a file with the logging data. Here's a detail of the what I did.

Thanks again

Discovered IP, MY API KEY, mydomain.com & mysubdomain are obfuscated

root@8fe489e34640:/# 
root@8fe489e34640:/# git clone https://github.com/johnjaylward/digitalocean-dynamic-dns-ip.git
Cloning into 'digitalocean-dynamic-dns-ip'...
remote: Enumerating objects: 99, done.
remote: Counting objects: 100% (16/16), done.
remote: Compressing objects: 100% (13/13), done.
remote: Total 99 (delta 3), reused 8 (delta 2), pack-reused 83
Receiving objects: 100% (99/99), 33.02 KiB | 497.00 KiB/s, done.
Resolving deltas: 100% (43/43), done.
root@8fe489e34640:/# 
root@8fe489e34640:/# 
root@8fe489e34640:/# cd digitalocean-dynamic-dns-ip
root@8fe489e34640:/digitalocean-dynamic-dns-ip# 
root@8fe489e34640:/digitalocean-dynamic-dns-ip# 
root@8fe489e34640:/digitalocean-dynamic-dns-ip# git checkout -b addMoreLogs
Switched to a new branch 'addMoreLogs'
root@8fe489e34640:/digitalocean-dynamic-dns-ip# 
root@8fe489e34640:/digitalocean-dynamic-dns-ip# 
root@8fe489e34640:/digitalocean-dynamic-dns-ip# go get github.com/mitchellh/go-homedir
root@8fe489e34640:/digitalocean-dynamic-dns-ip# 
root@8fe489e34640:/digitalocean-dynamic-dns-ip# go build
root@8fe489e34640:/digitalocean-dynamic-dns-ip# 
root@8fe489e34640:/digitalocean-dynamic-dns-ip# cp digitalocean-dynamic-dns-ip /usr/bin/
root@8fe489e34640:/digitalocean-dynamic-dns-ip# 
root@8fe489e34640:/digitalocean-dynamic-dns-ip# chmod +x /usr/bin/digitalocean-dynamic-dns-ip 
root@8fe489e34640:/digitalocean-dynamic-dns-ip# 
root@8fe489e34640:/digitalocean-dynamic-dns-ip# cd ../
root@8fe489e34640:/#
root@8fe489e34640:/#
root@8fe489e34640:/# cat /data/digitalocean-dynamic-ip.json 
{
  "apikey": "MY API KEY",
  "doPageSize": 20,
  "useIPv4": true,
  "useIPv6": false,
  "allowIPv4InIPv6": false,
  "ipv4CheckUrl": "http://ipecho.net/plain",
  "domains": [
    {
      "domain": "mydomain.com",
      "records": [
        {
          "name": "mysubdomain",
          "type": "A"
        }
      ]
    }
  ]
}
root@8fe489e34640:/# 
root@8fe489e34640:/# /usr/bin/digitalocean-dynamic-dns-ip /data/digitalocean-dynamic-ip.json 
2021/10/20 13:57:34 Discovered IPv4 address `67.61.xx.xx`
2021/10/20 13:57:34 Get "https://ipv6bot.whatismyipaddress.com": dial tcp [2606:6e00:c000:1000::501]:443: connect: cannot assign requested address
root@8fe489e34640:/#
root@8fe489e34640:/# ll
total 112K
drwxr-xr-x   1 root root 4.0K Oct 20 13:42 ./
drwxr-xr-x   1 root root 4.0K Oct 20 13:42 ../
-rwxr-xr-x   1 root root    0 Oct 20 13:40 .dockerenv*
drwxr-xr-x   1 abc  abc  4.0K Oct 18 23:30 app/
drwxr-xr-x   1 root root 4.0K Oct 18 23:30 bin/
drwxr-xr-x   1 abc  abc  4.0K Oct 20 13:40 config/
drwxrwxr-x   2 abc  1001 4.0K Oct 20 11:03 data/
drwxr-xr-x   1 abc  abc  4.0K Oct 18 23:30 defaults/
drwxr-xr-x   5 root root  340 Oct 20 13:40 dev/
drwxr-xr-x   4 root root 4.0K Oct 20 13:43 digitalocean-dynamic-dns-ip/
-rwxrwxr-x   1 root root 3.5K Oct 18 23:29 docker-mods*
drwxrwxr-x   1 root root 4.0K Oct 20 13:40 etc/
drwxr-xr-x   2 root root 4.0K Oct 18 23:30 home/
-rwxr-xr-x   1 root root  389 Feb 15  2021 init*
drwxr-xr-x   1 root root 4.0K Oct 18 23:30 lib/
drwxr-xr-x   2 root root 4.0K Oct 18 23:30 libexec/
drwxr-xr-x   5 root root 4.0K Oct 18 23:30 media/
drwxr-xr-x   2 root root 4.0K Oct 18 23:30 mnt/
drwxr-xr-x   2 root root 4.0K Oct 18 23:30 opt/
dr-xr-xr-x 371 root root    0 Oct 20 13:40 proc/
drwx------   1 root root 4.0K Oct 20 13:26 root/
drwxr-xr-x   1 root root 4.0K Oct 20 13:40 run/
drwxr-xr-x   1 root root 4.0K Oct 18 23:30 sbin/
drwxr-xr-x   2 root root 4.0K Oct 18 23:30 srv/
dr-xr-xr-x  13 root root    0 Oct 17 13:41 sys/
drwxrwxrwt   1 root root 4.0K Oct 20 13:43 tmp/
drwxrwxr-x   1 root root 4.0K Oct 20 13:21 usr/
drwxr-xr-x   1 root root 4.0K Oct 20 13:21 var/
root@8fe489e34640:/# 
root@8fe489e34640:/# 
root@8fe489e34640:/# ll /digitalocean-dynamic-dns-ip/
total 6.6M
drwxr-xr-x 4 root root 4.0K Oct 20 13:43 ./
drwxr-xr-x 1 root root 4.0K Oct 20 13:42 ../
drwxr-xr-x 2 root root 4.0K Oct 20 13:42 .circleci/
drwxr-xr-x 8 root root 4.0K Oct 20 13:42 .git/
-rw-r--r-- 1 root root  123 Oct 20 13:42 .gitignore
-rw-r--r-- 1 root root 1.1K Oct 20 13:42 LICENSE.md
-rw-r--r-- 1 root root 4.1K Oct 20 13:42 README.md
-rwxr-xr-x 1 root root 1.3K Oct 20 13:42 ci-build-script.sh*
-rwxr-xr-x 1 root root 6.5M Oct 20 13:43 digitalocean-dynamic-dns-ip*
-rw-r--r-- 1 root root  10K Oct 20 13:42 digitalocean-dynamic-ip.go
-rw-r--r-- 1 root root  669 Oct 20 13:42 digitalocean-dynamic-ip.sample.json
-rw-r--r-- 1 root root  112 Oct 20 13:42 go.mod
-rw-r--r-- 1 root root  181 Oct 20 13:42 go.sum
root@8fe489e34640:/# ll /tmp/
total 8.0K
drwxrwxrwt 1 root root 4.0K Oct 20 13:43 ./
drwxr-xr-x 1 root root 4.0K Oct 20 13:42 ../
root@8fe489e34640:/# ll /home/
total 8.0K
drwxr-xr-x 2 root root 4.0K Oct 18 23:30 ./
drwxr-xr-x 1 root root 4.0K Oct 20 13:42 ../
root@8fe489e34640:/# ll /var/log
total 12K
drwxr-xr-x 2 root root 4.0K Oct 18 23:30 ./
drwxr-xr-x 1 root root 4.0K Oct 20 13:21 ../
root@8fe489e34640:/# ll /root/
total 24K
drwx------ 1 root root 4.0K Oct 20 13:26 ./
drwxr-xr-x 1 root root 4.0K Oct 20 13:42 ../
drwxr-xr-x 1 root root 4.0K Oct 20 13:26 .cache/
drwxr-xr-x 3 root root 4.0K Oct 20 13:26 go/
tonydm commented 3 years ago

I resolved the issue although no idea how. I copied a config from another working site and pasted it in this servers data/digitalocean-dynamic-ip.json config file. Same API Key and domain, diff sub domains. Changed the sub domains. Everything else the same. Viola, working. Copy my original config back to the /data/digitalocean-dynamic-ip.json and it too works. Complete mystery to me. Both files pass a linter check. Both appear(d) identical. Your quick response and effort are very appreciated. I'm going to close this issue since the issue is gone. If I missed something in using the testing branch, I'd be interested to know what that is.

Thanks again

Config from another working site

{
  "apikey": "MY API KEY",
  "doPageSize": 20,
  "useIPv4": true,
  "useIPv6": false,
  "allowIPv4InIPv6": false,
  "ipv4CheckUrl": "https://ipv4bot.whatismyipaddress.com",
  "domains": [
    {
      "domain": "mydomain.com",
      "records": [
        {
          "name": "mysubdomain",
          "type": "A"
        }
      ]
    }
  ]
}

Original config

{
  "apikey": "MY API KEY",
  "doPageSize": 20,
  "useIPv4": true,
  "useIPv6": false,
  "allowIPv4InIPv6": false,
  "ipv4CheckUrl": "https://ipv4bot.whatismyipaddress.com",
  "domains": [
    {
      "domain": "mydomain.com",
      "records": [
        {
          "name": "mysubdomain",
          "type": "A"
        }
      ]
    }
  ]
}