Publishers of technology books, eBooks, and videos for creative people

Home > Articles > Apple > Operating Systems

This chapter is from the book

Understanding the Mac OS X Server Firewall

Though Mac OS X’s Application Firewall provides a simplified interface for handling firewall rules based on services and applications, Mac OS X Server administrators require more granular access controls than the Application Firewall provides. Mac OS X Server v10.6 contains a host-based firewall service based on ipfw software that was developed as part of the FreeBSD project. This traditional stateful packet firewall provides stateless or stateful packet inspection.

Stateful packet inspection tracks the state of network connections traveling across it. A stateless firewall looks at packets as individual events. A stateful firewall, on the other hand, can track multipacket communication sessions and more intelligently accept or deny traffic. For example, a stateful firewall can remember that a protected client initiated a request to download data from an Internet server and allow data back in for that connection.

Mac OS X Server can do both stateless and stateful processing. To use stateful processing, Mac OS X Server adds the keep-state keyword to rules. Since the release of Mac OS X Server version 10.5 Leopard, an Adaptive Firewall has been present in OS X Server. The Adaptive Firewall will monitor firewall activity and block an IP address that has excessive failed login attempts.

While documentation may make this seem like a second firewall, the Adaptive Firewall is really a monitor that dynamically creates and disables rules in the ipfw firewall as needed. The Adaptive Firewall is currently called into action following ten failed login attempts. Such behavior blocks the requesting IP address for 15 minutes, which makes brute-force password attacks virtually impossible. No administrator needs to take action to enable the Adaptive Firewall, as it is enabled by default.

Accessing the Firewall Setup

Some servers will have access to several networks such as an internal network, the Internet, and a management network. To avoid having to configure rules manually for each system on a specific network, you can create an address group to handle network addresses. The Address Groups tab in the Settings pane enables you to group addresses logically and create address ranges to which you can then apply rules. An address group can be a single address, such as 192.168.3.1, or a range of addresses, such as 192.168.3.0–192.168.3.255. You can set up a range of addresses using subnet mask notation (192.168.3.0: 255.255.255.0) or Classless Interdomain Routing (CIDR) notation (192.168.3.0/24).

  1. From the Dock, open Server Admin.
  2. Authenticate, if necessary, and then click the name of the server you want to configure.
  3. In the Toolbar, click the Settings button, and then select the Firewall checkbox, if necessary.
  4. At the lower right of the Server Admin window, click Save.
  5. In the leftmost pane, click the Firewall service.
  6. Click the Address Groups tab (as seen in the figure above).
  7. Click the Add (+) button located at the bottom of the Server Admin window.
  8. In the proceeding dialog box, enter the network address or range (using subnet notation), and then click OK to add the group.

    You will now be able to assign rules to this specific address group.

  9. Click the pencil button if or when you need to edit existing groups.

Configuring Service Firewall Rules

The Services tab defines the rules for predetermined services for a given address group selected in the pop-up menu.

By default, all traffic is allowed out, but only Apple administrative ports and established traffic are allowed in. Established traffic has validly been sent out and is receiving a reply. Established traffic may receive reply traffic on ports that are closed, but because the firewall software tracks established traffic, use of the ports is allowed for established traffic streams.

The Services tab contains a long list of predefined services, any of which may be activated for a given address group. If the service or port range needed has not been predefined, it is easy to add a custom service. To add a custom service like Jabber for the iChat service, do the following:

  1. Click the Advanced tab.
  2. Click the Add (+) button to display a dialog box in which you can define a custom service to add to the list.
  3. Provide a name for the service you are configuring. In this exercise, enter Jabber.
  4. Enter the port numbers and, from the Protocol pop-up menu, choose a transport type (such as TCP for Jabber).

    If you are not sure which port to add for a given service, you can get that information from several places. You can find well-known services in the /etc/services file on your local computer.

  5. In Applications > Utilities, open the Terminal application.
  6. Use the grep command to filter out terms in the services file, which contains a list of known services and their associated ports and transport types:
    $ grep -i jabber-server /etc/services
    jabber-server      5269/udp  # Jabber Server Connection
    jabber-server      5269/tcp  # Jabber Server Connection
    
  7. Click OK to save your rule.
  8. To view the rules you are currently enforcing with your firewall, in the Toolbar, click the Active Rules button.

    This displays the currently active rules for all rule sets and address groups.

    Notice that each rule includes a priority number, the number of packets and bytes affected by the rule, and a description of the rule.

