MatthewVance / unbound-docker-rpi

Run Unbound with latest version of OpenSSL on Raspberry Pi with Docker.
MIT License
136 stars 23 forks source link

IPv6 Address Assignment #12

Closed liambresnahan closed 2 years ago

liambresnahan commented 3 years ago

Using the base config (i.e. that inside the unbound.sh file) I am seeing the below errors which appear to be blocking startup so that unbound never fully inits and waits for queries. Is this a known issue? If so is there a workaround for this? I tried to disable IPv6 in a custom config, but this didn't seem to have any effect.

[1614822393] libunbound[19:0] error: udp connect failed: Cannot assign requested address for XXXX:XXX:XX::X port 53 [1614822393] libunbound[19:0] error: udp connect failed: Cannot assign requested address for XXXX:XXX:XX::X port 53 [1614822393] libunbound[19:0] error: udp connect failed: Cannot assign requested address for XXXX:XXX:XX::X port 53 [1614822393] libunbound[19:0] error: udp connect failed: Cannot assign requested address for XXXX:XXX:XX::X port 53 [1614822393] libunbound[19:0] error: udp connect failed: Cannot assign requested address for XXXX:XXX:XX::X port 53 [1614822393] libunbound[19:0] error: udp connect failed: Cannot assign requested address for XXXX:XXX:XX::X port 53 [1614822393] libunbound[19:0] error: udp connect failed: Cannot assign requested address for XXXX:XXX:XX::X port 53 [1614822393] libunbound[19:0] error: udp connect failed: Cannot assign requested address for XXXX:XXX:XX::X port 53

MatthewVance commented 3 years ago

Which version are you using? I ask because it looks somewhat similar to: https://github.com/MatthewVance/unbound-docker/issues/55

IPv6 should already be disabled in the default config. Docker and IPv6 is tricky so I default it to off for broader compatibility.

On Wed, Mar 3, 2021, 8:33 PM liambresnahan notifications@github.com wrote:

Using the base config (i.e. that inside the unbound.sh file) I am seeing the below errors which appear to be blocking startup so that unbound never fully inits and waits for queries. Is this a known issue? If so is there a workaround for this? I tried to disable IPv6 in a custom config, but this didn't seem to have any effect.

`[1614822393] libunbound[19:0] error: udp connect failed: Cannot assign requested address for XXXX:XXX:XX::X port 53

[1614822393] libunbound[19:0] error: udp connect failed: Cannot assign requested address for XXXX:XXX:XX::X port 53

[1614822393] libunbound[19:0] error: udp connect failed: Cannot assign requested address for XXXX:XXX:XX::X port 53

[1614822393] libunbound[19:0] error: udp connect failed: Cannot assign requested address for XXXX:XXX:XX::X port 53

[1614822393] libunbound[19:0] error: udp connect failed: Cannot assign requested address for XXXX:XXX:XX::X port 53

[1614822393] libunbound[19:0] error: udp connect failed: Cannot assign requested address for XXXX:XXX:XX::X port 53

[1614822393] libunbound[19:0] error: udp connect failed: Cannot assign requested address for XXXX:XXX:XX::X port 53

[1614822393] libunbound[19:0] error: udp connect failed: Cannot assign requested address for XXXX:XXX:XX::X port 53`

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/MatthewVance/unbound-docker-rpi/issues/12, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAUMHOQT2OGGD7KR6FQG6RLTB3WPRANCNFSM4YSMAIZA .

sohojmanush commented 3 years ago

[1619282073] libunbound[20:0] error: udp connect failed: Cannot assign requested address for xxxx:xxx:xx::b port 53 Still having the same issue. Docker run command is: docker run --name=unbound --net=macvlan_network --ip=xxx.xxx.xx.x --restart=unless-stopped --detach=true mvance/unbound-rpi

MatthewVance commented 3 years ago

I was able to re-create the issue. I'm investigating a resolution. It's likely due to Unbound wanting to use IPv6 by default but Docker not supporting IPv6 by default.

sohojmanush commented 3 years ago

My isp doesn't support ipv6 too. Also, will you please describe how this unbound container handle upstream nameserver. Previously there were a section stating that it was using 1.1.1.1 on the read me section. And a description in the docker hub page that pull request for rpi should use mvance/unbound-rpi instead of mvance/unbound . Btw,thanks for this awesome container.

