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

    Regex - How to block subdomains?

    Scheduled Pinned Locked Moved pfBlockerNG
    4 Posts 2 Posters 1.1k 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.
    • CreationGuyC
      CreationGuy
      last edited by

      I'm trying to block a domain and all of it's subdomains, I've tried a few different methods and none seem to be working.

      \.google\.
      

      With that, I can't get to www.google.com but can get to subdomains.

      (\.|^)google\.com$
      

      Same results as above.

      (^|\.)google\.com$
      

      Same results as above.

      P 1 Reply Last reply Reply Quote 0
      • P
        Patch @CreationGuy
        last edited by Patch

        @creationguy said in Regex - How to block subdomains?:

        I'm trying to block a domain and all of it's subdomains,

        I suspect what you want to do is hard at the firewall level.
        You could try blocking Googles ASN in pfblockerNG then white list what you want to allow. Unfortunately Google frequently changes the IP address each domain name resolves to, so to make this solution work, pfsense needs aliases with history (which I don't think are currently supported).

        Alternatively blocking it at the DNS may be possible.

        CreationGuyC 1 Reply Last reply Reply Quote 0
        • CreationGuyC
          CreationGuy @Patch
          last edited by

          Google was just an example, not the real domain. Wouldn't this be best accomplished within the pfBlocker package? That's what I'm trying to do.

          It works in Pihole use the 1st regex, but not here.

          CreationGuyC 1 Reply Last reply Reply Quote 0
          • CreationGuyC
            CreationGuy @CreationGuy
            last edited by CreationGuy

            Update:

            (^|\.)domain\.com$
            

            Blocks the domain and subdomain... I just didn't clear my DNS cache on device. So far, it is working.

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