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

    How to Block all Ports, except 80, 21, 22, 443

    Scheduled Pinned Locked Moved Firewalling
    13 Posts 4 Posters 12.0k 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.
    • D Offline
      doktornotor Banned
      last edited by

      No need. Just don't allow them.

      1 Reply Last reply Reply Quote 0
      • S Offline
        shersinghrawat
        last edited by

        ;D ;D ;D

        I am serious… how to do it in pfSense

        1 Reply Last reply Reply Quote 0
        • D Offline
          doktornotor Banned
          last edited by

          Yeah, I am serious as well.

          1 Reply Last reply Reply Quote 0
          • DerelictD Offline
            Derelict LAYER 8 Netgate
            last edited by

            https://doc.pfsense.org/index.php/Firewall_Rule_Basics

            https://doc.pfsense.org/index.php/Firewall_Rule_Processing_Order

            https://doc.pfsense.org/index.php/Firewall_Rule_Troubleshooting

            Chattanooga, Tennessee, USA
            A comprehensive network diagram is worth 10,000 words and 15 conference calls.
            DO NOT set a source address/port in a port forward or firewall rule unless you KNOW you need it!
            Do Not Chat For Help! NO_WAN_EGRESS(TM)

            1 Reply Last reply Reply Quote 0
            • S Offline
              shersinghrawat
              last edited by

              Dear Derelict,

              I have already gone through all the links you posted. But I am not able to figure out how to implement what i said earlier in the post. I just need some assistance.

              Sher

              1 Reply Last reply Reply Quote 0
              • DerelictD Offline
                Derelict LAYER 8 Netgate
                last edited by

                Pass the traffic you want passed then block everything else.

                There is a default deny rule, which is what @doktornotor was referring to.  If you don't pass it, it is blocked by default.  So the "block everything else" instructions above are redundant.

                If the only rules on an interface pass traffic to 80, 21, 22, 443, everything else will be blocked and you will be done.

                Chances are you also want pass rules to some DNS servers somewhere.

                Chattanooga, Tennessee, USA
                A comprehensive network diagram is worth 10,000 words and 15 conference calls.
                DO NOT set a source address/port in a port forward or firewall rule unless you KNOW you need it!
                Do Not Chat For Help! NO_WAN_EGRESS(TM)

                1 Reply Last reply Reply Quote 0
                • S Offline
                  shersinghrawat
                  last edited by

                  how can i block the port level traffic on some interface.

                  1 Reply Last reply Reply Quote 0
                  • DerelictD Offline
                    Derelict LAYER 8 Netgate
                    last edited by

                    Goodness.

                    ![Screen Shot 2015-07-25 at 4.18.49 AM.png](/public/imported_attachments/1/Screen Shot 2015-07-25 at 4.18.49 AM.png)
                    ![Screen Shot 2015-07-25 at 4.18.49 AM.png_thumb](/public/imported_attachments/1/Screen Shot 2015-07-25 at 4.18.49 AM.png_thumb)

                    Chattanooga, Tennessee, USA
                    A comprehensive network diagram is worth 10,000 words and 15 conference calls.
                    DO NOT set a source address/port in a port forward or firewall rule unless you KNOW you need it!
                    Do Not Chat For Help! NO_WAN_EGRESS(TM)

                    1 Reply Last reply Reply Quote 0
                    • D Offline
                      doktornotor Banned
                      last edited by

                      @Sher:

                      But I am not able to figure out how to implement what i said earlier in the post. I just need some assistance.

                      For goddamn sake. When you ONLY allow the PortsOK ports, then everything else will be BLOCKED by default!

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

                        Dude really if you can not figure this out - maybe you shouldn't be using something like pfsense.  Whatever your isp gave you prob better suited for your skill set.

                        It really is stupid simple.. As clearly stated if not allowed it is blocked.  So if you created an alias called ports ok, then put that in the dest ports.. See attached screenshots.

                        Keep in mind if that is your only rule, you won't even be allowed to ping or talk to pfsense other than the lockout rule allow you access to pfsense gui..  How are you going to get dns?  You might want to add 53 into your ports rule.  And make sure you allow udp for 53, you could just use any as the protocol vs tcp only.

                        Also I feel your going to have issues with such a rule.. The default lan rule is any any for a reason - users that can not figure out basics like this, once you start blocking stuff and break stuff on the internet.. For example my dns point.  Your not going to have a good time with pfsense..  While you have the basic ports allowed.. For example 21 for ftp…  How exactly do you think the data channel is going to work??

                        Active sure would not work because WAN is block all by default and you don't have any forward setup and there is no ftp helper or proxy any more.  And if your trying to use passive where your client would talk to the data port the ftp server gives you - you have all ports blocked, your sure not going to talk to ftp server data channel on 22, 80 or 443..

                        If you implement this sort of rule, I am quite sure you will be back with XYZ doesn't work, etc..

                        allowedports.png
                        allowedports.png_thumb

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

                        1 Reply Last reply Reply Quote 0
                        • S Offline
                          shersinghrawat
                          last edited by

                          Thanks guys, for your support.

                          I am a novice in case of pfSense and started using it about a month ago.

                          I have pfSense 2.2.3 64bit with Squid3, SquidGuard and Snort running successfully. I want to to block torrent downloads for LAN users. As torrent clients use random ports, therefore, I want to open only certain known ports (portsOK) and block all others. I will be adding more and more ports to portsOK as per requirement.

                          dashboard.png
                          dashboard.png_thumb

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

                            So you do understand torrent clients can use proxies right..  If you had snort working - it could be set to block p2p 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 24.11 | Lab VMs 2.8, 24.11

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