MatthewVance commented 3 years ago

@sohojmanush

Thank you.

The README still mentions "By default, forwarders are configured to use Cloudflare DNS." It forwards queries to:

That default is defined in the forward-records.conf file. Other examples are provided and you can also customize it.

The README shows mvance/unbound-rpi. It's in the example run command (it'll auto pull it if you run it). I went ahead and added an example pull command to go with it.

sohojmanush commented 3 years ago

Thank you.

sohojmanush commented 3 years ago

docker run --name=unbound --net=macvlan_network --ip=xxx.xxx.xx.x -v /home/pi/unbound:/opt/unbound/etc/unbound/ --restart=unless-stopped --detach=true mvance/unbound returns: WARNING: The requested image's platform (linux/amd64) does not match the detected host platform (linux/arm/v7) and no specific platform was requested

docker run --name=unbound --net=macvlan_network --ip=xxx.xxx.xx.x -v /home/pi/unbound:/opt/unbound/etc/unbound/ --restart=unless-stopped --detach=true mvance/unbound-rpi docker run log shows , read /opt/unbound/etc/unbound/unbound.conf failed: 3 errors in configuration file [1619462443] unbound[1:0] fatal error: Could not read config file: /opt/unbound/etc/unbound/unbound.conf. Maybe try unbound -dd, it stays on the commandline to see more errors, or unbound-checkconf

The docker log output mentioned above generated the same output where the folder is in root, instead of "/home/pi" mentioned in the run command. Regardless of the directory, it shows the same output.

MatthewVance commented 3 years ago

Can you share your directory structure and also your unbound.conf file? That error implies errors in your custom config file or mounting method.

You may also want to review this: https://github.com/MatthewVance/unbound-docker-rpi/issues/8#issuecomment-753991522

The wildcard include method of volume mounting is for special use cases.

sohojmanush commented 3 years ago

No changes were made to the unbound.conf file. Run command (Using predefined network and ip):

_docker run --name=unbound --net=macvlannetwork --ip=xxx.xxx.xx.xx --restart=unless-stopped --detach=true mvance/unbound-rpi

Error: libunbound[19:0] error: udp connect failed: Cannot assign requested address for 2001:500:9f::42 port 53

But, the containers work.

Run command (Using Dns:127.0.0.1 on pihole ):

docker run --name=unbound --restart=unless-stopped --detach=true mvance/unbound-rpi

Doesn’t work.

Run command (Using with file path):

_docker run --name=unbound --net=macvlannetwork --ip=xxx.xxx.xx.xx -v /home/pi/unbound:/opt/unbound/etc/unbound/ --restart=unless-stopped --detach=true mvance/unbound-rpi

Error: read /opt/unbound/etc/unbound/unbound.conf failed: 3 errors in configuration file

[1619598622] unbound[1:0] fatal error: Could not read config file: /opt/unbound/etc/unbound/unbound.conf. Maybe try unbound -dd, it stays on the commandline to see more errors, or unbound-checkconf

Containers don’t work.

Root directory structure: Bin data
dockerfile home
lost+found mnt
pihole resilio
root sbin
sys usr boot dev
etc lib
media opt
proc resilio-sync
run srv
tmp var

Directory structure of /home/pi/unbound:

dev unbound.conf var

Unbound.conf file:

server: ###########################################################################

BASIC SETTINGS

###########################################################################
# Time to live maximum for RRsets and messages in the cache. If the maximum
# kicks in, responses to clients still get decrementing TTLs based on the
# original (larger) values. When the internal TTL expires, the cache item
# has expired. Can be set lower to force the resolver to query for data
# often, and not trust (very large) TTL values.
cache-max-ttl: 86400

# Time to live minimum for RRsets and messages in the cache. If the minimum
# kicks in, the data is cached for longer than the domain owner intended,
# and thus less queries are made to look up the data. Zero makes sure the
# data in the cache is as the domain owner intended, higher values,
# especially more than an hour or so, can lead to trouble as the data in
# the cache does not match up with the actual data any more.
cache-min-ttl: 300

# Set the working directory for the program.
directory: "/opt/unbound/etc/unbound"

