Technical Tip: Firewall policy lookups
Description
This article provides a sample of firewall policy lookups.
Scope
FortiGate.
Solution
Policy lookups:
Firewall policy lookup is based on the Source_interfaces/Protocol/Source_Address/Destination_Address that matches the source-port and dst-port of the protocol.
Use this tool to find out which policy matches specific traffic from several policies. After completing the lookup, the matching firewall policy is highlighted on the policy list page.
Policy matching is performed based on the traffic parameters, including the source interface, source and destination IP addresses, protocol, and destination port. Ensure that these parameters accurately represent the traffic being tested.
The source interface must be the actual incoming interface through which the traffic enters the FortiGate. Selecting an incorrect interface may result in an inaccurate policy match.
Policy matching does not generate traffic or verify whether the destination server is reachable. It only identifies the firewall policy that would be evaluated for the specified traffic.
If the lookup returns policy ID 0, the traffic does not match an applicable firewall policy and may be denied by the implicit deny policy.
When multiple firewall policies contain overlapping source, destination, service, and interface conditions, the policy lookup helps identify the policy that matches the specified traffic parameters.
For traffic using a VIP or DNAT, consider the destination address and interface involved in the policy evaluation. The policy match result may differ from the original destination IP entered by the client.
For troubleshooting policy matching issues, verify the routing table, firewall policy configuration, address objects, service definitions, schedules, and relevant security policy settings.
When troubleshooting identity-based policies, ensure that the authenticated username or user group is correctly specified where supported by the Policy Match tool or CLI.
For traffic traversing a VDOM, ensure that the lookup is performed in the correct VDOM and that the selected source interface belongs to the relevant routing context.
The policy match tool can assist in identifying the matching policy, but it does not replace packet flow debugging when investigating issues such as asymmetric routing, session problems, NAT behavior, or packet drops.
If the expected policy is not identified, compare the lookup parameters with the actual traffic details collected through packet captures, traffic logs, or flow debugging.
Policy matching should be performed using the same protocol and destination port used by the application. For example, TCP/443 and UDP/443 are different traffic types and may match different policies.
The Policy Lookup tool has the following requirements:
When executing the policy lookup, it is necessary to confirm whether the relevant route required for the policy to work already exists.
Source Interface or Incoming Interface is a mandatory field to find out the correct source interface. Use the following command:
get router info routing-table details <source IP>Â
Â
Example:
Â
FortiGate# get router info routing-table details 192.168.10.2
Routing table for VRF=0
Routing entry for 192.168.10.0/24
Known via "connected", distance 0, metric 0, best
* is directly connected, port5 <-- Source Interface.Â
Sample configuration:
This example uses the TCP protocol to show how policy lookup works:
In the Policy & Objects policy list page, select 'Policy Lookup' and enter the traffic parameters.

Â
Select 'Search' to display the policy lookup results.
 Â

Â
For the SSL VPN, it is possible to follow the same steps; just pay attention to the fact that in the source interface, it is necessary to select the SSL VPN interface, and in the source, the IP addresses of users who are currently online (Authenticated).
Â
In the example below, the IP 10.200.1.2 is from an SSL VPN user who is connected to the VPN.
Â

Note:Â From version 7.4, the option has changed to 'policy match'.

Alternatively, use the following command to trace specific traffic on which firewall policy it will match:
Â
diagnose firewall iprope lookup <src_ip> <src_port> <dst_ip> <dst_port> <protocol> <Source interface>Â
Example:
diagnose firewall iprope lookup 10.187.1.100 12345 8.8.8.8 53 udp port2
<src [10.187.1.100-12345] dst [8.8.8.8-53] proto udp dev port2> matches policy id: 0
diagnose firewall iprope lookup 10.187.1.100 12345 8.8.8.8 53 tcp port2
<src [10.187.1.100-12345] dst [8.8.8.8-53] proto tcp dev port2> matches policy id: 2Â
The above commands can also be run using the protocol number assigned by IANA.
Â
diagnose firewall iprope lookup 10.187.1.100 12345 8.8.8.8 53 17 port2
<src [10.187.1.100-12345] dst [8.8.8.8-53] proto udp dev port2> matches policy id: 0
Â
diagnose firewall iprope lookup 10.187.1.100 12345 8.8.8.8 53 6 port2
<src [10.187.1.100-12345] dst [8.8.8.8-53] proto tcp dev port2> matches policy id: 2Â
The diagnose firewall iprope lookup command has been updated to specify additional parameters, including policy type (policy or proxy), and a new parameter for identity-based policy matching.
The policy match feature will be activated if more than six parameters are specified in the existing diagnose command:
Â
diagnose firewall iprope lookup <source_ip> <source_port> <destination_ip> <destination_port> <protocol> <device> <policy_type> [<auth_type>] [<user/group>] [<server>]Note: On entry-level FortiGates, the Policy lookup tool is renamed to Policy match. The web filter action tracing and user matching functionalities are not available, and the diagnose firewall iprope lookup can only be used for basic policy lookups.
Â
On firmware versions that do not support the extended syntax above, 'diagnose firewall iprope lookup' may not match firewall policies where authentication is enabled, because the user/group cannot be specified.
Also, when using diagnose firewall iprope lookup, ensure that the appropriate VRF (Virtual Routing and Forwarding)Â is selected if multiple virtual routing tables are in use, as the lookup may yield incorrect results if the traffic is routed via a different VRF.
Â
In multi-VDOM mode, run the lookup inside the relevant VDOM:
config vdom
edit <vdom_name>
diagnose firewall iprope lookup <src_ip> <src_port> <dst_ip> <dst_port> <protocol> <source_interface>
To confirm which policy real traffic actually hits, run a debug flow while generating the traffic:
diagnose debug flow filter saddr <src_ip>
diagnose debug flow filter daddr <dst_ip>
diagnose debug flow trace start 10
diagnose debug enable
Check the policy ID in the 'Allowed by Policy-X' or 'Denied by forward policy check (policy X)' line, and compare it with the lookup result.
Policy match tool in the GUI:Â Update policy lookup tool with policy match tool v7.4.1.
Â
The protocol number list can be found in the following document:
