NAT for two overlapping LANs

Connect two overlapping LANs using NAT.

Network

Scroll sideways to exploreOpen full diagram
PC1–R1 and PC2–R2 form separate identical LANs; R1 and R2 reach PC3 through R3.
PC1 and PC2 have identical IPs in separate LANs.
Open a console

1. Test connectivity without NAT

PC1 and PC2

ping -n -c 3 -W 1 192.168.1.2
ping -n -c 3 -W 1 10.0.0.1

The gateways reply; remote PC3 does not.

2. Enable NAT

R1 and R2

iptables -t nat -A POSTROUTING -s 192.168.1.0/24 -o eth1 -j MASQUERADE

R1 and R2

timeout 120 tcpdump -U --immediate-mode -i eth1 -w /tmp/lab-nat.pcap "icmp" &
capture_pid=$!
sleep 1

3. Compare source addresses

PC1 and PC2

ping -n -c 3 -W 1 10.0.0.1

R1 and R2

sleep 2
kill -INT "$capture_pid"
wait "$capture_pid" || true
tcpdump -nn -e -r /tmp/lab-nat.pcap

Both pings should succeed. R1’s capture shows source 172.16.0.1; R2’s shows 172.16.1.1: NAT distinguishes the LANs.

Validation

Click "Check". Once all steps pass, click "End".