I have a Linux box (machine A) connected to a LAN via eth0 and to another machine (machine B) on eth1.
I want to forward connections made to machine A port 80 to machine B.
Machine A's IP on eth0 (main LAN) is 192.168.1.126.
Machine A's IP on eth1 (my personal 2-machine LAN) is 192.168.10.1.
Machine B's IP on the mini-lan connected to eth1 is 192.168.10.2
First, I ran this script to get a clean slate with my IP table settings.
Code:
#!/bin/bash
echo "Stopping firewall...."
iptables -F
iptables -X
iptables -t nat -F
iptables -t nat -X
iptables -t mangle -F
iptables -t mangle -X
iptables -P INPUT ACCEPT
iptables -P FORWARD ACCEPT
iptables -P OUTPUT ACCEPT
Then I ran these commands to try to setup the port forwarding:
Code:
iptables -t nat -A PREROUTING -i eth0 -p tcp -d 192.168.1.126 --dport 80 -j DNAT --to 192.168.10.2:80
iptables -A FORWARD -p tcp -i eth0 -d 192.168.10.2 --dport 80 -j ACCEPT
When I test from another machine the eth0 main LAN, it doesn't work. Can anyone tell me what I'm doing wrong?
Bookmarks