[Day 8] 7. IP Forwarding and NAT Configuration (LAB 4)
Network Configuration
| Machine | IP Address | Network Type | | -------------------- | ---------------------------------- | ---------------- | | Debian Machine 1 |
192.168.40.10192.168.40.101192.168.50.101192.168.50.10Make sure you have given the correct gateways in both Debian 1 and Debian 3 as
192.168.40.101192.168.50.101Steps
1. Initial State (Ping Failure)
- Issue:
- If you attempt to ping Deb1 () from Deb3 (
192.168.40.10), the ping will fail.192.168.50.10 - Reason: IP packet forwarding is disabled by default on Deb2 (and
192.168.40.101), which is acting as a router.192.168.50.101
- If you attempt to ping Deb1 (
2. Enable IP Forwarding on Debian 2
To allow traffic forwarding through Deb2, perform the following steps:
-
Check if packet forwarding is enabled:
bashcat /proc/sys/net/ipv4/ip_forward- If the output is , forwarding is disabled.
0
- If the output is
-
Enable packet forwarding:
bashsudo sh -c "echo 1 > /proc/sys/net/ipv4/ip_forward"- This command enables IP packet forwarding temporarily on Deb2.
3. Verify Ping (After Enabling Forwarding)
- Now, try pinging Deb1 () from Deb3 (
192.168.40.10).192.168.50.10 - The ping will work because forwarding is now enabled on Deb2.
4. Issue: IP Exposure in WAN Network
- When IP packet forwarding is enabled, the private IP address of Deb1 () gets exposed to the WAN network.
192.168.40.10 - To resolve this and mask the private IP, we configure NATing (Network Address Translation) on Deb2.
5. View NAT Table in IPTables
-
To inspect the NAT table in iptables:
bashsudo iptables -t nat -L -
NAT Table Chains:
| Chain | Description | | --------------- | --------------------------------------------------- | | PREROUTING | Handles incoming packets (before routing decision). | | POSTROUTING | Handles outgoing packets (after routing decision). | | INPUT | For packets destined to the machine itself. | | OUTPUT | For packets generated by the machine. |
Here, we use
POSTROUTINGstatic NATPREROUTINGdynamic NAT6. Configure NAT (MASQUERADE)
To configure NAT using the POSTROUTING chain:
bashsudo iptables -t nat -A POSTROUTING -o ens36 -j MASQUERADE
- Explanation:
- : Specifies the NAT table.
-t nat - : Appends the rule to the POSTROUTING chain.
-A POSTROUTING - : Applies the rule to the ens36 interface (Deb2’s WAN-facing interface).
-o ens36 - : Masks the source IP address with the IP of the ens36 interface (
-j MASQUERADE).192.168.50.101
7. Final State
- Result:
- Deb1 () and Deb3 (
192.168.40.10) can now communicate through Deb2.192.168.50.10 - The private IP of Deb1 is masked, and WAN traffic sees the IP of Deb2’s ens36 interface ().
192.168.50.101
- Deb1 (
Here are the steps to check private IP exposure using
tcpdump8. Steps to Check with tcpdump
on Deb3
tcpdump-
Install tcpdump (if not already installed):
bashsudo apt-get install tcpdump -
Capture ICMP packets on Deb3’s interface (e.g.,
):ens36bashsudo tcpdump -i ens36 icmp -
Ping Deb1 (
) from Deb3 (192.168.40.10):192.168.50.10bashping 192.168.40.10 -
Observe the Output:
- Check if the source IP of ICMP packets shows Deb1’s private IP ().
192.168.40.10
- Check if the source IP of ICMP packets shows Deb1’s private IP (
If you still see the private IP, NATing is not configured correctly. Fix the NAT rule on Deb2.
Read Next
[Day 8] 8. Extra
1. **Graphical Passwords**: These are passwords that use images or graphics instead of traditional alphanumeric characters. Users often select points...
[Day 9] 1. PKI Lab in Short (XCA)
**Naming Conventions for Better Understanding** ### Root CA 1. **001-001-DB-rootca.xdb** – Root CA Database 2. **001-002-CRT-RootCA.crt** – Roo...