Help us improve your experience.

Let us know what you think.

Do you have time for a two-minute survey?

Announcement: Try the Ask AI chatbot for answers to your technical questions about Juniper products and solutions.

close
header-navigation
keyboard_arrow_up
close
keyboard_arrow_left
list Table of Contents
file_download PDF
{ "lLangCode": "en", "lName": "English", "lCountryCode": "us", "transcode": "en_US" }
English
keyboard_arrow_right

Example: Configuring Filter-Based Forwarding on Logical Systems

date_range 24-Nov-23

This example shows how to configure filter-based forwarding within a logical system. The filter classifies packets to determine their forwarding path within the ingress routing device.

Requirements

In this example, no special configuration beyond device initialization is required.

Overview

Filter-based forwarding is supported for IP version 4 (IPv4) and IP version 6 (IPv6).

Use filter-based forwarding for service provider selection when customers have Internet connectivity provided by different ISPs yet share a common access layer. When a shared media (such as a cable modem) is used, a mechanism on the common access layer looks at Layer 2 or Layer 3 addresses and distinguishes between customers. You can use filter-based forwarding when the common access layer is implemented using a combination of Layer 2 switches and a single router.

With filter-based forwarding, all packets received on an interface are considered. Each packet passes through a filter that has match conditions. If the match conditions are met for a filter and you have created a routing instance, filter-based forwarding is applied to a packet. The packet is forwarded based on the next hop specified in the routing instance. For static routes, the next hop can be a specific LSP.

Note:

Source-class usage filter matching and unicast reverse-path forwarding checks are not supported on an interface configured with filter-based forwarding (FBF).

To configure filter-based forwarding, perform the following tasks:

  • Create a match filter on an ingress router or switch. To specify a match filter, include the filter filter-name statement at the [edit firewall] hierarchy level. A packet that passes through the filter is compared against a set of rules to classify it and to determine its membership in a set. Once classified, the packet is forwarded to a routing table specified in the accept action in the filter description language. The routing table then forwards the packet to the next hop that corresponds to the destination address entry in the table.

  • Create routing instances that specify the routing table(s) to which a packet is forwarded, and the destination to which the packet is forwarded at the [edit routing-instances] or [edit logical-systems logical-system-name routing-instances] hierarchy level. For example:

    content_copy zoom_out_map
    [edit]
    routing-instances {
        routing-table-name1 {
            instance-type forwarding;
            routing-options {
                static {
                    route 0.0.0.0/0 nexthop 10.0.0.1;
                }
            }
        }
        routing-table-name2 {
            instance-type forwarding;
            routing-options {
                static {
                    route 0.0.0.0/0 nexthop 10.0.0.2;
                }
            }
        }
    }
    
  • Create a routing table group that adds interface routes to the forwarding routing instances used in filter-based forwarding (FBF), as well as to the default routing instance inet.0. This part of the configuration resolves the routes installed in the routing instances to directly connected next hops on that interface. Create the routing table group at the [edit routing-options] or [edit logical-systems logical-system-name routing-options] hierarchy level.

Note:

Specify inet.0 as one of the routing instances that the interface routes are imported into. If the default instance inet.0 is not specified, interface routes are not imported into the default routing instance.

This example shows a packet filter that directs customer traffic to a next-hop router in the domains, SP 1 or SP 2, based on the packet’s source address.

If the packet has a source address assigned to an SP 1 customer, destination-based forwarding occurs using the sp1-route-table.inet.0 routing table. If the packet has a source address assigned to an SP 2 customer, destination-based forwarding occurs using the sp2-route-table.inet.0 routing table. If a packet does not match either of these conditions, the filter accepts the packet, and destination-based forwarding occurs using the standard inet.0 routing table.

One way to make filter-based forwarding work within a logical system is to configure the firewall filter on the logical system that receives the packets. Another way is to configure the firewall filter on the main router and then reference the logical system in the firewall filter. This example uses the second approach. The specific routing instances are configured within the logical system. Because each routing instance has its own routing table, you have to reference the routing instances in the firewall filter, as well. The syntax looks as follows:

content_copy zoom_out_map
[edit firewall filter filter-name term term-name]
user@host# set then logical-system logical-system-name routing-instance routing-instance-name

Topology

