How to block an IP address on macOS?
We often get asked ‘How to block an IP address on mac?’. Let’s dive in…
There are some situations where you need to block an IP address on a mac, but it depends on which kind of user you are. If you have a home-based connection and only need to block one IP address from being accessed by anyone, it can be done in system preferences. There is no way to have the blocked IP addresses shown in the menu bar or within the finder unless you download a 3rd party application that will show a blocked list of numbers.
Kindly note that the below require advanced knowledge of MacOS. If you don’t know what you are doing, kindly get in touch with one of our technicians who excels at Apple mac repair in Melbourne.
How to add a firewall rule on MacOS 10.7 and above?
You do not need any software for blocking an IP Address with OS X 10.7+ if you know how to configure your router properly. So basically all home users have this ability without needing any extra software. In addition, if someone knows what they are doing they can log into the router’s address and unblock any IP Address they wish.
If you want to block an IP address on mac, follow these steps:
1. Open system preferences either from your dock or Apple menu > System Preferences.
2. Click on “Network” located in the internet and wireless section of the preferences window under hardware (if using a MacBook Air click on the network at the very left of system preferences).
3. Select the connection type that is being used for internet access by clicking once on it and not double-clicking as this will bring up fine-tune controls window instead of a basic internet connection details window. In this case, we are going to choose Airport from the connection list as this is what is usually used for wifi.
4. Click on the “Advanced” button located at the bottom right of the internet connection details window.
5. A new network preference pane will pop up, click on the “Firewall” tab then check go into the stealth mode option that is under the block incoming connections section to activate blocking features of Mac firewall (see attached picture). If you want Mac to perform automatic successful outbound packet detection and block outgoing traffic as well then enable Block all incoming connections option as well from this new preferences pane however note that disabling both options under allow section from this network preference pane isn’t going to completely disable firewall feature from mac as there are still some other methods that can be used in order prevent your mac from being compromised or hacked. For example, if you are using any third-party apps that support connection to their servers via SSL then “Block all incoming connections” option in mac firewall isn’t going to affect them and we can use different methods such as using application-specific rules for this task or we can simply add rules in order prevent certain connections so they will be automatically rejected and won’t even reach our computer, however in most cases you will want to block entire IP address ranges instead of individual IP addresses when it comes to these situations because you might not know which range is responsible for brute force attacks on your SSH port (for ex. – lets say some attacker tries to access your ssh server from 126.96.36.199:22 IP address and fails to login 5 times within 5 minutes, then your rules will be triggered and block that range of IP addresses making our ssh service inaccessible for other users at the same time period).
How to add a firewall rule on MacOS 10.9 and above?
In this article, I’m going to show you how to add a firewall rule on mac os x 10.9 Mavericks so you can block all incoming connections from an entire IP address range. This method is quite simple and it won’t take much time to implement it however there are some disadvantages when using it such as blocking legit traffic from others but in most cases, this isn’t a big issue if you have decent hardware which can handle several connection attempts made by attackers or simply use VPN software whenever you need to access resources behind your mac computer. The first thing we need to do is add a firewall rule to block all connections from the ip address we want using the terminal so let’s do it!
To block an ip you can also check this method: how to block any website on mac os x
We need to access the Terminal which can be done by going to Launchpad -> Utilities -> and then open the terminal. After that you have to type these commands in order :
sudo ipfw add reject src-ip <ip>/<netmask>
After that just enter your admin password and thats all !
Your incoming connections will be now denied from this specific ip for as long as the duration of your computer’s session which means until you shut down or restart your Apple Mac.
How to remove a firewall rule?
In case you want to remove this entry use the following command :
sudo ipfw delete <rule_number>
And here you can see why using ipset is much better. For removing the rule number you have to go in the list of rules with: sudo ipfw list and then find your particular rule number and remove it with: sudo ipfw delete [rule number] . For example, if I want to block a spammer on a web forum I simply add a rule for blocking his IP so he cant connect again right away, but if someone else wants to contact me from that specific ISP or other users from that network I wouldn’t have any problems because other people are still allowed through. In case the spammer gets another IP just add another rule for it. The same works for a single website, if you want to block it for everyone but yourself then let’s say you go to the list of rules with: sudo ipfw list and then find your particular rule number and double-check that it is really referring to the site you think. Then remove the whole line with: sudo ipfw delete [rule number]. If someone else can access the site fine as long as they are not from that specific network or ISP. In this case, the other people would still be able to see what you have blocked.