Netgate Discussion Forum
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Search
    • Register
    • Login

    pfSense - DNS redirect to local DNS server

    Scheduled Pinned Locked Moved NAT
    natdnsmasqueradepihole
    32 Posts 7 Posters 9.9k Views 13 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.
    • P Offline
      P.J @AndyRH
      last edited by P.J

      @AndyRH Your NATing to redirect all dns queries to Piehole isn't working because you get no error from dig saying "reply from unexpected source: <insert_your_piehole_server_ip_here>, expected 1.2.3.4#53" which you would get if PfSense would truly NAT properly. Something else is replying to dig, but its not piehole.

      I redirect all DNS queries from my LAN3 and WIFI segments to Piehole like this:
      898a23ef-fff4-4c41-a005-fb36f51f1625-image.png

      As you can see, all WIFI DNS requests from any source (segment 10.40.x.x/24) are NATed to my Piehole server on segment (10.22.x.x/24). Then you can see on the Piehole segment itself I redirect all DNS requests (segment 10.22.x.x/24) to the Piehole server EXCEPT for the Piehole server itself.

      Then here are the rules for the WIFI segment that goes with the NATing of WIFI DNS's request:

      a90ac14f-a971-462e-8e8a-d4686dc094dc-image.png

      And the rule for LAN3 segment (where the source isn't piehole itself):
      e7726d38-a81b-410f-b47e-634bb0fbc3dc-image.png

      And this is the output from Dig with a proper DNS redirection :

      ba6fa3ed-330e-4cba-855e-d0d400ce5700-image.png

      You can see the DNS request comes back from the Piehole server but Dig is waiting a reply from 1.2.3.4.

      And in piehole, you can see the request being redirected, resolved and returned to dig:
      a0ad5443-c8d4-4e1a-82f3-74eec0dd7374-image.png

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

        You are correct if the goal is to prevent resolution if a wrong DNS server is used. In that case a simple block of the port will work just fine.
        It is working as I intended. The goal is to get a proper response to the client. Without the "masquerade" of the wrong DNS server the client is not able to resolve the requested address.
        I do not want to stop the clients from resolving addresses, I do want to stop clients from resolving addresses on servers that are not mine.
        Roku's are notorious for using 8.8.8.8 if they fail to connect to the usage reporting servers. I have also found Amcrest cameras try hard coded DNS servers when they fail to connect home.

        o||||o
        7100-1u

        P 1 Reply Last reply Reply Quote 3
        • P Offline
          P.J @AndyRH
          last edited by

          @AndyRH Oh I understand what you wanted to do. You are anonymizing your piehole so your client's think their reply comes from the legitimate DNS they wanted to use. That's clever!

          1 Reply Last reply Reply Quote 0
          • P Offline
            pneuma2021
            last edited by

            I know this post is pretty old, but I just want to thank you for providing an elegant solution of forwarding all DNS queries to the Pihole. I am running Pfsense 2.5.2 and this solution is working for me.

            1 Reply Last reply Reply Quote 0
            • Y Offline
              yay
              last edited by

              Excellent, tyvm! ;)

              F 1 Reply Last reply Reply Quote 0
              • AndyRHA AndyRH referenced this topic on
              • AndyRHA AndyRH referenced this topic on
              • AndyRHA AndyRH referenced this topic on
              • johnpozJ johnpoz referenced this topic on
              • AndyRHA AndyRH referenced this topic on
              • AndyRHA AndyRH referenced this topic on
              • F Offline
                fjmp24 @yay
                last edited by

                @AndyRH Thank you for this post ! I have a question, with this solution pi-hole see only one IP "VLAN42 address" and not client IP ? It's correct ?

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

                  @fjmp24 No, a client on VLAN100 will be seen with its correct address. Any redirected (rouge) queries come from pfSense (42.1). I know it works because VLAN100 does not have ad filtering because 192.168.100.0/24 is in a group on PiHole to not do ad filtering.

                  o||||o
                  7100-1u

                  P F 2 Replies Last reply Reply Quote 0
                  • P Offline
                    P.J @AndyRH
                    last edited by P.J

                    Even though I have experimented a lot with PiHole a few years ago, and add filtering from many top firewall brands, the best thing to remove ads is Ad Blocker Ultimate plugin for Chrome.
                    Nothing passes through and free YouTube is possible. So it is worth to get and pay a little to help development as I did because it is simply outstanding.

                    johnpozJ 1 Reply Last reply Reply Quote 0
                    • F Offline
                      fjmp24 @AndyRH
                      last edited by

                      @AndyRH VLAN100 ?

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

                        @fjmp24 An example, one of my VLANs is VLAN100. VLAN42 (the meaning of Life, the Universe and Everything) is my primary VLAN and where the PiHoles reside.

                        o||||o
                        7100-1u

                        1 Reply Last reply Reply Quote 0
                        • johnpozJ Offline
                          johnpoz LAYER 8 Global Moderator @P.J
                          last edited by johnpoz

                          @P-J said in pfSense - DNS redirect to local DNS server:

                          is Ad Blocker Ultimate plugin for Chrome.

                          And those browser plugs are a bit hard to run on say your roku stick.. Or some app your playing on your phone.. I use a browser plug for sure in my browser but dns filtering can be very helpful on stuff your network is doing that is not browser based, or even on browsers that do not allow for addons, etc..

                          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 25.07 | Lab VMs 2.8, 25.07

                          F 1 Reply Last reply Reply Quote 0
                          • F Offline
                            fjmp24 @johnpoz
                            last edited by

                            @AndyRH Sorry but it doesn't work with me :-(

                            When I use the command :

                            • dig @1.2.3.4 google.fr, adguard display firewall address
                            • dig @adguard google.fr, adguard display client address

                            What is wrong ?

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

                              @fjmp24 no idea what your trying to do.. Have you setup redirection? @1.2.3.4 is not going to answer anything unless your redirecting or your dns is being redirected

                              And @aguard sure an the hell would never work.. Its not an IP address or a fqdn that could be resolved by anything.

                              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 25.07 | Lab VMs 2.8, 25.07

                              F 1 Reply Last reply Reply Quote 0
                              • F Offline
                                fjmp24 @johnpoz
                                last edited by

                                @johnpoz Sorry I wrote my message quickly

                                I want to redirect all DNS requests to my internal DNS server Adguard Home.

                                I configured Adguard Home as DNS server in my DHCP servers so by default my devices use Adguard Home as DNS server.

                                Now I want to redirect DNS request that do not have Adguard Home as destination to Adguard Home.
                                I followed the procedure of @AndyRH but I have a name revolving problem. Adguard Home does not display names all the time. When I executes theses commands from a client device I have:

                                • dig @1.2.3.4 google.fr, adguard displays firewall address
                                • dig @<Adguard home ip> google.fr, adguard displays client address

                                I think the problem is with the mappings rules but I don't know how to fix it. Ideas ? Thanks

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

                                  @fjmp24 said in pfSense - DNS redirect to local DNS server:

                                  adguard displays firewall address

                                  What does this mean? You are seeing this error?

                                  unexpected.jpg

                                  Would be helpful if you showed how you setup redirection, and the actual output of your dig command.

                                  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 25.07 | Lab VMs 2.8, 25.07

                                  F 1 Reply Last reply Reply Quote 0
                                  • F Offline
                                    fjmp24 @johnpoz
                                    last edited by fjmp24

                                    @johnpoz No I have not an error.

                                    Dig response:
                                    e6014a1d-6023-428d-aa5f-be943297345b-image.png

                                    Adguard home log:
                                    792dc93e-6f3e-4879-bd45-988ba9ecc4bc-image.png

                                    IP is my pfsense address.

                                    My configuration:

                                    d59edbba-4755-46de-a92a-22bfc5c4f3d5-image.png

                                    ad2e93af-c4e3-41cb-9e09-ac85601f804d-image.png

                                    d44ac2b9-ef1e-42e5-b5a6-3e99062b928a-image.png

                                    The alias MAIN_Host_Shepheherd represents Adgaurd Home host.

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

                                      @fjmp24 what do you think it would show? your doing an outbound nat that nats it to your main address..

                                      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 25.07 | Lab VMs 2.8, 25.07

                                      F 1 Reply Last reply Reply Quote 0
                                      • F Offline
                                        fjmp24 @johnpoz
                                        last edited by fjmp24

                                        @johnpoz Client IP

                                        6f96892b-c97a-4740-af60-670f2f7df600-image.png

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

                                          @fjmp24 not sure what that has to do with you... Your doing you have a outbound nat on man, that says any traffic to that main host, on dns ports to nat it to your main address..

                                          Here I setup a quick port forward to my pihole... You can see it lists my client as who asked for it.

                                          redirect.jpg

                                          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 25.07 | Lab VMs 2.8, 25.07

                                          F 1 Reply Last reply Reply Quote 1
                                          • F Offline
                                            fjmp24 @johnpoz
                                            last edited by

                                            @johnpoz I created the same rules and I have not the same result

                                            62acdc61-1697-4663-87e7-afd24b03ce22-image.png

                                            I disabled my outbound rule. Your DNS server is in LAN network ?

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