Figure 1 shows the topology used in this example.

On Logical System P1, an input filter classifies packets received from Logical System PE3 and Logical System PE4. The packets are routed based on the source addresses. Packets with source addresses in the 10.1.1.0/24 and 10.1.2.0/24 networks are routed to Logical System PE1. Packets with source addresses in the 10.2.1.0/24 and 10.2.2.0/24 networks are routed to Logical System PE2.

Figure 1: Logical Systems with Filter-Based ForwardingLogical Systems with Filter-Based Forwarding

To establish connectivity, OSPF is configured on all of the interfaces. For demonstration purposes, loopback interface addresses are configured on the routing devices to represent networks in the clouds.

The CLI Quick Configuration section shows the entire configuration for all of the devices in the topology. The Configuring the Routing Instances on the Logical System P1 and Configuring the Firewall Filter on the Main Router sections shows the step-by-step configuration of the ingress routing device, Logical System P1.

Configuration

CLI Quick Configuration

To quickly configure this example, copy the following commands, paste them into a text file, remove any line breaks, change any details necessary to match your network configuration, and then copy and paste the commands into the CLI at the [edit] hierarchy level.

content_copy zoom_out_map
set firewall filter classify-customers term sp1-customers from source-address 10.1.1.0/24
set firewall filter classify-customers term sp1-customers from source-address 10.1.2.0/24
set firewall filter classify-customers term sp1-customers then log
set firewall filter classify-customers term sp1-customers then logical-system P1 routing-instance sp1-route-table
set firewall filter classify-customers term sp2-customers from source-address 10.2.1.0/24
set firewall filter classify-customers term sp2-customers from source-address 10.2.2.0/24
set firewall filter classify-customers term sp2-customers then log
set firewall filter classify-customers term sp2-customers then logical-system P1 routing-instance sp2-route-table
set firewall filter classify-customers term default then accept
set logical-systems P1 interfaces lt-1/2/0 unit 10 encapsulation ethernet
set logical-systems P1 interfaces lt-1/2/0 unit 10 peer-unit 9
set logical-systems P1 interfaces lt-1/2/0 unit 10 family inet filter input classify-customers
set logical-systems P1 interfaces lt-1/2/0 unit 10 family inet address 172.16.0.10/30
set logical-systems P1 interfaces lt-1/2/0 unit 13 encapsulation ethernet
set logical-systems P1 interfaces lt-1/2/0 unit 13 peer-unit 14
set logical-systems P1 interfaces lt-1/2/0 unit 13 family inet address 172.16.0.13/30
set logical-systems P1 interfaces lt-1/2/0 unit 17 encapsulation ethernet
set logical-systems P1 interfaces lt-1/2/0 unit 17 peer-unit 18
set logical-systems P1 interfaces lt-1/2/0 unit 17 family inet address 172.16.0.17/30
set logical-systems P1 protocols ospf rib-group fbf-group
set logical-systems P1 protocols ospf area 0.0.0.0 interface all
set logical-systems P1 protocols ospf area 0.0.0.0 interface fxp0.0 disable
set logical-systems P1 routing-instances sp1-route-table instance-type forwarding
set logical-systems P1 routing-instances sp1-route-table routing-options static route 0.0.0.0/0 next-hop 172.16.0.13
set logical-systems P1 routing-instances sp2-route-table instance-type forwarding
set logical-systems P1 routing-instances sp2-route-table routing-options static route 0.0.0.0/0 next-hop 172.16.0.17
set logical-systems P1 routing-options rib-groups fbf-group import-rib inet.0
set logical-systems P1 routing-options rib-groups fbf-group import-rib sp1-route-table.inet.0
set logical-systems P1 routing-options rib-groups fbf-group import-rib sp2-route-table.inet.0
set logical-systems P2 interfaces lt-1/2/0 unit 2 encapsulation ethernet
set logical-systems P2 interfaces lt-1/2/0 unit 2 peer-unit 1
set logical-systems P2 interfaces lt-1/2/0 unit 2 family inet address 172.16.0.2/30
set logical-systems P2 interfaces lt-1/2/0 unit 6 encapsulation ethernet
set logical-systems P2 interfaces lt-1/2/0 unit 6 peer-unit 5
set logical-systems P2 interfaces lt-1/2/0 unit 6 family inet address 172.16.0.6/30
set logical-systems P2 interfaces lt-1/2/0 unit 9 encapsulation ethernet
set logical-systems P2 interfaces lt-1/2/0 unit 9 peer-unit 10
set logical-systems P2 interfaces lt-1/2/0 unit 9 family inet address 172.16.0.9/30
set logical-systems P2 protocols ospf area 0.0.0.0 interface all
set logical-systems P2 protocols ospf area 0.0.0.0 interface fxp0.0 disable
set logical-systems PE1 interfaces lt-1/2/0 unit 14 encapsulation ethernet
set logical-systems PE1 interfaces lt-1/2/0 unit 14 peer-unit 13
set logical-systems PE1 interfaces lt-1/2/0 unit 14 family inet address 172.16.0.14/30
set logical-systems PE1 interfaces lo0 unit 3 family inet address 172.16.1.1/32
set logical-systems PE1 protocols ospf area 0.0.0.0 interface all
set logical-systems PE1 protocols ospf area 0.0.0.0 interface fxp0.0 disable
set logical-systems PE2 interfaces lt-1/2/0 unit 18 encapsulation ethernet
set logical-systems PE2 interfaces lt-1/2/0 unit 18 peer-unit 17
set logical-systems PE2 interfaces lt-1/2/0 unit 18 family inet address 172.16.0.18/30
set logical-systems PE2 interfaces lo0 unit 4 family inet address 172.16.2.2/32
set logical-systems PE2 protocols ospf area 0.0.0.0 interface all
set logical-systems PE2 protocols ospf area 0.0.0.0 interface fxp0.0 disable
set logical-systems PE3 interfaces lt-1/2/0 unit 1 encapsulation ethernet
set logical-systems PE3 interfaces lt-1/2/0 unit 1 peer-unit 2
set logical-systems PE3 interfaces lt-1/2/0 unit 1 family inet address 172.16.0.1/30
set logical-systems PE3 interfaces lo0 unit 1 family inet address 10.1.1.1/32
set logical-systems PE3 interfaces lo0 unit 1 family inet address 10.1.2.1/32
set logical-systems PE3 protocols ospf area 0.0.0.0 interface all
set logical-systems PE3 protocols ospf area 0.0.0.0 interface fxp0.0 disable
set logical-systems PE4 interfaces lt-1/2/0 unit 5 encapsulation ethernet
set logical-systems PE4 interfaces lt-1/2/0 unit 5 peer-unit 6
set logical-systems PE4 interfaces lt-1/2/0 unit 5 family inet address 172.16.0.5/30
set logical-systems PE4 interfaces lo0 unit 2 family inet address 10.2.1.1/32
set logical-systems PE4 interfaces lo0 unit 2 family inet address 10.2.2.1/32
set logical-systems PE4 protocols ospf area 0.0.0.0 interface all
set logical-systems PE4 protocols ospf area 0.0.0.0 interface fxp0.0 disable

