NDC & PKI

[Day 9] 3. Port forwarding using PREROUTING chain

D
DITISS Admin
••2 min read

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

8000
to port
80
on the same machine.


Steps

  1. Run the PREROUTING Command
    Execute the following command to configure port forwarding:

    bash
    sudo iptables -t nat -A PREROUTING -p tcp --dport 8000 -j REDIRECT --to-port 80
    

    Explanation:

    • -t nat
      : Use the NAT table.
    • -A PREROUTING
      : Append the rule to the PREROUTING chain.
    • -p tcp
      : Match TCP packets.
    • --dport 8000
      : Match packets destined for port 8000.
    • -j REDIRECT
      : Redirect the packet.
    • --to-port 80
      : Redirect to port 80 (where Apache is listening).
  2. Verify the Rule
    Check if the rule has been added successfully:

    bash
    sudo iptables -t nat -L -n -v
    

    This will display the NAT table rules, including the newly added PREROUTING rule.


Test the Setup

  1. Open a browser or use a tool like

    curl
    to test:

    bash
    curl http://192.168.80.128:8000
    

    If configured correctly, this will serve content from Apache (running on port 80).

  2. Traffic Behavior

    • Any traffic sent to port
      8000
      is automatically forwarded to port
      80
      .

Conclusion

This simple rule dynamically forwards traffic from one port to another using iptables' NAT table and the PREROUTING chain.


Read Next

8/26/2026

[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...

8/26/2026

[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...