# RFC 6891. Number  of bytes size to advertise as the EDNS reassembly buffer
# size. This is the value put into  datagrams over UDP towards peers.
# The actual buffer size is determined by msg-buffer-size (both for TCP and
# UDP). Do not set higher than that value.
# Default  is  1232 which is the DNS Flag Day 2020 recommendation.
# Setting to 512 bypasses even the most stringent path MTU problems, but
# is seen as extreme, since the amount of TCP fallback generated is
# excessive (probably also for this resolver, consider tuning the outgoing
# tcp number).
edns-buffer-size: 1232

# Listen to for queries from clients and answer from this network interface
# and port.
interface: 0.0.0.0@53

# Rotates RRSet order in response (the pseudo-random number is taken from
# the query ID, for speed and thread safety).
rrset-roundrobin: yes

# Drop user  privileges after  binding the port.
username: "_unbound"

###########################################################################
# LOGGING
###########################################################################

# Do not print log lines to inform about local zone actions
log-local-actions: no

# Do not print one line per query to the log
log-queries: no

# Do not print one line per reply to the log
log-replies: no

# Do not print log lines that say why queries return SERVFAIL to clients
log-servfail: no

# Further limit logging
logfile: /dev/null

# Only log errors
verbosity: 0

###########################################################################
# PRIVACY SETTINGS
###########################################################################

# RFC 8198. Use the DNSSEC NSEC chain to synthesize NXDO-MAIN and other
# denials, using information from previous NXDO-MAINs answers. In other
# words, use cached NSEC records to generate negative answers within a
# range and positive answers from wildcards. This increases performance,
# decreases latency and resource utilization on both authoritative and
# recursive servers, and increases privacy. Also, it may help increase
# resilience to certain DoS attacks in some circumstances.
aggressive-nsec: yes

# Extra delay for timeouted UDP ports before they are closed, in msec.
# This prevents very delayed answer packets from the upstream (recursive)
# servers from bouncing against closed ports and setting off all sort of
# close-port counters, with eg. 1500 msec. When timeouts happen you need
# extra sockets, it checks the ID and remote IP of packets, and unwanted
# packets are added to the unwanted packet counter.
delay-close: 10000

# Prevent the unbound server from forking into the background as a daemon
do-daemonize: no

# Add localhost to the do-not-query-address list.
do-not-query-localhost: no

# Number  of  bytes size of the aggressive negative cache.
neg-cache-size: 4M

# Send minimum amount of information to upstream servers to enhance
# privacy (best privacy).
qname-minimisation: yes

###########################################################################
# SECURITY SETTINGS
###########################################################################
# Only give access to recursion clients from LAN IPs
access-control: 127.0.0.1/32 allow
access-control: 192.168.0.0/16 allow
access-control: 172.16.0.0/12 allow
access-control: 10.0.0.0/8 allow
# access-control: fc00::/7 allow
# access-control: ::1/128 allow

# File with trust anchor for  one  zone, which is tracked with RFC5011
# probes.
auto-trust-anchor-file: "var/root.key"

# Enable chroot (i.e, change apparent root directory for the current
# running process and its children)
chroot: "/opt/unbound/etc/unbound"

# Deny queries of type ANY with an empty response.
deny-any: yes

# Harden against algorithm downgrade when multiple algorithms are
# advertised in the DS record.
harden-algo-downgrade: yes

# RFC 8020. returns nxdomain to queries for a name below another name that
# is already known to be nxdomain.
harden-below-nxdomain: yes

# Require DNSSEC data for trust-anchored zones, if such data is absent, the
# zone becomes bogus. If turned off you run the risk of a downgrade attack
# that disables security for a zone.
harden-dnssec-stripped: yes

# Only trust glue if it is within the servers authority.
harden-glue: yes

# Ignore very large queries.
harden-large-queries: yes

# Perform additional queries for infrastructure data to harden the referral
# path. Validates the replies if trust anchors are configured and the zones
# are signed. This enforces DNSSEC validation on nameserver NS sets and the
# nameserver addresses that are encountered on the referral path to the
# answer. Experimental option.
harden-referral-path: no

# Ignore very small EDNS buffer sizes from queries.
harden-short-bufsize: yes

# Refuse id.server and hostname.bind queries
hide-identity: yes

# Refuse version.server and version.bind queries
hide-version: yes