Configuring the Firewall Filter on the Main Router

Step-by-Step Procedure

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 in the CLI User Guide.

To configure the firewall filter on the main router:

  1. Configure the source addresses for SP1 customers.

    content_copy zoom_out_map
    [edit firewall filter classify-customers term sp1-customers]
    user@host# set from source-address 10.1.1.0/24
    user@host# set from source-address 10.1.2.0/24
    
  2. Configure the actions that are taken when packets are received with the specified source addresses.

    To track the action of the firewall filter, a log action is configured. The sp1-route-table.inet.0 routing table on Logical System P1 routes the packets.

    content_copy zoom_out_map
    [edit firewall filter classify-customers term sp1-customers]
    user@host# set then log
    user@host# set then logical-system P1 routing-instance sp1-route-table
    
  3. Configure the source addresses for SP2 customers.

    content_copy zoom_out_map
    [edit firewall filter classify-customers term sp2-customers]
    user@host# set from source-address 10.2.1.0/24
    user@host# set from source-address 10.2.2.0/24
    
  4. Configure the actions that are taken when packets are received with the specified source addresses.

    To track the action of the firewall filter, a log action is configured. The sp2-route-table.inet.0 routing table on Logical System P1 routes the packet.

    content_copy zoom_out_map
    [edit firewall filter classify-customers term sp2-customers]
    user@host# set then log
    user@host# set then logical-system P1 routing-instance sp2-route-table
    
  5. Configure the action to take when packets are received from any other source address.

    All of these packets are simply accepted and routed using the default IPv4 unicast routing table, inet.0.

    content_copy zoom_out_map
    [edit firewall filter classify-customers term default]
    user@host# set then accept
    

