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

    Allowing only specific DNS server through firewall

    Scheduled Pinned Locked Moved Firewalling
    9 Posts 3 Posters 1.3k Views
    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.
    • M
      mattlach
      last edited by

      Hi all,

      I wrote a longer post regarding my goals, but my firewalling question was embedded in a question about the cron package, which means it might have wound up in the wrong section to get a good answer from firewalling experts, so I figured I'd try again here.

      I have one VLAN on my network (using interface ix1.5) which I am trying to do some DNS based family filtering on.

      I decided to try the free OpenDNS family Shield DNS servers (208.67.222.123, 208.67.220.123). I added them to the DNS list in the DHCP server configuration for just that VLAN:

      64be6e42-27e2-4a6a-bd19-34d341752456-image.png

      This works beautifully. Devices on that specific VLAN that pull an IP via DHCP show the correct thwo DNS servers locally and use the DNS filter as intended.

      There is nothing to stop it from being circumvented by changing the DNS server though. I tried to fix this by adding a few firewall rules, first one each that explicitly allow the above two IP addresses on port 53 (DNS) then one directly below those that blocks ALL port 53 attempts, as screen capped below:

      437b9804-6d8d-4776-a112-0fad9893b4b1-image.png

      This - however - did not work. After adding these three rules, making sure they were in the correct order, saving and refreshing rules, the VLAN promptly lost all access to DNS.

      So, something is wrong with my firewall rules.

      I'd appreciate any suggestions on what I might try to get this working as intended.

      Thanks,
      Matt

      V 1 Reply Last reply Reply Quote 0
      • V
        viragomann @mattlach
        last edited by

        @mattlach
        Obviously these pass rules have already handled some traffic as the states and bytes counter are showing.
        Do you also have other rules in place to allow upstream traffic?

        M 1 Reply Last reply Reply Quote 0
        • M
          mattlach @viragomann
          last edited by

          @viragomann said in Allowing only specific DNS server through firewall:

          @mattlach
          Obviously these pass rules have already handled some traffic as the states and bytes counter are showing.
          Do you also have other rules in place to allow upstream traffic?

          I appreciate the reply!

          Hmm.

          When you say "upstream" where would they be?

          The subnet for this network is 10.0.5.0/24 with a gateway at 10.0.5.1.

          The only other upstream place I think they could be would be on the WAN interface.

          Do DNS servers typically need to be explicitly allowed on the WAN? I don't think I've ever had to do that before.

          The only real rules on my WAN interface are the standard ones (block Bogon and Private networks) and a few port forwards for my server.

          Appreciate your thoughts.

          V 1 Reply Last reply Reply Quote 0
          • V
            viragomann @mattlach
            last edited by

            @mattlach
            No, on exactly the same interface you need additional pass rule to allow any traffic apart from DNS, like HTTP.

            M 1 Reply Last reply Reply Quote 0
            • M
              mattlach @viragomann
              last edited by

              @viragomann said in Allowing only specific DNS server through firewall:

              @mattlach
              No, on exactly the same interface you need additional pass rule to allow any traffic apart from DNS, like HTTP.

              Oh, OK. Thank you I understand what you mean now.

              Here is the whole shebang for this network in it's current working state:

              9be3730f-d66f-4e57-8cf6-1152da96c995-image.png

              What you are looking at here us first three rules blocking this network from logging on to pfsense via http, https or ssh.

              Nerxt are the three rules that cause trouble, currently disabled, so things are working. First the rules that allow access on port 53 to the two specific IP addresses, followed by the rule that blocks all other requests via port 53.

              Next are six rules that block access to all of the other Subnets on their separate VLAN's, and last is the default allow any rule.

              So, as mentioned, in its current state it works, the local clients are using the desired DNS and have their content filtered, but there is nothing to prevent the change of DNS server on the local machine to circumvent the content filtering.

              As soon as I enable those three greyed out rules, the network loses all DNS. I can still ping outside IP addresses on the internet, but without DNS I can't really do anything.

              Each of the two "Allow" rules look as follows:

              1f8441cd-5105-4e00-8d57-5b4b0f857018-image.png

              The only difference between them is the target IP address.

              The block rule looks like this.

              6dee6a91-1804-409f-9dc3-d6195348198c-image.png

              From my limited understanding (I'm trying to learn) of firewall rules, this really ought to work. It's puzzling me that it isn't.

              I'd appreciate any suggestions you or anyone else may have!

              V 1 Reply Last reply Reply Quote 0
              • V
                viragomann @mattlach
                last edited by

                @mattlach said in Allowing only specific DNS server through firewall:

                What you are looking at here us first three rules blocking this network from logging on to pfsense via http, https or ssh.

                To achieve that, it's better to use "This firewall" as destination. This covers all pfSense IPs, otherwise it may be possible to access another interface IP of pfSense.

                The rules look well indeed and should work this way.
                I suspect, that the client isn't really using the allowed DNS servers. You may use the Packet Capture tool in the Diagnostic menu on pfSense GUI to investigate that.

                However, a more reliable way to achieve what you want may be natting any DNS traffic from that subnet to the external DNS servers. A NAT portforwarding rule with destination address any and port DNS and redirecting to the external server should do the job.
                You may also add the two DNS servers to an alias and use this one for redirecting, so pfSense sends request alternately to the servers.

                With the NAT rule the client my think he is accessing his preferred DNS server while the requests are effectively redirected to the server given in the rule.
                However, also consider the possibility of using DoH today.

                GertjanG M 2 Replies Last reply Reply Quote 0
                • GertjanG
                  Gertjan @viragomann
                  last edited by

                  The rule with a red line in front of them :

                  1805b28a-9c76-4fb5-ad1e-46e6a1a59f10-image.png

                  are disabled right now.

                  No "help me" PM's please. Use the forum, the community will thank you.
                  Edit : and where are the logs ??

                  M 1 Reply Last reply Reply Quote 0
                  • M
                    mattlach @viragomann
                    last edited by

                    @viragomann said in Allowing only specific DNS server through firewall:

                    @mattlach said in Allowing only specific DNS server through firewall:

                    What you are looking at here us first three rules blocking this network from logging on to pfsense via http, https or ssh.

                    To achieve that, it's better to use "This firewall" as destination. This covers all pfSense IPs, otherwise it may be possible to access another interface IP of pfSense.

                    The rules look well indeed and should work this way.
                    I suspect, that the client isn't really using the allowed DNS servers. You may use the Packet Capture tool in the Diagnostic menu on pfSense GUI to investigate that.

                    However, a more reliable way to achieve what you want may be natting any DNS traffic from that subnet to the external DNS servers. A NAT portforwarding rule with destination address any and port DNS and redirecting to the external server should do the job.
                    You may also add the two DNS servers to an alias and use this one for redirecting, so pfSense sends request alternately to the servers.

                    With the NAT rule the client my think he is accessing his preferred DNS server while the requests are effectively redirected to the server given in the rule.
                    However, also consider the possibility of using DoH today.

                    I like the NAT forwarding idea. I will try that. Thank you for the suggestion!

                    1 Reply Last reply Reply Quote 0
                    • M
                      mattlach @Gertjan
                      last edited by

                      @gertjan said in Allowing only specific DNS server through firewall:

                      The rule with a red line in front of them :

                      1805b28a-9c76-4fb5-ad1e-46e6a1a59f10-image.png

                      are disabled right now.

                      Yes,

                      Thank you for taking the time to reply.

                      As I explained in my post, they are temporarily disabled because when I turn them on, DNS on the network stops working.

                      What I am trying to accomplish is for DNS to work once these are enabled.

                      I am going to try the NAT:ing suggestion above.

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