📖 Scenario: You are learning how a firewall protects a home network by controlling which data packets can enter or leave.Imagine a firewall as a security guard checking each data packet against rules before allowing it through.
🎯 Goal: Build a simple list of data packets and a set of filtering rules, then apply the rules to decide which packets are allowed or blocked.
📋 What You'll Learn
Create a list of data packets with specific source IPs and destination ports
Define a configuration variable for allowed destination ports
Use a loop to filter packets based on allowed ports
Mark each packet as 'allowed' or 'blocked' according to the filtering
💡 Why This Matters
🌍 Real World
Firewalls protect home and business networks by controlling which data packets can pass through based on rules.
💼 Career
Network administrators and cybersecurity professionals configure firewalls and packet filters to secure systems from unauthorized access.
Progress0 / 4 steps
1
Create the list of data packets
Create a list called packets with these exact dictionaries representing data packets: {'src_ip': '192.168.1.10', 'dst_port': 80}, {'src_ip': '10.0.0.5', 'dst_port': 22}, {'src_ip': '172.16.0.3', 'dst_port': 443}, {'src_ip': '192.168.1.15', 'dst_port': 25}
Computer Networks
Hint
Use a list with dictionaries. Each dictionary has keys 'src_ip' and 'dst_port'.
2
Define allowed destination ports
Create a list called allowed_ports containing these exact port numbers: 80, 443
Computer Networks
Hint
Use a list with the numbers 80 and 443 exactly.
3
Filter packets based on allowed ports
Create a new list called filtered_packets that contains only the packets from packets where the dst_port is in allowed_ports. Use a for loop with the variable packet to check each packet.
Computer Networks
Hint
Start with an empty list filtered_packets. Use a for loop to check each packet's dst_port. Append allowed packets to the new list.
4
Mark packets as allowed or blocked
Create a new list called final_packets where each packet from packets has an added key 'status' with the value 'allowed' if its dst_port is in allowed_ports, otherwise 'blocked'. Use a for loop with the variable packet.
Computer Networks
Hint
Copy each packet dictionary to avoid changing the original. Add a 'status' key with 'allowed' or 'blocked' based on the port.
Practice
(1/5)
1. What is the primary function of a firewall in a computer network?
easy
A. To allow or block data packets based on security rules
B. To increase the speed of data transmission
C. To store data packets temporarily
D. To convert data packets into different formats
Solution
Step 1: Understand the role of a firewall
A firewall controls network access by filtering data packets according to security rules.
Step 2: Identify the correct function
It does not speed up transmission, store packets, or convert formats; it only allows or blocks packets.
Final Answer:
To allow or block data packets based on security rules -> Option A
Quick Check:
Firewall function = Allow/block packets [OK]
Hint: Firewalls control access by blocking or allowing packets [OK]
Common Mistakes:
Thinking firewalls speed up network traffic
Confusing firewalls with data storage devices
Believing firewalls change packet formats
2. Which of the following is a correct example of a packet filtering rule?
easy
A. Store packets for later analysis
B. Block packets based on their payload content
C. Convert packets from TCP to UDP
D. Allow packets from IP 192.168.1.10 to port 80
Solution
Step 1: Understand packet filtering rules
Packet filtering rules specify conditions like source IP and destination port to allow or block packets.
Step 2: Identify the valid rule
Allowing packets from a specific IP to a specific port is a valid rule; converting or storing packets is not filtering.
Final Answer:
Allow packets from IP 192.168.1.10 to port 80 -> Option D
Quick Check:
Packet filtering = Allow/block by IP and port [OK]
Hint: Packet filtering rules specify IP and port conditions [OK]
Common Mistakes:
Confusing filtering with packet conversion
Thinking filtering stores packets
Believing all packets are always blocked
3. Consider a firewall rule: Block packets from IP 10.0.0.5 to port 22. What will happen if a packet from IP 10.0.0.5 tries to connect to port 22?
medium
A. The packet will be redirected to another port
B. The packet will be allowed through the firewall
C. The packet will be blocked by the firewall
D. The packet will be logged but allowed
Solution
Step 1: Analyze the firewall rule
The rule explicitly blocks packets from IP 10.0.0.5 to port 22.
Step 2: Determine the packet's fate
Since the packet matches the block rule, it will be stopped and not allowed through.
Final Answer:
The packet will be blocked by the firewall -> Option C
Quick Check:
Block rule matched = Packet blocked [OK]
Hint: Block rules stop matching packets from passing [OK]
Common Mistakes:
Assuming packets are redirected instead of blocked
Thinking packets are logged but allowed by default
Confusing allow and block rules
4. A firewall rule is written as: Allow packets to port 443 from any IP. However, packets from IP 192.168.1.20 to port 443 are still blocked. What is the most likely error?
medium
A. There is a conflicting block rule with higher priority
B. The firewall does not filter packets by port
C. Port 443 is not used for secure connections
D. The rule is missing a source IP specification
Solution
Step 1: Review the allow rule
The rule allows packets to port 443 from any IP, so it should permit packets from 192.168.1.20.
Step 2: Identify possible conflicts
If packets are blocked despite the allow rule, a block rule with higher priority likely overrides it.
Final Answer:
There is a conflicting block rule with higher priority -> Option A
Quick Check:
Conflicting rules = Block overrides allow [OK]
Hint: Check for higher priority block rules when allow fails [OK]
Common Mistakes:
Believing port 443 is not for secure connections
Ignoring rule priority order
Assuming firewall ignores ports
5. You want to create a firewall rule that allows HTTP traffic (port 80) only from the IP range 192.168.1.0 to 192.168.1.255 and blocks all other HTTP traffic. Which approach correctly applies packet filtering to achieve this?
hard
A. Block packets from 192.168.1.0/24 to port 80; then allow all packets to port 80
B. Allow packets from 192.168.1.0/24 to port 80; then block all packets to port 80
C. Allow all packets to port 80 without IP restrictions
D. Block all packets to port 80 without exceptions
Solution
Step 1: Define the allow rule for the IP range
Allow packets from IP range 192.168.1.0/24 (which covers 192.168.1.0 to 192.168.1.255) to port 80.
Step 2: Define the block rule for all other HTTP traffic
Block all other packets to port 80 that do not match the allow rule.
Final Answer:
Allow packets from 192.168.1.0/24 to port 80; then block all packets to port 80 -> Option B
Quick Check:
Allow specific IP range, then block others = Correct filtering [OK]
Hint: Allow specific IP range first, then block others [OK]
Common Mistakes:
Blocking allowed IP range by mistake
Allowing all traffic without restrictions
Reversing allow and block order
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.