Configuring the Routing Instances on the Logical System P1

Step-by-Step Procedure

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 in the CLI User Guide.

To configure the routing instances on a logical system:

  1. Configure the interfaces on the logical system.

    content_copy zoom_out_map
    [edit logical-systems P1 interfaces lt-1/2/0]
    user@host# set unit 10 encapsulation ethernet
    user@host# set unit 10 peer-unit 9
    user@host# set unit 10 family inet address 172.16.0.10/30
    user@host# set unit 13 encapsulation ethernet
    user@host# set unit 13 peer-unit 14
    user@host# set unit 13 family inet address 172.16.0.13/30
    user@host# set unit 17 encapsulation ethernet
    user@host# set unit 17 peer-unit 18
    user@host# set unit 17 family inet address 172.16.0.17/30
    
  2. Assign the classify-customers firewall filter to router interface lt-1/2/0.10 as an input packet filter.

    content_copy zoom_out_map
    [edit logical-systems P1 interfaces lt-1/2/0]
    user@host# set unit 10 family inet filter input classify-customers
    
  3. Configure connectivity, using either a routing protocol or static routing.

    As a best practice, disable routing on the management interface.

    content_copy zoom_out_map
    [edit  logical-systems P1 protocols ospf area 0.0.0.0]
    user@host# set interface all
    user@host# set interface fxp0.0 disable
    
  4. Create the routing instances.

    These routing instances are referenced in the classify-customers firewall filter.

    The forwarding instance type provides support for filter-based forwarding, where interfaces are not associated with instances. All interfaces belong to the default instance, in this case Logical System P1.

    content_copy zoom_out_map
    [edit logical-systems P1 routing-instances]
    user@host# set sp1-route-table instance-type forwarding
    user@host# set sp2-route-table instance-type forwarding
    
  5. Resolve the routes installed in the routing instances to directly connected next hops.

    content_copy zoom_out_map
    [edit logical-systems P1 routing-instances]
    user@host# set sp1-route-table routing-options static route 0.0.0.0/0 next-hop 172.16.0.13
    user@host# set sp2-route-table routing-options static route 0.0.0.0/0 next-hop 172.16.0.17
    
  6. Group together the routing tables to form a routing table group.

    The first routing table, inet.0, is the primary routing table, and the additional routing tables are the secondary routing tables.

    The primary routing table determines the address family of the routing table group, in this case IPv4.

    content_copy zoom_out_map
    [edit logical-systems P1 routing-options]
    user@host# set rib-groups fbf-group import-rib inet.0
    user@host# set rib-groups fbf-group import-rib sp1-route-table.inet.0
    user@host# set rib-groups fbf-group import-rib sp2-route-table.inet.0
    
  7. Apply the routing table group to OSPF.

    This causes the OSPF routes to be installed into all the routing tables in the group.

    content_copy zoom_out_map
    [edit logical-systems P1 protocols ospf]
    user@host# set rib-group fbf-group
    
  8. If you are done configuring the device, commit the configuration.

    content_copy zoom_out_map
    [edit]
    user@host# commit
    

Results

Confirm your configuration by issuing the show firewall and show logical-systems P1 commands.