# Report this identity rather than the hostname of the server.
identity: "DNS"

# These private network addresses are not allowed to be returned for public
# internet names. Any  occurrence of such addresses are removed from DNS
# answers. Additionally, the DNSSEC validator may mark the  answers  bogus.
# This  protects  against DNS  Rebinding
private-address: 10.0.0.0/8
private-address: 172.16.0.0/12
private-address: 192.168.0.0/16
private-address: 169.254.0.0/16
# private-address: fd00::/8
# private-address: fe80::/10
# private-address: ::ffff:0:0/96

# Enable ratelimiting of queries (per second) sent to nameserver for
# performing recursion. More queries are turned away with an error
# (servfail). This stops recursive floods (e.g., random query names), but
# not spoofed reflection floods. Cached responses are not rate limited by
# this setting. Experimental option.
ratelimit: 1000

# Use this certificate bundle for authenticating connections made to
# outside peers (e.g., auth-zone urls, DNS over TLS connections).
tls-cert-bundle: /etc/ssl/certs/ca-certificates.crt

# Set the total number of unwanted replies to eep track of in every thread.
# When it reaches the threshold, a defensive action of clearing the rrset
# and message caches is taken, hopefully flushing away any poison.
# Unbound suggests a value of 10 million.
unwanted-reply-threshold: 10000

# Use 0x20-encoded random bits in the query to foil spoof attempts. This
# perturbs the lowercase and uppercase of query names sent to authority
# servers and checks if the reply still has the correct casing.
# This feature is an experimental implementation of draft dns-0x20.
# Experimental option.
use-caps-for-id: yes

# Help protect users that rely on this validator for authentication from
# potentially bad data in the additional section. Instruct the validator to
# remove data from the additional section of secure messages that are not
# signed properly. Messages that are insecure, bogus, indeterminate or
# unchecked are not affected.
val-clean-additional: yes

###########################################################################
# PERFORMANCE SETTINGS
###########################################################################
# https://nlnetlabs.nl/documentation/unbound/howto-optimise/
# https://nlnetlabs.nl/news/2019/Feb/05/unbound-1.9.0-released/

# Number of slabs in the infrastructure cache. Slabs reduce lock contention
# by threads. Must be set to a power of 2.
infra-cache-slabs: 4

# Number of incoming TCP buffers to allocate per thread. Default
# is 10. If set to 0, or if do-tcp is "no", no  TCP  queries  from
# clients  are  accepted. For larger installations increasing this
# value is a good idea.
incoming-num-tcp: 10

# Number of slabs in the key cache. Slabs reduce lock contention by
# threads. Must be set to a power of 2. Setting (close) to the number
# of cpus is a reasonable guess.
key-cache-slabs: 4

# Number  of  bytes  size  of  the  message  cache.
# Unbound recommendation is to Use roughly twice as much rrset cache memory
# as you use msg cache memory.
msg-cache-size: 611351210

# Number of slabs in the message cache. Slabs reduce lock contention by
# threads. Must be set to a power of 2. Setting (close) to the number of
# cpus is a reasonable guess.
msg-cache-slabs: 4

# The number of queries that every thread will service simultaneously. If
# more queries arrive that need servicing, and no queries can be jostled
# out (see jostle-timeout), then the queries are dropped.
# This is best set at half the number of the outgoing-range.
# This Unbound instance was compiled with libevent so it can efficiently
# use more than 1024 file descriptors.
num-queries-per-thread: 4096

# The number of threads to create to serve clients.
# This is set dynamically at run time to effectively use available CPUs
# resources
num-threads: 3

# Number of ports to open. This number of file descriptors can be opened
# per thread.
# This Unbound instance was compiled with libevent so it can efficiently
# use more than 1024 file descriptors.
outgoing-range: 8192

# Number of bytes size of the RRset cache.
# Use roughly twice as much rrset cache memory as msg cache memory
rrset-cache-size: 1222702421

# Number of slabs in the RRset cache. Slabs reduce lock contention by
# threads. Must be set to a power of 2.
rrset-cache-slabs: 4

# Do no insert authority/additional sections into response messages when
# those sections are not required. This reduces response size
# significantly, and may avoid TCP fallback for some responses. This may
# cause a slight speedup.
minimal-responses: yes

