Security policies are fundamental in configuring and managing traffic flow on SRX devices. They define rules for how traffic is allowed, denied, or logged between different network zones.
Security policies control traffic between zones on an SRX device. Without these policies, traffic between zones (e.g., trust and untrust) is blocked by default. These policies are critical for:
Each security policy consists of several components:
Defines where the traffic originates:
192.168.1.0/24.Defines where the traffic is going:
203.0.113.10.Specifies the type of traffic or protocol:
Determines what happens to the traffic:
Allow HTTP (TCP port 80) traffic from the trust zone to the untrust zone.
Match traffic originating from any address in the trust zone:
set security policies from-zone trust to-zone untrust policy allow-web match source-address any
Match traffic destined for any address in the untrust zone:
set security policies from-zone trust to-zone untrust policy allow-web match destination-address any
Match the application (HTTP):
set security policies from-zone trust to-zone untrust policy allow-web match application junos-http
Permit the traffic:
set security policies from-zone trust to-zone untrust policy allow-web then permit
Allow all traffic from the trust zone to the untrust zone and log every session for monitoring.
Match all traffic from the trust zone:
set security policies from-zone trust to-zone untrust policy log-all match source-address any
Permit the traffic and enable logging:
set security policies from-zone trust to-zone untrust policy log-all then permit log
Allow SSH traffic only from a specific subnet (192.168.1.0/24) in the trust zone to an external server (203.0.113.10) in the untrust zone.
Match traffic from 192.168.1.0/24:
set security address-book global address internal-network 192.168.1.0/24
set security policies from-zone trust to-zone untrust policy ssh-access match source-address internal-network
Match traffic destined for 203.0.113.10:
set security address-book global address web-server 203.0.113.10
set security policies from-zone trust to-zone untrust policy ssh-access match destination-address web-server
Match the SSH application:
set security policies from-zone trust to-zone untrust policy ssh-access match application junos-ssh
Permit the traffic:
set security policies from-zone trust to-zone untrust policy ssh-access then permit
Use the following commands to verify your configuration:
View the policy:
show configuration security policies
Monitor traffic matching the policy:
show security flow session
Check hit counts (number of times the policy has been used):
show security policies hit-count
Allow HTTP traffic only from 8:00 AM to 6:00 PM:
Define a schedule:
set schedules time-range business-hours start-time 08:00 stop-time 18:00 daily
Attach the schedule to the policy:
set security policies from-zone trust to-zone untrust policy allow-web then permit schedule business-hours
Always create explicit policies for legitimate traffic and rely on the default deny for unwanted traffic.
The show security flow session command shows all active traffic sessions on the device, including:
Command:
show security flow session
Example Output:
Session ID: 12345
From: 192.168.1.10/1234 to 203.0.113.10/80, TCP
Policy name: allow-web
Ingress interface: ge-0/0/1
Egress interface: ge-0/0/2
The show security policies hit-count command displays how many times each policy has been matched.
Command:
show security policies hit-count
Example Output:
From zone: trust, To zone: untrust
Policy: allow-web
Hits: 234
Policy: deny-all
Hits: 45
Policy logging captures detailed information about traffic matches. Use it to analyze traffic patterns or investigate denied traffic.
Configuration: Enable logging for a policy:
set security policies from-zone trust to-zone untrust policy allow-web then permit log
View log messages:
show log messages
If traffic isn’t working as expected, you can trace its path through the SRX device.
Enable trace logging for flow issues:
set security flow traceoptions file flow-log
set security flow traceoptions flag basic-datapath
Commit the changes:
commit
View the trace log:
show log flow-log
If traffic isn’t matching a policy:
Junos OS supports deep packet inspection (DPI) to identify applications regardless of their port numbers.
You want to block Facebook traffic but allow general web browsing.
Use the predefined application facebook:
set security policies from-zone trust to-zone untrust policy block-facebook match application facebook
set security policies from-zone trust to-zone untrust policy block-facebook then deny
Allow web browsing:
set security policies from-zone trust to-zone untrust policy allow-web match application junos-http
set security policies from-zone trust to-zone untrust policy allow-web match application junos-https
set security policies from-zone trust to-zone untrust policy allow-web then permit
Block or allow traffic based on the geographic location of IP addresses.
Allow traffic only from the United States and block all others.
Enable Geo-IP filtering:
set security policies from-zone untrust to-zone trust policy geo-block match source-address country US
set security policies from-zone untrust to-zone trust policy geo-block then permit
Deny traffic from all other countries:
set security policies from-zone untrust to-zone trust policy deny-all then deny
Allow FTP traffic only during business hours (9 AM - 5 PM).
Define a time range:
set schedules time-range business-hours start-time 09:00 stop-time 17:00 daily
Apply the schedule to the policy:
set security policies from-zone trust to-zone untrust policy allow-ftp match application junos-ftp
set security policies from-zone trust to-zone untrust policy allow-ftp then permit schedule business-hours
This is a must-know rule for both Junos configuration and the JNCIA-SEC exam.
service and application in the Same PolicyIn Junos OS, a security policy match clause can include either:
An application or application-set OR
A service or service-set
But not both at the same time. Attempting to use both results in a configuration failure at commit time.
set security policies from-zone trust to-zone untrust policy invalid-policy match application junos-http
set security policies from-zone trust to-zone untrust policy invalid-policy match service my-custom-service
→ This configuration will fail to commit, because it tries to use both application and service.
Application objects provide deep inspection and protocol identification (layer 7).
Service objects rely only on port/protocol matching (layer 4).
Mixing both would create ambiguity in traffic classification.
Decide whether you want to use application-based or service-based matching.
Stick to application objects when using features like UTM, IDP, or when using application sets.
Expect questions like:
"A security policy fails to commit due to configuration syntax. Which of the following is the cause?"
→ Correct answer:
"The policy uses both application and service match conditions, which are mutually exclusive in Junos OS."
Even though you cannot use both in the same policy, it's important to understand why application objects are preferred, especially in complex environments.
Applications (like junos-http, junos-https) support:
Protocol detection beyond port numbers
Integration with application-based UTM, AppFW, IDP, and logging
Support for nested application sets
Services (e.g., TCP port 80) only match based on layer 4 headers (protocol + port)
You can group multiple applications into application-sets and reference those in your policy.
This is stronger and more flexible than service objects.
Example:
set applications application-set web-traffic application [ junos-http junos-https ]
set security policies from-zone trust to-zone untrust policy allow-web match application web-traffic
If your policy uses application-set, the system will:
Detect traffic dynamically.
Apply match based on actual application behavior, not just port.
"Which of the following statements about applications and services in a policy is true?"
→ Correct answer:
"Security policies cannot include both application and service in the match clause."
| Rule/Concept | Details |
|---|---|
| Mutual exclusivity | application and service cannot be used together in one policy |
| Application matching priority | Application objects offer richer detection and policy granularity |
| Preferred for security features | Use application when using UTM, AppFW, IDP, or content inspection |
| Policy syntax enforcement | Misuse leads to commit-time error, not runtime failure |
Why does an SRX firewall deny traffic even though a security policy appears to allow it?
Because the traffic may not match the policy’s zones, addresses, or application conditions.
SRX security policies are evaluated based on multiple matching criteria including source zone, destination zone, source address, destination address, and application. If any of these parameters do not match exactly, the policy will not be applied and the default deny rule will drop the packet. A common mistake is configuring the correct addresses but assigning the interface to the wrong security zone, causing traffic to arrive from a different zone than expected. Another common issue is application mismatch when using application-aware policies. Engineers troubleshooting this should verify zone assignments, check the session table, and confirm the packet flow using show security flow session.
Demand Score: 95
Exam Relevance Score: 96
In what order are SRX security policies evaluated?
Policies are evaluated top-down within the policy list for the specific zone pair.
In Junos SRX, security policies are processed sequentially from the first rule to the last rule for the defined source zone and destination zone. Once a match is found, the action (permit or deny) is applied and no further policies are evaluated. This behavior makes rule ordering critical for correct firewall operation. More specific rules should be placed above broader rules to ensure that important traffic is not unintentionally matched by a generic rule earlier in the list. Engineers often encounter unexpected behavior when a broad “permit any” policy is placed above a more restrictive rule.
Demand Score: 91
Exam Relevance Score: 94
Is traffic within the same security zone allowed by default on an SRX firewall?
Yes, intra-zone traffic is allowed by default unless explicitly restricted.
SRX devices follow a zone-based firewall model. By default, traffic flowing between interfaces within the same security zone is permitted without requiring a security policy. This default behavior simplifies internal communication but can introduce risk if sensitive systems share the same zone. Administrators who need stricter segmentation should create explicit intra-zone policies or place interfaces into separate zones. Understanding this default behavior is important for troubleshooting because engineers sometimes search for a missing policy even though the traffic is permitted automatically.
Demand Score: 90
Exam Relevance Score: 92
Do SRX security policies apply to traffic entering and exiting the same interface?
Only if the traffic crosses different security zones.
Security policies in SRX firewalls are evaluated based on the zone pair: source zone to destination zone. If traffic enters and exits interfaces belonging to the same zone, no security policy evaluation occurs because intra-zone traffic is allowed by default. If the interfaces belong to different zones, the firewall must evaluate policies for that zone pair. This design helps simplify firewall configuration but also means that proper zone planning is essential for enforcing security controls.
Demand Score: 86
Exam Relevance Score: 90
What is the purpose of a global security policy on an SRX device?
A global policy applies to traffic between any zones when no zone-specific policy matches.
Global policies provide a fallback security rule that can apply across all zone pairs. They are evaluated after zone-based policies if no match is found. This feature allows administrators to enforce baseline rules such as logging or default deny policies without repeating the same configuration for every zone pair. However, because zone-specific policies are evaluated first, global policies typically act as a safety net rather than the primary method for controlling traffic.
Demand Score: 84
Exam Relevance Score: 88
Why might a newly created security policy not take effect immediately?
Because the configuration must be committed before the firewall begins using the new policy.
Junos uses a candidate configuration model. When administrators enter configuration mode and add or modify policies, the changes are stored in the candidate configuration but are not active until the commit command is executed. This approach allows administrators to review and validate changes before applying them to the running system. Many engineers troubleshooting SRX behavior forget to commit changes, leading them to believe the firewall is ignoring their configuration.
Demand Score: 80
Exam Relevance Score: 87