Block A Specific Port In Linux Mint

If you’re using Linux Mint, you’ll find you have ufw already installed which means it’s easy to block a specific port in Linux Mint! I’ll explain how to do that in this article and do what I can to make it easy enough for a new Linux user to follow. If this interests you, read on!

You might want to block a port for all sorts of reasons. If you’re open to the public web via your router, you might find bots hammering at the default ports (such as 22 for SSH) trying to find the login credentials, even if none exist. This is unnecessary traffic and can cause the system to slow down if it’s overwhelmed with connection requests.

Also, Linux uses a lot of ports. There are a bunch that are reserved, for example. You can also designate your ports for many things. I’ve written articles about ports before, so here’s some light reading material:

How To: Check If A Specific Port Is Open
How To: Scan A Remote Host For Open Ports
Find Out What Process Is Listening On A Specific Port
Prevent Brute-Force SSH Attacks With fail2ban

About Ports:

Now, I think I’ll let an AI tell you what a port is in Linux.

A Linux port is a virtual concept that helps access different services within a network. A port is a 16-bit integer ranging from 0 to 65535 with no physical existence.

A port acts as a communication endpoint for identifying a given process or application on the Linux operating system. A port is a 16-bit (o to 65535) number that differentiates a single application from others on various end systems.

As the blurb says, these are virtual ports. They’re not like the physical ports on your router, or anything like that. They’re used for communication and sending traffic to a specific port is asking for traffic on that port. 

If you have nmap installed, you could run nmap localhost to find out which ports are open on your computer. You probably should run that command (you’ll need to install nmap with sudo apt install nmap before you can run this command in Linux Mint). If the port isn’t open, then you don’t need to block that specific port.

UFW:

Linux Mint comes with ‘ufw’ already installed. It is not enabled by default, however. It’s good that it comes installed, which means it’s almost ready for use and you only need to enable ufw for it to be of use. If you don’t know what ufw is, you can check the man page with man ufw to learn more. For simplicity’s sake, you’ll find that ufw is described as:

ufw – program for managing a netfilter firewall

We will be using ufw to block a specific port in Linux Mint. You’ll learn that ufw stands for “Uncomplicated Firewall” and is a frontend for iptables. You can do anything with iptables that you can with ufw, but ufw is much easier for a new Linux Mint user. It doesn’t need to be complicated, as you’ll see in this article.

Use UFW To Block A Specific Port In Linux Mint:

While there is a GUI front-end for ufw, we won’t be using that. Instead, we’ll just use the installed terminal and ufw. As you’re using Linux Mint, you can open your default terminal by pressing CTRL + ALT + T.

With your terminal now open, we first need to enable ufw because ufw is not enabled by default. To enable ufw, run the following command:

That will enable ufw on system startup. That command should output something that looks like this:

You can later disable ufw if you find you no longer wish to use it. That command would look like this:

Now, to block a specific port in Linux Mint with ufw, the syntax would be easy enough to figure out. It just looks like this:

If you want to block the default SSH port (port 22) then you can do that like so:

If you change your mind at a later date, the command to undo this would be:

All you need to do is remember ‘deny’ and ‘allow’ and that ufw commands require elevated permissions which means you need to use sudo. If you can remember that, you can block and unblock specific ports in Linux Mint!

Closure:

Yes, this article is about blocking a specific port in Linux Mint with the ufw command, but it applies to many other distros. I just happened to be using Linux Mint when I wrote the article and didn’t want to test on other systems before smashing the schedule button. So, I wrote it specifically for Linux Mint. This will likely be an accurate tutorial for Ubuntu, the official Ubuntu flavors, other Ubuntu derivatives, and maybe Debian. I’m not sure about Debian.

And now you know…

Thanks for reading! If you want to help, or if the site has helped you, you can donate, register to help, write an article, or buy inexpensive hosting to start your site. If you scroll down, you can sign up for the newsletter, vote for the article, and comment.

Subscribe To Our Newsletter
Get notified when new articles are published! It's free and I won't send you any spam.
Linux Tips
Creative Commons License
This work is licensed under a Creative Commons Attribution 4.0 International License.