As mentioned earlier in “Understanding the Mac OS X v10.6 Server Firewall,” the firewall service in Mac OS X Server is built on top of ipfw, a kernel-based application. This means that the actual code for the ipfw service(s) is built into the kernel stack, making it extremely fast and secure from tampering. You can control ipfw via the same-named command-line program.

Verifying current firewall rules is simply a matter of asking ipfw to list them. This list corresponds to the list in the Active Rules pane in Server Admin.

  1. In Applications > Utilities, open the Terminal application.
  2. Execute the ipfw command using the list argument:
    # ipfw list
    01000 allow ip from any to any via lo0
    01010 deny ip from any to 127.0.0.0/8
    01020 deny ip from 224.0.0.0/4 to any in
    01030 deny tcp from any to 224.0.0.0/4 in
    12300 allow tcp from any to any established
    12301 allow tcp from any to any out
    12302 allow tcp from any to any dst-port 22
    12302 allow udp from any to any dst-port 22
    12303 allow udp from any to any out keep-state
    12304 allow tcp from any to any dst-port 53 out keep-state
    12304 allow udp from any to any dst-port 53 out keep-state
    12305 allow udp from any to any in frag
    12306 allow tcp from any to any dst-port 311
    12307 allow tcp from any to any dst-port 625
    12308 allow udp from any to any dst-port 626
    12309 allow icmp from any to any icmptypes 8
    12310 allow icmp from any to any icmptypes 0
    12311 allow igmp from any to any
    65534 deny ip from any to any
    65535 allow ip from any to any
    

    Dissecting this output, let’s take ssh tcp as an example:

    12302 allow tcp from any to any dst-port 22
    

    The first position is the rule number; the second is the action (allow or deny); the third position represents protocol type, TCP in our example. Fourth is the from-to combination explaining the allowed or denied path of traffic. In this case you are allowing TCP from any network to any network (equivalent to allow all), and the final two positions describe the type of rule, in this case a port-based rule, and the port number. So reading this across, you are allowing TCP from any network to any network on port 22.

Using Stealth Mode

In the Server Admin Settings pane, under the Advanced tab, you can set stealth options and create custom rule sets for the firewall service. Stealth options drop denied packets rather than sending the requesting computer an error message.

Once you have completed setup and testing, you should enable the Stealth Mode option for both TCP and User Datagram Protocol (UDP), which makes the job for attackers much more difficult as probing attacks and open port discovery are thwarted.

  1. In the Stealth Mode section of the Advanced tab, select the “Enable For TCP” checkbox.
  2. Select the “Enable for UDP” checkbox.
  3. From Applications > Utilities, open the terminal and type the following command to ping your system:
    ping localhost
    

    You will receive the following timeout message to indicate that your system is not responding to the ping request.

    Request timeout for icmp_seq
    

Understanding Firewall Rule Priority

The rules in the Firewall Settings Services pane operate with the rules shown in the Advanced tab. Usually, the broad rules in the Advanced tab block (or open) access for all ports. These broad, lower-priority (higher-numbered) rules apply after the rules in the Services pane.

The rules created in the Services pane open access to specific services. Higher in priority, Services rules take precedence over those created in the Advanced tab. For most normal uses, using the Advanced tab to open access to designated services is sufficient.

If you create multiple rules in the Advanced tab, the rule number determines the precedence for a rule. This number corresponds to the order of the rule in the Advanced pane. You can reorder rules in the Advanced pane by dragging them up or down in the list. If necessary, you can add more rules using the Advanced pane.

Using ipfw

