Help us improve your experience.

Let us know what you think.

Do you have time for a two-minute survey?

Navigation

Example: Configuring a Filter to Count and Sample Accepted Packets

This example shows how to configure a standard stateless firewall filter to count and sample accepted packets.

Requirements

No special configuration beyond device initialization is required before configuring this example.

Before you begin, configure traffic sampling by including the sampling statement at the [edit forwarding-options] hierarchy level.

Overview

In this example, you use a standard stateless firewall filter to count and sample all packets received on a logical interface.

Note: When you enable reverse path forwarding (RPF) on an interface with an input filter for firewall log and count, the input firewall filter does not log the packets rejected by RPF, although the rejected packets are counted. To log the rejected packets, use an RPF check fail filter.

Configuration

The following example requires you to navigate various levels in the configuration hierarchy. For information about navigating the CLI, see Using the CLI Editor in Configuration Mode.

To configure this example, perform the following tasks:

CLI Quick Configuration

To quickly configure this example, copy the following configuration commands into a text file, remove any line breaks, and then paste the commands into the CLI at the [edit] hierarchy level.

set firewall family inet filter sam term all then count count_samset firewall family inet filter sam term all then sampleset interfaces at-2/0/0 unit 301 family inet address 10.1.2.3/30set interfaces at-2/0/0 unit 301 family inet filter input sam

Configure the Stateless Firewall Filter

Step-by-Step Procedure

To configure the stateless firewall filter sam:

  1. Create the stateless firewall filter sam.

    [edit]user@host# edit firewall family inet filter sam
  2. Configure the term to count and sample all packets.

    [edit firewall family inet filter sam]user@host# set term all then count count_samuser@host# set term all then sample

Apply the Stateless Firewall Filter to a Logical Interface

Step-by-Step Procedure

To apply the stateless firewall filter to a logical interface:

  1. Configure the logical interface to which you will apply the stateless firewall filter.

    [edit]user@host# edit interfaces ge-0/0/1 unit 0 family inet
  2. Configure the interface address for the logical interface.

    [edit interfaces ge-0/0/1 unit 0 family inet]user@host# set address 10.1.2.3/30
  3. Apply the stateless firewall filter to the logical interface.

    [edit interfaces ge-0/0/1 unit 0 family inet]user@host# set filter input sam

    Note: The Junos OS does not sample packets originating from the router or switch. If you configure a filter and apply it to the output side of an interface, then only the transit packets going through that interface are sampled. Packets that are sent from the Routing Engine to the Packet Forwarding Engine are not sampled.

Confirm and Commit Your Candidate Configuration

Step-by-Step Procedure

To confirm and then commit your candidate configuration:

  1. Confirm the configuration of the stateless firewall filter by entering the show firewall configuration mode command. If the command output does not display the intended configuration, repeat the instructions in this example to correct the configuration.

    [edit]user@host# show firewall
    family inet {filter sam {term all {then {count count_sam;sample; # default action is accept}}}}
  2. Confirm the configuration of the interface by entering the show interfaces configuration mode command. If the command output does not display the intended configuration, repeat the instructions in this example to correct the configuration.

    [edit]user@host# show interfaces
    interfaces {at-2/0/0 {unit 301 {family inet {filter {input sam;}address 10.1.2.3/30;}}}}
  3. If you are done configuring the device, commit your candidate configuration.

    [edit]user@host# commit

Verification

Confirm that the configuration is working properly.

Displaying the Packet Counter

Purpose

Verify that the firewall filter is evaluating packets.

Action

user@host> show firewall filter sam
Filter:
Counters:
Name              Bytes                Packets
sam
sam-1             98                   8028

Displaying the Firewall Filter Log Output

Purpose

Display the packet header information for all packets evaluated by the firewall filter.

Action

user@host> show firewall log
Time     Filter     A Interface        Pro Source address  Destination address
23:09:09 -          A at-2/0/0.301     TCP 10.2.0.25       10.211.211.1:80
23:09:07 -          A at-2/0/0.301     TCP 10.2.0.25       10.211.211.1:56
23:09:07 -          A at-2/0/0.301     ICM 10.2.0.25       10.211.211.1:49552
23:02:27 -          A at-2/0/0.301     TCP 10.2.0.25       10.211.211.1:56
23:02:25 -          A at-2/0/0.301     TCP 10.2.0.25       10.211.211.1:80
23:01:22 -          A at-2/0/0.301     ICM 10.2.2.101      10.211.211.1:23251
23:01:21 -          A at-2/0/0.301     ICM 10.2.2.101      10.211.211.1:16557
23:01:20 -          A at-2/0/0.301     ICM 10.2.2.101      10.211.211.1:29471
23:01:19 -          A at-2/0/0.301     ICM 10.2.2.101      10.211.211.1:26873

Meaning

This output file contains the following fields:

  • Time—Time at which the packet was received (not shown in the default).
  • Filter—Name of a filter that has been configured with the filter statement at the [edit firewall] hierarchy level. A hyphen (-) or the abbreviation pfe indicates that the packet was handled by the Packet Forwarding Engine. A space (no hyphen) indicates that the packet was handled by the Routing Engine.
  • A—Filter action:
    • A—Accept (or next term)
    • D—Discard
    • R—Reject
  • Interface—Interface on which the filter is configured.

    Note: We strongly recommend that you always explicitly configure an action in the then statement.

  • Pro—Packet’s protocol name or number.
  • Source address—Source IP address in the packet.
  • Destination address—Destination IP address in the packet.

Displaying the Sampling Output

Purpose

Verify that the sampling output contains appropriate data.

Action

  wtmp.0.gz            Size: 15017, Last changed: Dec 19 13:15:54 wtmp.1.gz            Size: 493, Last changed: Nov 19 13:47:29
  wtmp.2.gz            Size: 57, Last changed: Oct 20 15:24:34
  |                    Pipe through a command
user@host> show log /var/tmp/sam
# Apr  7 15:48:50
Time                    Dest           Src Dest Src Proto TOS Pkt Intf  IP   TCP
addr addr port port len num frag flags Apr 7 15:48:54 192.168.9.194 192.168.9.195 0 0 1 0x0 84 8 0x0 0x0 Apr 7 15:48:55 192.168.9.194 192.168.9.195 0 0 1 0x0 84 8 0x0 0x0 Apr 7 15:48:56 192.168.9.194 192.168.9.195 0 0 1 0x0 84 8 0x0 0x0

Published: 2013-04-10