Monitoring and Troubleshooting · Topic 1 of 3

Troubleshooting Security Policies

Learn to troubleshoot SRX security policies for JNCIA-SEC: policy order, shadowing, show security match-policies, hit counts and policy logging.

  • 6 min
In a nutshell
  • Policy lookup: zone pair policies top to bottom, then global policies, then the default policy (deny-all).
  • First match wins; source, destination and application must all match.
  • The to-zone comes from the route lookup on the destination after destination or static NAT.

What it is

Troubleshooting security policies means finding out which policy, if any, handles a given flow and why. Most "the firewall is blocking it" problems come down to a short list: the traffic arrives in a different zone than expected, a policy above the intended one matches first, an address or application does not match, or nothing matches and the default policy denies the traffic.

Junos OS has commands that answer these questions directly.

Trafficfrom zone to zoneZone pair policiestop to bottomno matchGlobal policiesno matchDefault policydeny all

How it works

How the SRX picks a policy

  1. The from-zone is the zone of the ingress interface.
  2. The to-zone comes from the route lookup on the destination address, after any destination or static NAT.
  3. Policies for that zone pair are checked top to bottom, and the first match wins.
  4. If none match, global policies are checked, in order.
  5. If still nothing matches, the default policy applies. Its default is deny-all.

A policy matches only when the source address, destination address and application all match. Every policy has a terminal action, permit, deny or reject, so later policies are never reached once one matches.

Listing policies

Command (operational mode)Shows
show security policiesAll policies, in order, with their index and sequence number
show security policies from-zone trust to-zone untrustPolicies for one zone pair
show security policies policy-name WEB-OUT detailFull detail of one policy, including addresses, applications and actions
show security policies hit-countHow many times each policy has matched
show security shadow-policies from-zone trust to-zone untrustPolicies that can never match because an earlier policy covers them

clear security policies hit-count resets the counters before a test.

Asking the SRX which policy matches

show security match-policies runs the policy lookup for a flow you describe, without any traffic.

user@srx> show security match-policies from-zone trust to-zone untrust source-ip 10.1.1.10 destination-ip 198.51.100.20 source-port 51544 destination-port 80 protocol tcp
Policy: DENY-SERVERS, action-type: deny, State: enabled, Index: 7
  Policy Type: Configured
  Sequence number: 1
  From zone: trust, To zone: untrust
  Source addresses: SERVER-NET
  Destination addresses: any
  Applications: any

The output names the policy that would match first. In this example the host hits DENY-SERVERS before the intended permit policy, so the fix is the policy order, not the policy content.

Exam tip

show security match-policies is the fastest way to answer "which policy handles this flow?" It needs the zones, both addresses, both ports and the protocol, and it works for traffic that has never been sent.

Fixing the order

New policies are added at the bottom of their zone pair. Move one with insert in configuration mode.

user@srx# insert security policies from-zone trust to-zone untrust policy WEB-OUT before policy DENY-SERVERS
user@srx# commit

A policy below a broader policy that matches the same traffic is shadowed: it commits without error but never matches.

Policy logging and counting

Logging shows what really happened to real traffic.

user@srx# set security policies from-zone trust to-zone untrust policy WEB-OUT then log session-init
user@srx# set security policies from-zone trust to-zone untrust policy WEB-OUT then log session-close
user@srx# set security policies from-zone trust to-zone untrust policy WEB-OUT then count
OptionWrites a log when
session-initThe session is created, or denied for a deny policy
session-closeThe session ends, with the close reason and byte counts

When traffic logs go to the local system log, a syslog file with a match string keeps them apart from other messages.

user@srx# set system syslog file traffic-log any any
user@srx# set system syslog file traffic-log match RT_FLOW
user@srx> show log traffic-log

The messages are named RT_FLOW_SESSION_CREATE, RT_FLOW_SESSION_CLOSE and RT_FLOW_SESSION_DENY. Each one names the policy, the zones, the addresses and ports, and any NAT translation.

New sessionpermit policy with logRT FLOW SESSION CREATEsession endsRT FLOW SESSION CLOSEwith reasonNew sessiondeny policy with logRT FLOW SESSION DENY

To log traffic denied by the default policy, add an explicit deny policy with then log session-init at the bottom of the zone pair. By default, the implicit default policy denies without a log.

Common causes and checks

SymptomLikely causeCheck
Wrong policy matchesOrder or shadowingshow security match-policies, show security shadow-policies
No policy matchesWrong zone, address or applicationshow security zones, show security policies detail
Wrong to-zoneRoute points out a different interfaceshow route <destination>
Published server not reachablePolicy uses the public addressPolicy must match the internal address after destination or static NAT
Traffic to the SRX itself droppedNot a policy problemhost-inbound-traffic on the ingress zone or interface
Custom service on an odd port deniedApplication does not matchDefine a custom application with the right port

Common mistakes

Assuming the newest policy is checked first. New policies go to the bottom. Use insert ... before to move them.

Forgetting the global and default policies. If no zone pair policy matches, global policies are checked, and then the default policy, which denies by default.

Looking for policy logs from the default policy. By default, the default deny writes no session log. Add an explicit deny with logging.

Treating management access as a policy issue. Traffic to the SRX itself is controlled by host-inbound-traffic, not by security policies between zones.

Watch out

A shadowed policy commits without any warning. Check with show security shadow-policies or show security match-policies instead of trusting the commit.

What to remember for the exam

  • Policy lookup: zone pair policies top to bottom, then global policies, then the default policy (deny-all).
  • First match wins; source, destination and application must all match.
  • The to-zone comes from the route lookup on the destination after destination or static NAT.
  • show security match-policies shows which policy a described flow would hit, without traffic.
  • show security policies hit-count and clear security policies hit-count confirm which policy real traffic hits.
  • show security shadow-policies finds policies that can never match.
  • insert security policies ... policy X before policy Y reorders policies.
  • then log session-init session-close produces RT_FLOW_SESSION_CREATE, RT_FLOW_SESSION_CLOSE and RT_FLOW_SESSION_DENY messages.

Check yourself

  • A new permit policy is added for a zone pair but traffic is still denied by an older deny policy. Why?

    New policies are added at the bottom and the first match wins, so the older deny policy matches first; move the permit with insert ... before.

  • Which command shows the policy a flow would match without sending any traffic?

    show security match-policies with the zones, addresses, ports and protocol of the flow.

  • Traffic is denied by the default policy and no log appears. How do you get a log?

    Add an explicit deny policy at the bottom of the zone pair with then log session-init.

Topic 1 of 3 in Monitoring and Troubleshooting

Test yourself on Monitoring and Troubleshooting

The full Juniper JNCIA-SEC JN0-232 question bank has 658 questions, with timed practice exams and an explanation for every answer.

This study guide is independent and is not affiliated with, endorsed by, or sponsored by Juniper. Vendor names, certification names and exam codes are trademarks of their respective owners and are used for identification only.