Although Server Admin treats the firewall as a service, it does not implement the firewall by a running process. Implementation is simply a set of behaviors in the kernel, controlled by the ipfw and sysctl tools. To start and stop the firewall, Server Admin sets a switch using the sysctl tool. Use the sysctl tool to enable the firewall as follows:

$ sysctl -w net.inet.ip.fw.enable=1

You can also disable the firewall by changing the setting to 0:

$ sysctl -w net.inet.ip.fw.enable=0

A successful command will respond with the change made represented after the arrow.

$ net.inet.ip.fw.enabled: 1 -> 0

Regardless of this setting, the rules loaded in the firewall remain. But they are ignored when the firewall is disabled.

You can also use the ipfw command-line program to manipulate firewall rules. This is practical when you’re working remotely or over ssh, or when a scripted solution is needed.

As an example rule, imagine that an Xserve with multiple network interfaces—physical or virtual—is running AFP (Apple Filing Protocol) for file access. The security team decides that AFP should be available only on the subnets that it is serving. AFP does not have the control to specify which interface it binds to. However, you can use the built-in firewall, ipfw, to block AFP on the unwanted ports. For example, to block AFP on the en0 interface, you can use the following command to add the appropriate rule:

ipfw add deny dst-port 548 via en0

The keywords to ipfw are as follows:

  • add—Denotes adding a rule

  • deny—Indicates what type of rule

  • dst-port—Denotes which port the rule affects and is specified by number or service name

  • via—Applies rules to packets arriving via the specified interface or IP address

If a rule number is not specified, ipfw will assign a default number to the added rule. You may want to specify this rule number yourself because the firewall evaluates rules in a sequential order. When a default rule number is assigned, it will be done in such a way that the rule becomes the last rule, prior to the default rule. You can add an equivalent AFP-blocking rule using this command:

ipfw add 6000 deny dst-port afpovertcp via 10.10.15.68

However, doing so specifies the rule number (6000). The command lists the destination port by service name (afpovertcp) and gives an IP address rather than an interface name.

If a rule is incorrect or no longer needed, you can remove it with the del (delete) command by executing the following:

ipfw del 6000

Using Firewall Log Files

The firewall sends log messages to /var/log/ipfw.log. For example, if the AFP service was blocked and a subsequent user request was made to the AFP service from a computer with the IP address of 10.1.17.2, the log might read:

Oct 17 09:41:17 mainserver servermgrd[58]: servermgr_ipfilter:ipfw
config:Notice:Flushed IPv6 rules
Oct 17 09:41:19 mainserver servermgrd[58]: servermgr_ipfilter:ipfw
config:Notice:Enabled firewall
Oct 17 09:41:24 mainserver ipfw[1940]: 1040 Deny TCP 10.1.17.2:49232 10.1.0.200:548
in via en0
Oct 17 09:41:59 mainserver ipfw[1940]: 1040 Deny TCP 10.1.17.2:49232 10.1.0.200:548
in via en0
Oct 17 09:42:31 mainserver ipfw[1940]: 1040 Deny TCP 10.1.17.2:49232 10.1.0.200:548
in via en0
Oct 17 09:43:31 mainserver ipfw[1940]: 100 Accept TCP 10.1.0.1:721 192.168.12.12:515
in via en0

Each log entry follows a similar form:

  • Time of entry—In this example, it is Oct 17....
  • Host name—In this example, it is mainserver.
  • Process name and ID—In this example, it is ipfw[1940].
  • Log message—The first two lines in this sample simply state that the firewall is flushing, then rereading its configuration, then starting and enabling.

For the firewall itself, each message follows this pattern:

  • Matching rule number—Why the firewall took this behavior
  • Action—The action taken (Deny, Accept, and so on)
  • Protocol—Which protocol this affected (TCP, UDP, and so on)
  • Source—The source IP address of packet
  • Destination—The destination IP address of packet
  • Interface—The network interface on which this packet appeared; in this example, it is in via en0, but it could also be lo0 (loopback), en1, or some other interface.

