OPNsense Forum

English Forums => 24.7, 24.10 Legacy Series => Topic started by: flushell on August 24, 2024, 07:59:08 PM

Title: Port Forward to 127.0.0.1 works, but not to ::1 [+ workaround]
Post by: flushell on August 24, 2024, 07:59:08 PM
I wanted a PF rule so all DNS / NTP traffic on my network not going to my OPNsense would be redirected to localhost (the OPNsense box itself) in order to transparantly redirect this traffic. I have a dual stack (IPv4/IPv6) setup.

Easy enough for IPv4, for example DNS, but same for NTP (but different ports and only UDP).
I have allow rules for DNS / NTP under Firewall-Rules-WhateverInterface

NAT Port Forward:


Works perfectly for IPv4.

For IPv6 however, I would expect that the only things I have to change are:
The 2nd one: TCP/IP: IPv6
The 7th one: Redirect target IP: Single host or Network: ::1

I found out this is not working. Unbound and Chrony, which I use for DNS/NTP, apparently bind on 127.0.0.1, but not on the IPv6 counterpart ::1.



I already found a workaround after too many hours of research and trying:

Make a NAT Port Forward rule:


To make things easier you could also make an alias under Firewall-Aliases to fd08::1/128 or whatever ULA you choose.

All set and done. Posted this for the benefit of the earth but also: I can't handle that I don't understand why it doesn't work with ::1? Or did I accidentally found a bug (probably not)? Maybe someone here could explain that, so I can sleep and give my brain some rest.

Thanks and cheers!
Title: Re: Port Forward to 127.0.0.1 works, but not to ::1 [+ workaround]
Post by: doktornotor on August 25, 2024, 10:17:02 AM
Cannot confirm this regarding Unbound. No idea about chrony.

# sockstat -n | grep :53
59       unbound    75740 5   udp6   *:53                  *:*
59       unbound    75740 6   tcp6   *:53                  *:*
59       unbound    75740 7   udp4   *:53                  *:*
59       unbound    75740 8   tcp4   *:53                  *:*
Title: Re: Port Forward to 127.0.0.1 works, but not to ::1 [+ workaround]
Post by: flushell on August 25, 2024, 10:33:58 AM
Quote from: doktornotor on August 25, 2024, 10:17:02 AM
Cannot confirm this regarding Unbound. No idea about chrony.

# sockstat -n | grep :53
59       unbound    75740 5   udp6   *:53                  *:*
59       unbound    75740 6   tcp6   *:53                  *:*
59       unbound    75740 7   udp4   *:53                  *:*
59       unbound    75740 8   tcp4   *:53                  *:*


I found that out too! And SSH'ing in the OPNsense box you van easily do

nslookup whatever.com ::1

And that works!

But in practice, doing an nslookup to an arbitrary IPv6 dns server (using the IPv6-address, not the hostname) from a node in my network fails with the ::1 rule in place, while the same succeeds for IPv4 (due to the 127.0.0.1 rule). It's almost if ::1 in this case does not redirect to OPNsense itself but to the machine asking? Weird.

Exact the same goes for Chrony and probably every service. ::1 does not work the way I think it works from a remote host in my network - not the same as 127.0.0.1, I suspect.
Title: Re: Port Forward to 127.0.0.1 works, but not to ::1 [+ workaround]
Post by: allan on August 25, 2024, 07:36:03 PM
Using the ULA for loopback is a great solution. When I was setting this up, I ended up creating a Dynamic IPv6 Host alias (https://docs.opnsense.org/manual/aliases.html#dynamic-ipv6-host) of my WAN SLAAC, and using that as my redirect target. I might switch to using your method instead.
Title: Re: Port Forward to 127.0.0.1 works, but not to ::1 [+ workaround]
Post by: newsense on August 25, 2024, 09:00:27 PM
For AdguardHome users, the /128 is not needed - service won't start otherwise

dns:
  bind_hosts:
    - 127.0.0.1
    - fd08::1