content_copy zoom_out_map
user@host# show firewall
filter classify-customers {
    term sp1-customers {
        from {
            source-address {
                10.1.1.0/24;
                10.1.2.0/24;
            }
        }
        then {
            log;
            logical-system P1 routing-instance sp1-route-table;
        }
    }
    term sp2-customers {
        from {
            source-address {
                10.2.1.0/24;
                10.2.2.0/24;
            }
        }
        then {
            log;
            logical-system P1 routing-instance sp2-route-table;
        }
    }
    term default {
        then accept;
    }
}
content_copy zoom_out_map
user@host# show logical-systems P1
interfaces {
    lt-1/2/0 {
        unit 10 {
            encapsulation ethernet;
            peer-unit 9;
            family inet {
                filter {
                    input classify-customers;
                }
                address 172.16.0.10/30;
            }
        }
        unit 13 {
            encapsulation ethernet;
            peer-unit 14;
            family inet {
                address 172.16.0.13/30;
            }
        }
        unit 17 {
            encapsulation ethernet;
            peer-unit 18;
            family inet {
                address 172.16.0.17/30;
            }
        }
    }
}
protocols {
    ospf {
        rib-group fbf-group;
        area 0.0.0.0 {
            interface all;
            interface fxp0.0 {
                disable;
            }
        }
    }
}
routing-instances {
    sp1-route-table {
        instance-type forwarding;
        routing-options {
            static {
                route 0.0.0.0/0 next-hop 172.16.0.13;
            }
        }
    }
    sp2-route-table {
        instance-type forwarding;
        routing-options {
            static {
                route 0.0.0.0/0 next-hop 172.16.0.17;
            }
        }
    }
}
routing-options {
    rib-groups {
        fbf-group {
            import-rib [ inet.0 sp1-route-table.inet.0 sp2-route-table.inet.0 ];
        }
    }
}

Verification

Confirm that the configuration is working properly.

Pinging with Specified Source Addresses

Purpose

Send some ICMP packets across the network to test the firewall filter.

Action

  1. Log in to Logical System PE3.

    content_copy zoom_out_map
    user@host> set cli logical-system PE3
    Logical system: PE3
  2. Run the ping command, pinging the lo0.3 interface on Logical System PE1.

    The address configured on this interface is 172.16.1.1.

    Specify the source address 10.1.2.1, which is the address configured on the lo0.1 interface on Logical System PE3.

    content_copy zoom_out_map
    user@host:PE3> ping 172.16.1.1 source 10.1.2.1
    PING 172.16.1.1 (172.16.1.1): 56 data bytes
    64 bytes from 172.16.1.1: icmp_seq=0 ttl=62 time=1.444 ms
    64 bytes from 172.16.1.1: icmp_seq=1 ttl=62 time=2.094 ms
    ^C
    --- 172.16.1.1 ping statistics ---
    2 packets transmitted, 2 packets received, 0% packet loss
    round-trip min/avg/max/stddev = 1.444/1.769/2.094/0.325 ms
  3. Log in to Logical System PE4.

    content_copy zoom_out_map
    user@host:PE3> set cli logical-system PE4
    Logical system: PE4
  4. Run the ping command, pinging the lo0.4 interface on Logical System PE2.

    The address configured on this interface is 172.16.2.2.

    Specify the source address 10.2.1.1, which is the address configured on the lo0.2 interface on Logical System PE4.

    content_copy zoom_out_map
    user@host:PE4> ping 172.16.2.2 source 10.2.1.1
    PING 172.16.2.2 (172.16.2.2): 56 data bytes
    64 bytes from 172.16.2.2: icmp_seq=0 ttl=62 time=1.473 ms
    64 bytes from 172.16.2.2: icmp_seq=1 ttl=62 time=1.407 ms
    ^C
    --- 172.16.2.2 ping statistics ---
    2 packets transmitted, 2 packets received, 0% packet loss
    round-trip min/avg/max/stddev = 1.407/1.440/1.473/0.033 ms

Meaning

Sending these pings activates the firewall filter actions.

Verifying the Firewall Filter

Purpose

Make sure the firewall filter actions take effect.

Action

  1. Log in to Logical System P1.

    content_copy zoom_out_map
    user@host> set cli logical-system P1
    Logical system: P1
  2. Run the show firewall log command on Logical System P1.

    content_copy zoom_out_map
    user@host:P1> show firewall log
    Log :
    Time      Filter    Action Interface     Protocol        Src Addr            Dest Addr
    13:52:20  pfe       A      lt-1/2/0.10   ICMP            10.2.1.1            172.16.2.2
    13:52:19  pfe       A      lt-1/2/0.10   ICMP            10.2.1.1            172.16.2.2
    13:51:53  pfe       A      lt-1/2/0.10   ICMP            10.1.2.1            172.16.1.1
    13:51:52  pfe       A      lt-1/2/0.10   ICMP            10.1.2.1            172.16.1.1
footer-navigation