You set up packet filtering by using packet filtering rule sets. Use the ipf command to work with packet filtering rule sets. For more information on the ipf command, see the ipf(1M) command.
You can create packet filtering rules either at the command line, using the ipf command, or in a packet filtering configuration file. To load the configuration file, you must create the file, then provide its pathname to the IP Filter service.
You can maintain two sets of packet filtering rule sets with IP Filter, the active rule set and the inactive rule set. In most cases, you work with the active rule set. However, the ipf -I command enables you to apply the command action to the inactive rule list. The inactive rule list is not used by IP Filter unless you select it. The inactive rule list provides you with a place to store rules without affecting active packet filtering.
IP Filter processes the rules in the rules list from the beginning of the configured rules list to the end of the rules list before passing or blocking a packet. IP Filter maintains a flag that determines whether it will or will not pass a packet. It goes through the entire rule set and determines whether to pass or block the packet based on the last matching rule.
There are two exceptions to this process. The first exception is if the packet matches a rule containing the quick keyword. If a rule includes the quick keyword, the action for that rule is taken, and no subsequent rules are checked. The second exception is if the packet matches a rule containing the group keyword. If a packet matches a group, only rules tagged with the group are checked.
Use the following syntax to create packet filtering rules:
action [in|out] option keyword, keyword...
Each rule begins with an action. IP Filter applies the action to the packet if the packet matches the rule. The following list includes the commonly used actions applied to a packet.
Prevents the packet from passing through the filter.
Allows the packet through the filter.
Logs the packet but does not determine if the packet is blocked or passed. Use the ipmon command to view the log.
Includes the packet in the filter statistics. Use the ipfstat command to view the statistics.
Makes the filter skip over number filtering rules.
Requests that packet authentication be performed by a user program that validates packet information. The program determines whether the packet is passed or blocked.
Following the action, the next word must be either in or out. Your choice determines whether the packet filtering rule is applied to an incoming packet or to an outgoing packet.
Next, you can choose from a list of options. If you use more than one option, they must be in the order shown here.
Logs the packet if the rule is the last matching rule. Use the ipmon command to view the log.
Executes the rule containing the quick option if there is a packet match. All further rule checking stops.
Applies the rule only if the packet is moving in or out of the specified interface.
Copies the packet and sends the duplicate out on interface-name to an optionally specified IP address.
Moves the packet to an outbound queue on interface-name.
After specifying the options, you can choose from a variety of keywords that determine whether the packet matches the rule. The following keywords must be used in the order shown here.
Filters the packet based on the type-of-service value expressed as either a hexadecimal or a decimal integer.
Matches the packet based on its time-to-live value. The time-to-live value stored in a packet indicates the length of time a packet can be on the network before being discarded.
Matches a specific protocol. You can use any of the protocol names specified in the /etc/protocols file, or use a decimal number to represent the protocol. The keyword tcp/udp can be used to match either a TCP or a UDP packet.
Matches any or all of the following: the source IP address, the destination IP address, and the port number. The all keyword is used to accept packets from all sources and to all destinations.
Matches specified attributes associated with the packet. Insert either the word not or the word no in front of the keyword in order to match the packet only if the option is not present.
Used for TCP to filter based on TCP flags that are set. For more information on the TCP flags, see the ipf(4) man page.
Filters according to ICMP type. This keyword is used only when the proto option is set to icmp and is not used if the flags option is used.
Determines the information that is kept for a packet. The keep-options that are available include the state option. The state option keeps information about the session and can be kept for TCP, UDP, and ICMP packets.
Creates a new group for filtering rules, which is denoted by the number number.
Adds the rule to group number number instead of the default group. All filtering rules are placed in group 0 if no other group is specified.
The following example illustrates how to put together the packet filtering rule syntax to create a rule. To block incoming traffic from the IP address 192.168.0.0/16, you would include the following rule in the rule list:
block in quick from 192.168.0.0/16 to any
For the complete grammar and syntax used to write packet filtering rules, see the ipf(4) man page. For tasks associated with packet filtering, see Managing Packet Filtering Rule Sets for IP Filter. For an explanation of the IP address scheme (192.168.0.0/16) shown in the example, see Chapter 1, Planning For Network Deployment, in Planning for Network Deployment in Oracle Solaris 11.2 .