Mac OSX – open a port

MacOS

Question or issue on macOS:

I want to open the port 25 of my Mac, so I edited the file /etc/pf.conf

MacBook-Pro-de-nunito:~ calzada$ more /etc/pf.conf
#
# Default PF configuration file.
#
# This file contains the main ruleset, which gets automatically loaded
# at startup.  PF will not be automatically enabled, however.  Instead,
# each component which utilizes PF is responsible for enabling and disabling
# PF via -E and -X as documented in pfctl(8).  That will ensure that PF
# is disabled only when the last enable reference is released.
#
# Care must be taken to ensure that the main ruleset does not get flushed,
# as the nested anchors rely on the anchor point defined here. In addition,
# to the anchors loaded by this file, some system services would dynamically 
# insert anchors into the main ruleset. These anchors will be added only when
# the system service is used and would removed on termination of the service.
#
# See pf.conf(5) for syntax.
#

#
# com.apple anchor point
#
pass in proto tcp from any to any port 80
pass in proto tcp from any to any port 25
scrub-anchor "com.apple/*"
nat-anchor "com.apple/*"
rdr-anchor "com.apple/*"
dummynet-anchor "com.apple/*"
anchor "com.apple/*"
load anchor "com.apple" from "/etc/pf.anchors/com.apple"

But when I restart the service, I got these errors:

MacBook-Pro-de-nunito:~ calzada$ sudo pfctl -f /etc/pf.conf
pfctl: Use of -f option, could result in flushing of rules
present in the main ruleset added by the system at startup.
See /etc/pf.conf for further details.

No ALTQ support in kernel
ALTQ related functions disabled
/etc/pf.conf:24: Rules must be in order: options, normalization, queueing, translation, filtering
/etc/pf.conf:25: Rules must be in order: options, normalization, queueing, translation, filtering
/etc/pf.conf:26: Rules must be in order: options, normalization, queueing, translation, filtering
pfctl: Syntax error in config file: pf rules not loaded

adding the lines at the end of the file:

MacBook-Pro-de-nunito:~ calzada$ sudo pfctl -f /etc/pf.conf
pfctl: Use of -f option, could result in flushing of rules
present in the main ruleset added by the system at startup.
See /etc/pf.conf for further details.

No ALTQ support in kernel
ALTQ related functions disabled
MacBook-Pro-de-nunito:~ calzada$ nmap -p 25 localhost

Starting Nmap 7.40 ( https://nmap.org ) at 2017-03-12 21:35 CET
Nmap scan report for localhost (127.0.0.1)
Host is up (0.00023s latency).
Other addresses for localhost (not scanned): ::1
PORT   STATE  SERVICE
25/tcp closed smtp

Nmap done: 1 IP address (1 host up) scanned in 0.04 seconds

How to solve this problem?

Are you sure you have something listening on port 25? If you don’t have anything listening on port 25 it will show as closed.

As you ran nmap on localhost you wouldn’t even need to allow anything through the firewall. You would only need to allow it through the firewall if traffic was coming inbound from another device.

You can use the following to check if a program is listening on port 25

lsof -n -i:25 | grep LISTEN

Hope this helps!