TimothyYe / godns

A dynamic DNS client tool that supports AliDNS, Cloudflare, Google Domains, DNSPod, HE.net & DuckDNS & DreamHost, etc, written in Go.
https://timothyye.github.io/godns/
Apache License 2.0
1.5k stars 221 forks source link

Fails to determine IP address of Interface on FreeBSD #202

Closed diizzyy closed 11 months ago

diizzyy commented 1 year ago

Not sure if it's configuration issue or not (seems like a bug) but trying to use an interface makes godns fail.

ERRO[0000] Cannot get IP:Get "": unsupported protocol scheme ""
ERRO[0000] get ip online failed. Fallback to get ip from interface if possible.
ERRO[0000] get ip from interface failed. There is no more ways to try.
ERRO[0000] Error during execution:can't get a vaild address from hn0: fail to get current IP

Relevant configuration (json):

...
  ],
  "ip_urls": [""],
  "ip_type": "IPv4",
  "ip_interface": "hn0",
  "interval": 300,
  "debug_info": true,
  "run_once": true
}

Using this code works however (standalone)

https://gist.github.com/schwarzeni/f25031a3123f895ff3785970921e962c

diizzyy commented 1 year ago

Still busy or is this something you can look into? @TimothyYe It appears to be a simple parsing bug

biship commented 1 year ago

Same problem on windows. "ip_interface": "wgpia0",

time="2023-09-07T16:09:24-04:00" level=info msg="Creating DNS handler with provider: DuckDNS" time="2023-09-07T16:09:24-04:00" level=info msg="GoDNS started, starting the DNS manager..." time="2023-09-07T16:09:24-04:00" level=error msg="Cannot get IP:Get \"\": unsupported protocol scheme \"\"" time="2023-09-07T16:09:24-04:00" level=error msg="get ip online failed. Fallback to get ip from interface if possible." time="2023-09-07T16:09:24-04:00" level=error msg="get ip from interface failed. There is no more ways to try." time="2023-09-07T16:09:24-04:00" level=error msg="can't get a vaild address from wgpia0" time="2023-09-07T16:09:24-04:00" level=debug msg="DNS update loop finished, will run again in 300 seconds"

diizzyy commented 11 months ago

@TimothyYe Can you possibly have a look at this?

TimothyYe commented 11 months ago

@diizzyy Thanks, I'll look into this issue.

TimothyYe commented 11 months ago

ERRO[0000] Cannot get IP:Get "": unsupported protocol scheme ""

@diizzyy I've checked the code, this error means GoDNS still tries to get the IP address from the internet.

I think to fix this issue, update your config as:

{
  "ip_type": "IPv4",
  "ip_interface": "hn0",
  "interval": 300,
  "debug_info": true,
  "run_once": true
}

Just remove ip_urls from it. By the way, I've released a new version to fix this problem and filter the empty URLs in the ip_urls option.

diizzyy commented 11 months ago

@TimothyYe Hi, still doesn't work unfortunately

  "ip_type": "IPv4",
  "ip_interface": "hn0",
  "interval": 300,
  "debug_info": true,
  "run_once": true

INFO[0000] GoDNS started, starting the DNS manager... ERRO[0000] get ip from interface failed. There is no more ways to try. ERRO[0000] Error during execution:fail to get current IP

Also the syntax is from the manual, https://github.com/TimothyYe/godns#network-interface-ip-address

TimothyYe commented 11 months ago

Could you please help to run the ifconfig command, and paste the output for your network interface hn0 here? I guess the only difference between GoDNS and the code snippet you mentioned is that GoDNS checks if the IP is private:

https://github.com/TimothyYe/godns/blob/master/pkg/lib/ip_helper.go#L122

TimothyYe commented 11 months ago

I use my Oracle cloud to test GoDNS on the FreeBSD system, and the same error shows when the network interface is assigned with a private IP address:

image

For the current implementation, GoDNS will ignore the private IP address while fetching it from the network interface.

diizzyy commented 11 months ago

Ahh, you're correct! I should've checked the code more carefully but it would be nice if godns where verbose about it especially in debug mode. There seems to be a loop however somewhere in the logic to detect IP?

INFO[0000] Creating DNS handler with provider: Infomaniak
INFO[0000] GoDNS started, starting the DNS manager...
DEBU[0000] get ip success from network intereface by: igb0, IP: NOT PRIVATE
DEBU[0000] get ip success from network intereface by: igb0, IP: NOT PRIVATE
INFO[0002] Update IP success: good NOT PRIVATE
DEBU[0002] Cached IP address: NOT PRIVATE
TimothyYe commented 11 months ago

It's not a loop, it only happens when the GoDNS is launched for the first time, the current_ip in the IPHelper is empty, so it tries to fetch the current IP address immediately. In this case, it produces one extra output log: https://github.com/TimothyYe/godns/blob/master/pkg/lib/ip_helper.go#L71

Another log is produced by the inner goroutine inside the IPHelper: https://github.com/TimothyYe/godns/blob/master/pkg/lib/ip_helper.go#L60

So you may see two output logs here.

diizzyy commented 11 months ago

Thanks for clarifying, I guess we can close this now.