Netgate Discussion Forum
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Search
    • Register
    • Login
    Introducing Netgate Nexus: Multi-Instance Management at Your Fingertips.

    what is the correct way to do DNS rules?

    Scheduled Pinned Locked Moved Firewalling
    18 Posts 6 Posters 431 Views 8 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • A Offline
      amrogers3
      last edited by amrogers3

      I am confusing myself on this. Which of these is correct?

      https://ibb.co/Wvd8mFCR

      https://ibb.co/N6kxJ01W

      Also, how do you get image to show? I can't get it to work.

      johnpozJ 1 Reply Last reply Reply Quote 1
      • johnpozJ Online
        johnpoz LAYER 8 Global Moderator @amrogers3
        last edited by johnpoz

        @amrogers3 just upload the image? Not sure what your asking to do with dns - redirect it? You have a rule - did you actually create the port forward?

        image.jpg

        But your rule to actually redirect anything is a reject, and it should above where your allow to loopback is.. So a reject wouldn't ever redirect anything. So not sure what your actually wanting to do.

        Here is how you redirect dns.

        https://docs.netgate.com/pfsense/en/latest/recipes/dns-redirect.html

        An intelligent man is sometimes forced to be drunk to spend time with his fools
        If you get confused: Listen to the Music Play
        Please don't Chat/PM me for help, unless mod related
        SG-4860 26.03.1 | Lab VMs 2.8.1, 26.03.1

        A 1 Reply Last reply Reply Quote 0
        • A Offline
          amrogers3 @johnpoz
          last edited by amrogers3

          @johnpoz
          Thank you for the question. I fumbled up the order of rules for sure. I am trying to redirect DNS to local interface and block DNS over 853 and 443 so that all requests go through pfSense. My understanding is that this is necessary for pfBlocker to inspect all the queries.

          Yes on the port forward and the screenshot is below.

          • Is there an example of what the proper DNS firewall rule set should look like? or firewall rules set in general?

          Screenshot 2026-05-31 at 9.55.48 PM.png

          Guest
          pfSense-purplemonster-com-Firewall-Rules-GUEST-2.png

          LAN
          Screenshot 2026-05-31 at 10.17.39 PM.png

          SteveITSS 1 Reply Last reply Reply Quote 0
          • SteveITSS Offline
            SteveITS Rebel Alliance @amrogers3
            last edited by

            @amrogers3 “proper” is extremely subjective.

            For DNS you may have also found https://docs.netgate.com/pfsense/en/latest/recipes/dns-block-external.html.

            At first glance your rules seem ok except the LAN rule to block DNS to !LAN is above the allow to localhost.

            To upgrade, select your branch in System/Update/Update Settings. When upgrading, allow 10-15 minutes to reboot, or more depending on packages, CPU, and/or disk speed.
            Only install packages for your version of pfSense.
            Upvote 👍 helpful posts!

            Bob.DigB 1 Reply Last reply Reply Quote 0
            • Bob.DigB Offline
              Bob.Dig LAYER 8 @SteveITS
              last edited by

              except the LAN rule to block DNS to !LAN is above the allow to localhost.

              I would make those with Filter rule association "pass", no need for an extra firewall rule.

              A 1 Reply Last reply Reply Quote 0
              • A Offline
                amrogers3 @Bob.Dig
                last edited by

                @Bob.Dig
                So you would do something like this and leave it at the same place in the list?
                Screenshot 2026-06-01 at 12.39.08 PM.png

                Bob.DigB 1 Reply Last reply Reply Quote 0
                • Bob.DigB Offline
                  Bob.Dig LAYER 8 @amrogers3
                  last edited by

                  @amrogers3 I meant the Port Forward.

                  A 1 Reply Last reply Reply Quote 0
                  • AndyRHA Offline
                    AndyRH
                    last edited by

                    Perhaps my thread from long ago will help. I silently redirect outbound DNS to PiHole.

                    https://forum.netgate.com/topic/156453/pfsense-dns-redirect-to-local-dns-server?_=1663853296484

                    o|||||||o
                    8200

                    1 Reply Last reply Reply Quote 0
                    • A Offline
                      amrogers3 @Bob.Dig
                      last edited by

                      @Bob.Dig
                      I am not following, so delete that rule above?

                      johnpozJ 1 Reply Last reply Reply Quote 0
                      • johnpozJ Online
                        johnpoz LAYER 8 Global Moderator @amrogers3
                        last edited by johnpoz

                        @amrogers3 Is it you do not understand the order of rules? Rules are evaluated top down, first to trigger wins and no other rules are evaluated.

                        If you create a port forward that says any NOT, ie ! to the lan address send to 127.0.0.1

                        This will be evaluated first, but then you need a rule to allow that. If we go top down first rule that triggers to 53 to ip 127.0.0.1 you are rejecting it..

                        When you create the port forward it should create the rule for you.. See here, I created the port forward, it created the allow rule for 127.0.0.1 to 53.

                        portforward.jpg

                        Now lets create some rules to go along with that and put them in the right order.

                        I want a rule that says hey you talking to pfsense address already for dns - put this above the allow rule to 127.0.0.1 (rule 1)

                        My allow rule to 127.0.0.1 (rule 2)

                        And while not really needed, since your nat should redirect any dns to anything other than your lan address, ie the ! lan address in your port forward you can put in a block all dns. (rule 3)

                        rules.jpg

                        So lets walk thru some examples if I ask pfsense for dns to its lan address, rule 1 would allow this. The port forward wouldn't trigger ever since I am actually asking the lan address, not ! lan address

                        If I ask say 8.8.8.8, rule 1 would not match, so lets check next - my redirect will be sending the traffic to 127.0.0.1 because 8.8.8.8 is not my lan address, ie the source ! lan address in my port forward.

                        So this rule 2 allows that to happen, and as you can see if I ask a direct query to 8.8.8.8 it has no clue about anything on my home.arpa network locally. But unbound does.

                        redirect.jpg

                        There is no possible way that googledns 8.8.8.8 would know the ip for nas.home.arpa, and it sure couldn't answer in less than 1 ms, see the query time listed. So clearly my query to 8.8.8.8 was redirected to unbound.

                        Also notice now that count on my redirect allow rule has gone up.

                        redirectcount.jpg

                        You don't really need that block rule - but sure its never going to trigger unless your port forward fails.

                        You can then put in other blocks to say dot (853) if you want - but clients almost never use dot, they use doh which is over 443.. It hides in normal https traffic so it is harder to filter.

                        But your rules need to be in the proper order to work. Top down, first to trigger wins, no other rules evaluated.

                        Keep in mind that port forwards are evaluated before firewall rules.

                        Hope that clears it up.

                        An intelligent man is sometimes forced to be drunk to spend time with his fools
                        If you get confused: Listen to the Music Play
                        Please don't Chat/PM me for help, unless mod related
                        SG-4860 26.03.1 | Lab VMs 2.8.1, 26.03.1

                        Q A 2 Replies Last reply Reply Quote 3
                        • Q Offline
                          q54e3w @johnpoz
                          last edited by

                          @johnpoz said in what is the correct way to do DNS rules?:

                          … but clients almost never use dot, they use doh which is over 443.. It hides in normal https traffic so it is harder to filter.

                          Any tips here if it’s possible other than by configuring the clients?

                          johnpozJ 1 Reply Last reply Reply Quote 0
                          • johnpozJ Online
                            johnpoz LAYER 8 Global Moderator @q54e3w
                            last edited by johnpoz

                            @q54e3w there are loads of lists of known doh servers that you can use to block access. Most clients would for sure tend to use the well known ones.. So for typical stuff like browsers and such that love to default to using doh, those can work. Pretty sure pfblocker has a block doh list out of the box.

                            Best to turn it off in your app for sure..

                            What can be tricky is more in a work sort of setup, where users could point to god knows what as their doh server to circumvent say work dns filtering.

                            An intelligent man is sometimes forced to be drunk to spend time with his fools
                            If you get confused: Listen to the Music Play
                            Please don't Chat/PM me for help, unless mod related
                            SG-4860 26.03.1 | Lab VMs 2.8.1, 26.03.1

                            SteveITSS 1 Reply Last reply Reply Quote 0
                            • SteveITSS Offline
                              SteveITS Rebel Alliance @johnpoz
                              last edited by

                              @johnpoz said in what is the correct way to do DNS rules?:

                              Pretty sure pfblocker has a block doh list out of the box.

                              Yes. One needs to select all the "DoH/DoT/DoQ Blocking List" servers:
                              3ce1d8c0-e83b-44a2-9195-6057999f195c-image.png

                              To upgrade, select your branch in System/Update/Update Settings. When upgrading, allow 10-15 minutes to reboot, or more depending on packages, CPU, and/or disk speed.
                              Only install packages for your version of pfSense.
                              Upvote 👍 helpful posts!

                              1 Reply Last reply Reply Quote 0
                              • A Offline
                                amrogers3 @johnpoz
                                last edited by amrogers3

                                @johnpoz
                                Fantastic examples and explanation John, thank you very much.
                                I was overthinking it and missed some core concepts about port forwarding and the firewall rules.
                                Anyway, thanks again, appreciate you taking the time to write all that with the examples. This post was
                                very helpful!! Thank you 🙏
                                Does it matter if NTP is above DNS? I can't think of a case how it should matter if NTP is before or after.

                                • antilock out rule
                                • NTP
                                • DNS
                                • allow rules
                                • block everything else rule

                                Screenshot 2026-06-02 at 2.31.39 PM.png

                                johnpozJ 2 Replies Last reply Reply Quote 0
                                • johnpozJ Online
                                  johnpoz LAYER 8 Global Moderator @amrogers3
                                  last edited by

                                  @amrogers3 it would matter where it is in the stack if you had something that blocked ntp, or blocked all etc..

                                  Just remember top down, first to match/trigger wins, evaluation stops.

                                  So if you have a question if the order of your rules is correct.. Just run down your rule in your head with the traffic example - which is the first rule to match.

                                  Keep in mind also if traffic gets to the end without matching anything - then it would be denied.. There is a hidden rule on all interfaces for deny.. If you do not actually allow the traffic with a rule and it gets to the end it will be blocked.

                                  An intelligent man is sometimes forced to be drunk to spend time with his fools
                                  If you get confused: Listen to the Music Play
                                  Please don't Chat/PM me for help, unless mod related
                                  SG-4860 26.03.1 | Lab VMs 2.8.1, 26.03.1

                                  A 1 Reply Last reply Reply Quote 0
                                  • johnpozJ Online
                                    johnpoz LAYER 8 Global Moderator @amrogers3
                                    last edited by

                                    @amrogers3 Just out of curiosity on my part - your lan to http rule you show there - 2.7GB of traffic - just curious what your talking to over 80 that would be that much traffic, I assume its something else on your local side networks (ie another segment).. Since pretty much everything on the internet these days is encrypted (443)..

                                    How long has that counter been running as well - one thing if 3 month for that much traffic, and another if 3 hours ;)

                                    I might put in a rule for 80 and 443 vs my just any any rule - to get an idea how much actual 80 traffic is flowing.. I would think it just a tiny fraction of overall traffic.

                                    An intelligent man is sometimes forced to be drunk to spend time with his fools
                                    If you get confused: Listen to the Music Play
                                    Please don't Chat/PM me for help, unless mod related
                                    SG-4860 26.03.1 | Lab VMs 2.8.1, 26.03.1

                                    1 Reply Last reply Reply Quote 0
                                    • A Offline
                                      amrogers3 @johnpoz
                                      last edited by amrogers3

                                      @johnpoz
                                      Appreciate the question. Looks like some funny business is going on here.
                                      I rebooted a few days ago and it looks like a reboot resets that counter. So therefore, that traffic is a lot for only a few days. It appears to be one site, 65.254.248.204 which comes back to Newfold Digital, Inc..
                                      The state table shows an established connection.
                                      Curl shows code 462 which is weird. Apologies for the large pics, I can't modify the size here.

                                      Screenshot 2026-06-02 at 10.47.21 PM.png

                                      Screenshot 2026-06-02 at 10.43.03 PM.png

                                      I started digging into it and only got this far before the state terminated. So I was unable to see what process was associated with port 80. I am going to keep my eye on this. Definitely weird.

                                      There is a ton of 80 banging on the WAN. 114.22.17.129 is not my real WAN IP.

                                      Screenshot 2026-06-02 at 11.04.00 PM.png

                                      johnpozJ 1 Reply Last reply Reply Quote 0
                                      • johnpozJ Online
                                        johnpoz LAYER 8 Global Moderator @amrogers3
                                        last edited by

                                        @amrogers3 said in what is the correct way to do DNS rules?:

                                        There is a ton of 80 banging on the WAN. 114.22.17.129 is not my real WAN IP.

                                        yeah to be expected.. There will be a lot of stuff banging on your front door, 24/7/365 - its the internet ;)

                                        So I had broken out 80 so I could see - and I have more than I would expect as well - but mine is all iot devices, alexas, firestick, tv - my guess is some sort of internet check, ie them checking if they can talk to the internet. My alexas for example are talking to 80 to an amazon IP.

                                        That company owns a lot of brands.

                                        https://www.newfold.com/brands

                                        An intelligent man is sometimes forced to be drunk to spend time with his fools
                                        If you get confused: Listen to the Music Play
                                        Please don't Chat/PM me for help, unless mod related
                                        SG-4860 26.03.1 | Lab VMs 2.8.1, 26.03.1

                                        1 Reply Last reply Reply Quote 0
                                        • First post
                                          Last post
                                        Copyright 2026 Rubicon Communications LLC (Netgate). All rights reserved.