[Day 9] 3. Port forwarding using PREROUTING chain
Setup Details
- Machine: Debian ()
192.168.80.128 - Service: Apache installed (default port: 80)
Objective
Use PREROUTING in the NAT table to perform dynamic NAT (port forwarding). Redirect traffic from port
800080Steps
-
Run the PREROUTING Command
Execute the following command to configure port forwarding:bashsudo iptables -t nat -A PREROUTING -p tcp --dport 8000 -j REDIRECT --to-port 80Explanation:
- : Use the NAT table.
-t nat - : Append the rule to the PREROUTING chain.
-A PREROUTING - : Match TCP packets.
-p tcp - : Match packets destined for port 8000.
--dport 8000 - : Redirect the packet.
-j REDIRECT - : Redirect to port 80 (where Apache is listening).
--to-port 80
-
Verify the Rule
Check if the rule has been added successfully:bashsudo iptables -t nat -L -n -vThis will display the NAT table rules, including the newly added PREROUTING rule.
Test the Setup
-
Open a browser or use a tool like
to test:curlbashcurl http://192.168.80.128:8000If configured correctly, this will serve content from Apache (running on port 80).
-
Traffic Behavior
- Any traffic sent to port is automatically forwarded to port
8000.80
- Any traffic sent to port
Conclusion
This simple rule dynamically forwards traffic from one port to another using iptables' NAT table and the PREROUTING chain.
Read Next
[Day 9] 4. BARNYARD2 and SNORT
**Objective:** Snort generates binary (U2) output, which Barnyard2 processes and writes into an SQL database. Finally, Apache with PHP will display th...
[Day 9] 5. Suricata
**Suricata** is an open-source, high-performance Intrusion Detection and Prevention System (IDS/IPS) that analyzes network traffic for malicious activ...