The firewall on a Mac selectively blocks unauthorised apps and services from the internet. However, you may find that the Mac firewall is switched off by default.
To switch on the Mac firewall, click Finder > Security & Privacy. Click the Firewall tab then Turn on Firewall to activate it.
Mac firewall options
Under Firewall Options you can block all incoming connections, or allow or deny them for selected items.
Click Enable stealth mode to stop your Mac from responding to uninvited internet traffic. Check Automatically allow signed software to receive incoming connections to avoid unwanted notifications.