How can I get this to work please? The example that I am using in the docs is
not working.
modprobe iptable_nat
iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
echo 1 > /proc/sys/net/ipv4/ip_forward
iptables -A PREROUTING -t nat -p tcp -d 127.0.0.1 --dport 80 -j DNAT --to
192.168.1.100:8080
iptables -A PREROUTING -t nat -p tcp -d 192.168.1.5 --dport 80 -j DNAT --to
192.168.1.100:8080
iptables -A PREROUTING -t nat -p tcp -d 127.0.0.1 --dport 53 -j DNAT --to
192.168.1.100:8080
iptables -t nat -A PREROUTING -p tcp --dport 80 -i eth0 -j DNAT --to
192.168.1.100:8080
--- Synchronet 3.15a-Win32 NewsLink 1.85
- telnet://sbbs.cyberchatnet.com:23 -
I grew tired of manually doing this, so I wrote a script to do so. I've
attached it, plus two other util pgms I use for such things:
- pf_admin : PortFortward Admin tool
- tcp_server.pl : Pgm to listen on a port
- tcp_client.pl : Pgm to send test data to a server:port
(running any of the above with '-h' gives usage/help)
For my tests, the following is true:
SuSETest = server to forward - 192.168.2.205 (like your 192.168.1.5)
DBLinuxTest = server to forward to - 192.168.2.204 (like your 192.168.1.100)
On the server I wish to forward, I ran this:
SuSETest:/root #pf_admin -s 192.168.2.204 -lp 80 -rp 8080
(this pgm logs the rules it used to /tmp/pfrules, which created:
SuSETest:/root #cat /tmp/pfrules
/usr/sbin/iptables -t nat -A PREROUTING -i eth0 -p TCP -s any/0 --dport
80 -j LOG --log-prefix "PortFW:80:192.168.2.204:8080 "
/usr/sbin/iptables -A FORWARD -p TCP --dport 80 -s any/0 -j ACCEPT
/usr/sbin/iptables -t nat -A POSTROUTING -s any/0 -j MASQUERADE
/usr/sbin/iptables -t nat -A PREROUTING -i eth0 -p TCP -s any/0 -j DNAT
--dport 80 --to-destination 192.168.2.204:8080
On the dest server, I started a tcp listener server, which is listening
on 8080:
DBLinuxTest:/root #tcp_server.pl -p 8080
10/27/09 07:19:54 > tcp_server.pl Ver: 03.0200
10/27/09 07:19:54 >
10/27/09 07:19:54 > PORT : 8080
10/27/09 07:19:54 > REPLY : off
10/27/09 07:19:54 > MAXQLEN : 5
10/27/09 07:19:54 > LOGFILEN : /tmp/tcp_server.log
10/27/09 07:19:54 >
10/27/09 07:19:54 > Creating a TCP socket on port 8080
10/27/09 07:19:54 > + Listening, up to 5 connections
10/27/09 07:19:54 > + Waiting for client requests
From (yet another) server, I sent a packet to the forwarding server
(SuSETest, 192.168.2.205), which should then forward it to
DBLinuxTest:8080...
tcp_client.pl -s 192.168.2.205 -p 80
10/27/09 07:21:50 > tcp_client.pl Ver: 03.0200
10/27/09 07:21:50 >
10/27/09 07:21:50 > SERVER : 192.168.2.205
10/27/09 07:21:50 > PORT : 80
10/27/09 07:21:50 > CPORT : ANY
10/27/09 07:21:50 > QUIET : off
10/27/09 07:21:50 > WAIT : off
10/27/09 07:21:50 > INFILEN :
10/27/09 07:21:50 >
10/27/09 07:21:50 > Creating a TCP socket on port 80
10/27/09 07:21:50 > + Sending data to 192.168.2.205:80 from port 32781
10/27/09 07:21:50 > + Test data
10/27/09 07:21:50 > > this is a test...
10/27/09 07:21:50 >
10/27/09 07:21:50 > Done: RC=0
Which it did:
10/27/09 07:21:50 > + Receiving data from client [susetest at
192.168.2.205:32781]
10/27/09 07:21:50 > this is a test...
10/27/09 07:21:50 > + Receive complete
10/27/09 07:21:50 > Closing connections
10/27/09 07:21:50 >
10/27/09 07:21:50 > Done: RC=0
Note - the attached programs were built from a common skeleton I use, so
they're kinda wordy and and contain stuff you don't need, but they work
in any case...
Hope this helps