You can fine-tune logging from the Server Admin graphical user interface (Settings > Logging) or by using the serveradmin command-line utility. For example, to log all allowed packets, you can make the following serveradmin call:

serveradmin settings ipfilter:logAllAllowed = yes

Using Firewall Configuration Files

In Mac OS X Server, the firewall is a service that administrators can configure. In contrast, Mac OS X does not support the firewall directly. Its ipfw-based firewall has no graphical user interface and you must manipulate it via the command line. However, Mac OS X does contain the Application Firewall, which you can configure in Security preferences.

Mac OS X Server uses several files for its ipfw-based firewall. The following configuration files are stored in /etc/ipfilter:

-r--r--r--@  1 root wheel  281 Oct 17 12:56 ip6fw.conf.apple
-r--r--r--  1 root wheel   0 Oct 17 12:33 ip6fwstate-on
-rw-r--r--  1 root wheel 41219 Oct 17 12:56 ip_address_groups.plist
-r--r--r--  1 root wheel 38243 Sep 23 2009 ip_address_groups.plist.default
-rw-r--r--  1 root wheel  1874 Sep 23 2009 ipfw.conf
-r--r--r--@  1 root wheel  1353 Oct 17 12:56 ipfw.conf.apple
-r--r--r--  1 root wheel  1874 Sep 23 2009 ipfw.conf.default
-r--r--r--  1 root wheel   0 Oct 17 12:33 ipfwstate-on
-r--r--r--  1 root wheel  632 Sep 23 2009
standard_services.plist.default

Server Admin writes to these configuration files. Note that:

  • IPv6 and IPv4 rules are kept in separate files.
  • Files with a name ending in “state-on” exist only if the service is running. They are flags used at boot time to indicate if the firewall should be enabled.
  • Plist files contain information presented in Server Admin. They are well commented, and you can customize services and addresses seen in Server Admin. For example, if you have a custom application that communicates with other servers on a particular port, you can add an entry to this file so that this service appears in the list of ports that may be selected via a checkbox.
  • The .apple files are edited by servermgrd. Changes made in these files may be overwritten by changes in Server Admin and may render Server Admin unable to manage the firewall service. You can make changes in other configuration files, such as ipfw.conf. Rules added to ipfw.conf will be loaded into ipfw at start time. The ipfw.conf file lists rules in the same format as rules added with the ipfw command line, minus the ipfw command itself. For example:
    add 03000 allow tcp from any to any http
    

When added to ipfw.conf, rule 3000 is appended to the rule list, allowing HTTP on any interface. In addition, two premigration files may exist if the server was upgraded to version 10.6 from an earlier version.

As mentioned in the section “Using Firewall Log Files,” the Mac OS X Server ipfw logs messages to /var/log/ipfw.log. The Mac OS X Server Adaptive Firewall is configured by and uses several files:

  • /etc/af.plist lists Adaptive Firewall preferences.
  • /var/db/af/whitelist contains addresses that will not be blocked.
  • /var/db/af/blacklist contains addresses that will always be blocked.
  • /System/Library/LaunchDaemons/com.apple.afctl.plist contains the launchd plist.

Do not manually edit the whitelist and blacklist files. Rather, you should use the command-line utility afctl to modify these files. The Apple Event Monitoring daemon, emond, performs the actual monitoring and spurs the Adaptive Firewall into action. While emond is an off-limits subsystem, the man page states that “emond accepts events from various services, runs them through a simple rules engine, and takes action.” One of its rules is /etc/emond.d/rules/AdaptiveFirewall.plist.

This rule is activated after ten failed login attempts and blocks the offending host attempting the login for a period of 15 minutes.

The Mac OS X Application Firewall also contains configuration files that affect its behavior. The Application Firewall is configured in Security preferences.

The Application Firewall can also be configured using the command line. The socketfilterfw program, which resides in /usr/libexec/ApplicationFirewall, can query and configure the Application Firewall. There is no man page for socketilterfw, but a usage statement can be printed when using the -h switch.

