LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Networking (https://www.linuxquestions.org/questions/linux-networking-3/)
-   -   iptables redirect (https://www.linuxquestions.org/questions/linux-networking-3/iptables-redirect-253275/)

_ben_deb_ 11-10-2004 11:59 AM

iptables redirect
 
hello !

i want to redirect stream from my firewall to another pc wich run apache on it...

for now i test this with:
(i test from 192.168.0.2 to 192.168.0.1 and i want connect to 192.168.0.3 transparantly)

iptables -t nat -A PREROUTING -p tcp --dport 80 -j DNAT --to-destination 192.168.0.3:80

but it doesn't work :confused:

what should i do ?

how can i view nat filter table because "iptables -L" does not ????

thank you for your help ;)

bignerd 11-10-2004 12:15 PM

Re: iptables redirect
 
Quote:

Originally posted by _ben_deb_
hello !

i want to redirect stream from my firewall to another pc wich run apache on it...

for now i test this with:
(i test from 192.168.0.2 to 192.168.0.1 and i want connect to 192.168.0.3 transparantly)

iptables -t nat -A PREROUTING -p tcp --dport 80 -j DNAT --to-destination 192.168.0.3:80

but it doesn't work :confused:

what should i do ?

how can i view nat filter table because "iptables -L" does not ????

thank you for your help ;)

iptables -t nat -A PREROUTING -p tcp --dport 80 -j DNAT --to-destination 192.168.0.3:80

That is correct. Any tcp 80 traffic that is destined to your firewalls ip will be redirected to 192.168.0.3 destination port 80.

iptables -t nat -L -n -v will show you your nat tables. You may have conflicting rules that you need to delete.

_ben_deb_ 11-10-2004 12:27 PM

thank for your reply ...

it still doesn't work ...

here my output iptables for: iptables -L

Chain INPUT (policy ACCEPT)
target prot opt source destination

Chain FORWARD (policy ACCEPT)
target prot opt source destination

Chain OUTPUT (policy ACCEPT)
target prot opt source destination


here my output iptables for: iptables -t nat -L -n -v

Chain PREROUTING (policy ACCEPT 11 packets, 540 bytes)
pkts bytes target prot opt in out source destination
0 0 DNAT tcp -- * * 0.0.0.0/0 0.0.0.0/0 tcp dpt:80 to:192.168.0.3:80

Chain POSTROUTING (policy ACCEPT 0 packets, 0 bytes)
pkts bytes target prot opt in out source destination

Chain OUTPUT (policy ACCEPT 0 packets, 0 bytes)
pkts bytes target prot opt in out source destination


i connect to 192.168.0.1 with mozilla but i still doesn't work ??????
i don't understand :confused:

_ben_deb_ 11-10-2004 12:30 PM

maybe i must do something for reply of 192.168.0.3 ?

bignerd 11-10-2004 02:21 PM

Did you remember to very nicely ask your linux box to forward packets?

cat /proc/sys/net/ipv4/ip_forward

If it does not respond with the number 1 then you forgot to ask your box to forward those nice ipv4 packets.

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

Is how you ask the box to do this for you. You probably want to add this to a start up script so when you reboot you don't have to do this by hand each time.

-b

peter_robb 11-11-2004 03:40 PM

You need to SNAT the replies from 192.168.0.3 to look like they are from 192.168.0.1

When you send the original packets from .0.2 to .0.1, it sends them to .0.3, which replies directly to .0.2 coz it's local. So 0.2 drops the packets coz it's expecting them to only come from 0.1

It's better to test this with 2 network cards and 2 different subnets..

_ben_deb_ 11-12-2004 05:02 AM

yes you right both !

i have a script to start my computer and when i stop the rules it put 0 on /proc/sys/net/ipv4/ip_forward

so i solve the problem and i success to redirect stream to internet adress.
But i want to test from .0.2 to connect to 0.0.3 from .0.1 but it doesn't work !

i think your right and i'll try to SNAT to .0.1 to make it work !

i'll send a message later ...

thank :)

_ben_deb_ 11-13-2004 05:06 AM

Ok it's working for testing !

i filter POSTROUTING and PREROUTING nat table for it !

thanks !
:rolleyes:


All times are GMT -5. The time now is 05:13 PM.