If you’re concerned about security, you can use “stealth mode” to make it more difficult for hackers and malware to find your Mac. When stealth mode is on, your Mac doesn’t respond to either “ping” requests or connection attempts from a closed TCP or UDP network.
On your Mac, choose Apple menu >System Settings, click Network in the sidebar, then click Firewall. (You may need to scroll down.)
If Firewall is turned off, first turn it on. See Block connections to your Mac with a firewall.
Click Options.
Turn on “Enable stealth mode”, then click OK.