# [SOLVED] just another Iptables Port Forwarding

## Gyscos

Hello !

I've spent the last few days trying to get a working port forwarding on my server... duh

So the server is in a local network, some ports are already forwaded from the router to it. Now I want the 81 port (or any other) to be forwarded from the server to yet another computer, on port 80.

Server is 192.168.1.40, the new computer is 192.168.1.51. Here is what I tried thus far :

```
server-alex ~ # iptables -t nat -A PREROUTING -p tcp -d 192.168.1.40 --dport 81 -j DNAT --to 192.168.1.51:80

server-alex ~ # iptables -t nat -A POSTROUTING -p tcp -d 192.168.1.51 --dport 80 -j SNAT --to-source 192.168.1.40

server-alex ~ # /etc/init.d/iptables save

 * Saving iptables state ...                                                                                                           [ ok ]

server-alex ~ # /etc/init.d/iptables start

 * Loading iptables state and starting firewall ...                                                                                    [ ok ]

server-alex ~ # /etc/init.d/iptables stop 

 * Saving iptables state ...                                                                                                           [ ok ]

 * Stopping firewall ...                                                                                                               [ ok ]

server-alex ~ # /etc/init.d/iptables start

 * Loading iptables state and starting firewall ...                                                                                    [ ok ]

server-alex ~ # 

```

If I do iptables -L, everything is in policy ACCEPT, so I guess I don't need a FORWARD rule.

Of course, I used every kernel option that was said to be needed, even remotely...

The start/stop/start was mentionned on some wiki, so I decided to try it; but I get no better result with a simple start.

After I did that, the server is still working on port 80, but port 81 gives nothing (timeout)... Yet http://192.168.1.51:80 works jsut fine in firefox.

I precise that I tested everything from my computer, wich happen to be this 192.168.1.51. I hope it doesn't change anything, but I'm being cautious...

Anyone knows why this isn't working ? Am I missing something ?...Last edited by Gyscos on Tue Jul 21, 2009 9:15 am; edited 1 time in total

----------

## Mike Hunt

Did you enable packet forwarding?

```
echo 1 > /proc/sys/net/ipv4/ip_forward
```

----------

## Gyscos

Wooow wow wow, you saved me !

Thanks a lot man, now everything works just sooo fine !!

----------

## cach0rr0

make sure you enable that in sysctl.conf, otherwise your change will be lost next time you reboot

not that a linux box ever requires a reboot, but the point still stands

----------

## Gyscos

so I do 

```
echo "echo 1 > /proc/sys/net/ipv4/ip_forward" > /etc/sysctl.conf

```

?

Thanks  :Smile: 

----------