By default, the Application Firewall is set to allow all incoming connections. The Application Firewall offers two choices for any given application: “Allow incoming connections” and “Block incoming connections.”

The Application Firewall logs its activity at /var/log/alf.log and is enabled by default when the Application Firewall is active.

A sample log snippet follows:

Sep 29 16:16:00 dhcp-172-26-94-100 Firewall[38]: Deny Microsoft Word data in from
192.168.92.234:52684 uid = 0 proto=17

You can set the Application Firewall state from the command line using the defaults command to alter preferences:

defaults write /Library/Preferences/com.apple.alf globalstate -int 1

In this command, the integer passed is one of the following:

  • 0—Off

  • 1—On for specific services

  • 2—On for essential services

The main preference file for the Application Firewall is located in /Library/Preferences/com.apple.alf.plist.

The executable files for the Application Firewall are located in /usr/libexec/ApplicationFirewall.

Peachpit Promotional Mailings & Special Offers

I would like to receive exclusive offers and hear about products from Peachpit and its family of brands. I can unsubscribe at any time.

Overview


Pearson Education, Inc., 221 River Street, Hoboken, New Jersey 07030, (Pearson) presents this site to provide information about Peachpit products and services that can be purchased through this site.

This privacy notice provides an overview of our commitment to privacy and describes how we collect, protect, use and share personal information collected through this site. Please note that other Pearson websites and online products and services have their own separate privacy policies.

Collection and Use of Information


To conduct business and deliver products and services, Pearson collects and uses personal information in several ways in connection with this site, including:

Questions and Inquiries

For inquiries and questions, we collect the inquiry or question, together with name, contact details (email address, phone number and mailing address) and any other additional information voluntarily submitted to us through a Contact Us form or an email. We use this information to address the inquiry and respond to the question.

Online Store

For orders and purchases placed through our online store on this site, we collect order details, name, institution name and address (if applicable), email address, phone number, shipping and billing addresses, credit/debit card information, shipping options and any instructions. We use this information to complete transactions, fulfill orders, communicate with individuals placing orders or visiting the online store, and for related purposes.

Surveys

Pearson may offer opportunities to provide feedback or participate in surveys, including surveys evaluating Pearson products, services or sites. Participation is voluntary. Pearson collects information requested in the survey questions and uses the information to evaluate, support, maintain and improve products, services or sites; develop new products and services; conduct educational research; and for other purposes specified in the survey.

Contests and Drawings

Occasionally, we may sponsor a contest or drawing. Participation is optional. Pearson collects name, contact information and other information specified on the entry form for the contest or drawing to conduct the contest or drawing. Pearson may collect additional personal information from the winners of a contest or drawing in order to award the prize and for tax reporting purposes, as required by law.

Newsletters

If you have elected to receive email newsletters or promotional mailings and special offers but want to unsubscribe, simply email ask@peachpit.com.

Service Announcements

On rare occasions it is necessary to send out a strictly service related announcement. For instance, if our service is temporarily suspended for maintenance we might send users an email. Generally, users may not opt-out of these communications, though they can deactivate their account information. However, these communications are not promotional in nature.

Customer Service

We communicate with users on a regular basis to provide requested services and in regard to issues relating to their account we reply via email or phone in accordance with the users' wishes when a user submits their information through our Contact Us form.

Other Collection and Use of Information


Application and System Logs

Pearson automatically collects log data to help ensure the delivery, availability and security of this site. Log data may include technical information about how a user or visitor connected to this site, such as browser type, type of computer/device, operating system, internet service provider and IP address. We use this information for support purposes and to monitor the health of the site, identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents and appropriately scale computing resources.

Web Analytics

Pearson may use third party web trend analytical services, including Google Analytics, to collect visitor information, such as IP addresses, browser types, referring pages, pages visited and time spent on a particular site. While these analytical services collect and report information on an anonymous basis, they may use cookies to gather web trend information. The information gathered may enable Pearson (but not the third party web trend services) to link information with application and system log data. Pearson uses this information for system administration and to identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents, appropriately scale computing resources and otherwise support and deliver this site and its services.

