Viewing Current iptables Rules
In this first step, you will learn how to view the current firewall rules using iptables
within the Kali Linux container. This is an essential starting point for understanding the existing firewall configuration before making any changes.
When you open the terminal in the LabEx VM environment, you will be automatically connected to the Kali Linux container's shell. There is no need to manually start the container or enter the shell; the environment is already set up for you. Let's begin by exploring the current state of the firewall rules.
iptables
is a command-line utility that allows you to manage the Linux kernel's IP packet filtering rules. These rules determine how network traffic is handledโwhether to accept, drop, or redirect packets based on specific criteria like source IP or port numbers. Viewing the rules helps you see what policies are currently in place.
Run the following command in the terminal to list the current iptables
rules. Type the command and press Enter:
iptables -L -v -n
This command breaks down as follows:
iptables
: The tool for managing firewall rules.
-L
: Lists all rules in the selected chains.
-v
: Provides verbose output, including packet and byte counters.
-n
: Shows IP addresses and ports in numeric format without name resolution.
After executing this command, you will see an output similar to the one below. The exact output may vary depending on the container's initial configuration.
Expected Output (example, actual output may vary):
Chain INPUT (policy ACCEPT 0 packets, 0 bytes)
pkts bytes target prot opt in out source destination
Chain FORWARD (policy ACCEPT 0 packets, 0 bytes)
pkts bytes target prot opt in out source destination
Chain OUTPUT (policy ACCEPT 0 packets, 0 bytes)
pkts bytes target prot opt in out source destination
This output displays the three main chains: INPUT
for incoming traffic, FORWARD
for traffic passing through, and OUTPUT
for outgoing traffic. Each chain shows its default policy (like ACCEPT
) and any specific rules if they exist. If the chains appear empty, as in this example, it means no custom rules are currently applied, and the default policies govern all traffic.
Take a moment to review the output. Understanding the current state of your firewall is crucial before adding or modifying rules, which you will do in the next steps. This foundational step ensures you are familiar with the starting configuration of iptables
in your Kali Linux container.