PDA

View Full Version : How do I setup IP port forwarding?


slaquer
2006-05-10, 08:46 PM CDT
My machine is directly connected to the network and internet. I want to set it up so that when someone goes to my IP address on port 2593, it will be forwarded to another machine on my network.

Like:
FTP to 207.234.148.118 and it will forward to 192.168.1.1
How do I do this?

slaquer
2006-05-10, 08:52 PM CDT
I think netcat can do this somehow cant it? I searched for port forwarding and only find stuff on routers. I want my machine that is connected to the internet via 1 adapter to forward incoming traffic to a port on another machine on the network is all, should be simple I jsut dont know how to do it...

Zotter
2006-05-10, 11:15 PM CDT
No, not netcat, but netfilter. Use the userspace tool 'iptables' to set it all up. Most folks will put the series of iptable commands into a shell script - makes it a bit easier to adjust and tweek.

There're several pre-packaged scripts out there to do this with. Just do a google search on iptables firewall script port forward and the like - that should hit at least a couple <eg>.

Reading through some of the prepackaged scripts and going through the iptables tutorial, manual and stuff all make for a great oportunity/method to learn how to set it up yourself.

mndar
2006-05-11, 02:45 AM CDT
Here is the setup I had done a long time back. Its on http://mndar.linux-fan.com

Information Center: Port Forwarding

External Interface: eth1 , 10.1.11.111
Internal Interface: eth0 , 192.168.0.1
LAN computer: 192.168.0.2
Client computer: 10.1.11.72

On the router(linux box). enable NAT .

iptables -t nat -A POSTROUTING -o eth1 -j MASQUERADE
iptables -A FORWARD -s 192.168.0.0/24 -j ACCEPT
iptables -A FORWARD -d 192.168.0.0/24 -j ACCEPT
iptables -A FORWARD -s ! 192.168.0.0/24 -j DROP

#for webserver, apache
iptables -t nat -A PREROUTING -p tcp -i eth1 -d 10.1.11.111 --dport 80 -j DNAT --to 192.168.0.2:80
iptables -A FORWARD -p tcp -i eth1 -d 192.168.0.2 --dport 80 -j ACCEPT

On the LAN computer. Set the gateway as the router(linux box)
Open port 80 for web server.