# # Fetch the DNSKEYs earlier in the validation process, when a DS record
# is encountered. This lowers the latency of requests at the expense of
# little more CPU usage.
prefetch: yes

# Fetch the DNSKEYs earlier in the validation process, when a DS record is
# encountered. This lowers the latency of requests at the expense of little
# more CPU usage.
prefetch-key: yes

# Have unbound attempt to serve old responses from cache with a TTL of 0 in
# the response without waiting for the actual resolution to finish. The
# actual resolution answer ends up in the cache later on.
serve-expired: yes

# Open dedicated listening sockets for incoming queries for each thread and
# try to set the SO_REUSEPORT socket option on each socket. May distribute
# incoming queries to threads more evenly.
so-reuseport: yes

###########################################################################
# LOCAL ZONE
###########################################################################

# Include file for local-data and local-data-ptr
include: /opt/unbound/etc/unbound/a-records.conf
include: /opt/unbound/etc/unbound/srv-records.conf

###########################################################################
# FORWARD ZONE
###########################################################################

include: /opt/unbound/etc/unbound/forward-records.conf

###########################################################################
# WILDCARD INCLUDE
###########################################################################
#include: "/opt/unbound/etc/unbound/*.conf"

remote-control: control-enable: no

No changes were made to the unbound.conf file.

Run Command: _docker run --name=unbound --net=macvlannetwork --ip=xxx.xxx.xx.xx -v /home/pi/unbound:/opt/unbound/etc/unbound/ -v /home/pi/unbound:/opt/unbound/etc/unbound/unbound.conf.d/ --restart=unless-stopped --detach=true mvance/unbound-rpi

Directory structure of /home/pi/unbound: dev unbound.conf unbound.conf.d var

After manually adding:

a-records.conf
forward-records.conf srv-records.conf

removes the ‘read /opt/unbound/etc/unbound/unbound.conf failed: 3 errors in configuration file’ from the error logs.

And unbound.conf.d

Seems like the only issue remains is:

libunbound[18:0] error: udp connect failed: Cannot assign requested address for 2001:500:9f::42 port 53

As of writing containers working great. My realization is that choosing a custom folder doesn’t fetch the record files.

So, I recreated the container without the unbound.conf.d directory, manually added the 3 missing .conf file. And now the container works again, so, the cause of the issues is not fetching the 3 .conf file. The only issue that remains is the udp issue mentioned earlier.

swift-nicholas commented 3 years ago

I have/had the same issue.

I just added interface: ::0 to the unbound.conf under the ipv4 interface 0.0.0.0@53 as per the docs here https://www.nlnetlabs.nl/documentation/unbound/howto-setup/

I also had the configuration error but like the previous comment, adding the three files removes the configuration error.

Will this cause undefined behaviour? Maybe. Does it mean I can resolve dns queries using the conainer? Yes.

I'm also using the https://github.com/MatthewVance/unbound-docker container in an Ubuntu 20.04 server virtual machine, not on a pi for your information.

weelad commented 2 years ago

@MatthewVance I know this issue is closed, but I'm having the same issue and there's a lot of context here that applies to me. I'm unable to resolve the following error: [1642202252] libunbound[21:0] error: udp connect failed: Cannot assign requested address for 2001:500:2::c port 53

I've tried disabling ipv6 do-ip6: no to no avail.

Any suggestions?

MatthewVance commented 2 years ago

I suggest reporting and discussing it upstream. The issue is closed because I’m not sure there’s anything to do in this Docker image, not because the issue is resolved. I too get these errors in my logs.

https://github.com/NLnetLabs/unbound/issues/364

On Jan 14, 2022, at 5:23 PM, weelad @.***> wrote:  @MatthewVance I know this issue is closed, but I'm having the same issue and there's a lot of context here that applies to me. I'm unable to resolve the following error: [1642202252] libunbound[21:0] error: udp connect failed: Cannot assign requested address for 2001:500:2::c port 53

I've tried disabling ipv6 do-ip6: no to no avail.

Any suggestions?

— Reply to this email directly, view it on GitHub, or unsubscribe. Triage notifications on the go with GitHub Mobile for iOS or Android. You are receiving this because you were mentioned.

weelad commented 2 years ago

Good to know. Cheers.