Cookies and Related Technologies

This site uses cookies and similar technologies to personalize content, measure traffic patterns, control security, track use and access of information on this site, and provide interest-based messages and advertising. Users can manage and block the use of cookies through their browser. Disabling or blocking certain cookies may limit the functionality of this site.

Do Not Track

This site currently does not respond to Do Not Track signals.

Security


Pearson uses appropriate physical, administrative and technical security measures to protect personal information from unauthorized access, use and disclosure.

Children


This site is not directed to children under the age of 13.

Marketing


Pearson may send or direct marketing communications to users, provided that

  • Pearson will not use personal information collected or processed as a K-12 school service provider for the purpose of directed or targeted advertising.
  • Such marketing is consistent with applicable law and Pearson's legal obligations.
  • Pearson will not knowingly direct or send marketing communications to an individual who has expressed a preference not to receive marketing.
  • Where required by applicable law, express or implied consent to marketing exists and has not been withdrawn.

Pearson may provide personal information to a third party service provider on a restricted basis to provide marketing solely on behalf of Pearson or an affiliate or customer for whom Pearson is a service provider. Marketing preferences may be changed at any time.

Correcting/Updating Personal Information


If a user's personally identifiable information changes (such as your postal address or email address), we provide a way to correct or update that user's personal data provided to us. This can be done on the Account page. If a user no longer desires our service and desires to delete his or her account, please contact us at customer-service@informit.com and we will process the deletion of a user's account.

Choice/Opt-out


Users can always make an informed choice as to whether they should proceed with certain services offered by Adobe Press. If you choose to remove yourself from our mailing list(s) simply visit the following page and uncheck any communication you no longer want to receive: www.peachpit.com/u.aspx.

Sale of Personal Information


Pearson does not rent or sell personal information in exchange for any payment of money.

While Pearson does not sell personal information, as defined in Nevada law, Nevada residents may email a request for no sale of their personal information to NevadaDesignatedRequest@pearson.com.

Supplemental Privacy Statement for California Residents


California residents should read our Supplemental privacy statement for California residents in conjunction with this Privacy Notice. The Supplemental privacy statement for California residents explains Pearson's commitment to comply with California law and applies to personal information of California residents collected in connection with this site and the Services.

Sharing and Disclosure


Pearson may disclose personal information, as follows:

  • As required by law.
  • With the consent of the individual (or their parent, if the individual is a minor)
  • In response to a subpoena, court order or legal process, to the extent permitted or required by law
  • To protect the security and safety of individuals, data, assets and systems, consistent with applicable law
  • In connection the sale, joint venture or other transfer of some or all of its company or assets, subject to the provisions of this Privacy Notice
  • To investigate or address actual or suspected fraud or other illegal activities
  • To exercise its legal rights, including enforcement of the Terms of Use for this site or another contract
  • To affiliated Pearson companies and other companies and organizations who perform work for Pearson and are obligated to protect the privacy of personal information consistent with this Privacy Notice
  • To a school, organization, company or government agency, where Pearson collects or processes the personal information in a school setting or on behalf of such organization, company or government agency.

Links


This web site contains links to other sites. Please be aware that we are not responsible for the privacy practices of such other sites. We encourage our users to be aware when they leave our site and to read the privacy statements of each and every web site that collects Personal Information. This privacy statement applies solely to information collected by this web site.

Requests and Contact


Please contact us about this Privacy Notice or if you have any requests or questions relating to the privacy of your personal information.

Changes to this Privacy Notice


We may revise this Privacy Notice through an updated posting. We will identify the effective date of the revision in the posting. Often, updates are made to provide greater clarity or to comply with changes in regulatory requirements. If the updates involve material changes to the collection, protection, use or disclosure of Personal Information, Pearson will provide notice of the change through a conspicuous notice on this site or other appropriate way. Continued use of the site after the effective date of a posted revision evidences acceptance. Please contact us if you have questions or concerns about the Privacy Notice or any objection to any revisions.

Last Update: November 17, 2020