IP forwarding
Hi,
I've got a network setup where the internal router is a Linux box running iptables. External interface is eth0, internal eth1. I'm attempting to forward an external IP address (say, 1.2.3.4) to an internal machine.
The rule I added is:
iptables -t nat -A PREROUTING -d 1.2.3.4 -p tcp --dport 80 -j DNAT --to 192.168.1.202
However, attempting to
telnet 1.2.3.4 80
does not work. It's clear that the rule is being applied, because the web server running on the external machine is not responding unless I telnet from the router itself, but unfortunately I'm not getting into 192.168.1.202 either. Attempting to
telnet 192.168.1.202 80
does work as expected.
What am I missing? Any pointers are welcome. Thanks,
Ricardo J. Méndez
http://ricardo.strangevistas.net/
Hi,
Quoted 15 lines
-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of Ricardo J. Méndez
Sent: Thursday, August 04, 2005 3:38 AM
To: [email protected]
Subject: IP forwardingHi,
I've got a network setup where the internal router is a Linux box running iptables. External interface is eth0, internal eth1. I'm attempting to forward an external IP address (say, 1.2.3.4) to an internal machine.
Quoted 4 lines
The rule I added is:
iptables -t nat -A PREROUTING -d 1.2.3.4 -p tcp --dport 80 -j DNAT --to 192.168.1.202
The roule should look like this:
iptables -t nat -A PREROUTING -d 1.2.3.4 -p tcp --dport 80 -j DNAT --to-destination 192.168.1.202
Quoted 12 lines
However, attempting to
telnet 1.2.3.4 80
does not work. It's clear that the rule is being applied, because the web server running on the external machine is not responding unless I telnet from the router itself, but unfortunately I'm not getting into 192.168.1.202 either. Attempting to
telnet 192.168.1.202 80
Quoted 10 lines
does work as expected.
What am I missing? Any pointers are welcome. Thanks,
Ricardo J. Méndez
http://ricardo.strangevistas.net/
Zoltán
Quoted 19 lines · Gömöri Zoltán
Hi,
Quoted 17 lines
-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of Ricardo J. Méndez
Sent: Thursday, August 04, 2005 3:38 AM
To: [email protected]
Subject: IP forwardingHi,
I've got a network setup where the internal router is a Linux box running iptables. External interface is eth0, internal eth1. I'm attempting to forward an external IP address (say, 1.2.3.4) to an internal machine.
The rule I added is:
Quoted 7 lines
Quoted 2 lines
iptables -t nat -A PREROUTING -d 1.2.3.4 -p tcp --dport 80 -j DNAT --to 192.168.1.202
The roule should look like this:
iptables -t nat -A PREROUTING -d 1.2.3.4 -p tcp --dport 80 -j DNAT --to-destination 192.168.1.202
Actually, I believe that --to is a valid unique prefix for --to-destination. The fact that it didn't flag as a syntax error supports this.
The problem is that locally generated packets (from the firewall itself) to 1.2.3.4 never pass through filter.PREROUTING. Each forwarded port may need up to four rules to NAT all access. The script I use (at http://www.curby.net/doc/curbywall ) is an example of using all four, though it may be difficult to understand. The general principle but applied to the SNAT-ed network as opposed to localhost is described in
http://netfilter.org/documentation/HOWTO//NAT-HOWTO-10.html
Other folks here are proponents of running a local DNS server so you don't have to do such NAT contortions.
--Curby
Quoted 8 lines
Quoted 4 lines
The roule should look like this:
iptables -t nat -A PREROUTING -d 1.2.3.4 -p tcp --dport 80 -j DNAT --to-destination 192.168.1.202
Actually, I believe that --to is a valid unique prefix for --to-destination. The fact that it didn't flag as a syntax error supports this.
Agreed. Webmin's IPTables interface displays the rule properly as well, so --to is a valid substitute.
Quoted 2 lines
The problem is that locally generated packets (from the firewall itself) to 1.2.3.4 never pass through filter.PREROUTING.
But I 'm testing this from a desktop on the network, not the firewall itself. PREROUTING should apply to those packets, correct?
Quoted 4 lines
Each
forwarded port may need up to four rules to NAT all access. The script I use (at http://www.curby.net/doc/curbywall ) is an example of using all four, though it may be difficult to understand.
From what I can see from the script, besides creating 1 PRE DNAT and up to 2 POST SNAT rules (one for the internal network and one for the de-militarized zone), cw_forwardin is creating also an OUT rule for
the destination IP. It also seems that the SNAT rule for the
internal network is using the ip address for the iptables machine as the source.
Assuming that last one is correct, would that still be the IP address used for SNAT on the scenario I'm faced with? IE, doing DNAT/SNAT for a machine internal to the network, redirecting to it the requests that come from our network to a web server outside of it.
(Am I missing something? It's a bit difficult to read, now having that much experience with bash scripts)
Quoted 3 lines
Other folks here are proponents of running a local DNS server so you don't have to do such NAT contortions.
Indeed, it's an approach we considered, but we need this to work with some internal apps that access the IP address directly.
Thanks,
Ricardo J. Méndez
http://ricardo.strangevistas.net/
Quoted 2 lines · Ricardo J. Méndez
But I 'm testing this from a desktop on the network, not the firewall itself. PREROUTING should apply to those packets, correct?
In that case, the problem you're seeing is exactly that which is discussed in the HOWTO link I posted last time. It's also explained by Jason's link. The idea is that packets TO the server are indeed being correctly mangled by the router, but return packets go directly from server to client. The client expects the reply from the router, sees some spurious traffic from the server, and drops the traffic.
The netfilter list sees some variation of this question once every week or so. You're definitely not alone. =)
Another attempt to explain it:
https://lists.netfilter.org/pipermail/netfilter/2005-July/061636.html
Thanks for the pointer, it's working now. It was indeed the SNAT that was missing.
-- R.
Quoted 17 lines · curby .
Quoted 2 lines · Ricardo J. Méndez
But I 'm testing this from a desktop on the network, not the firewall itself. PREROUTING should apply to those packets, correct?
In that case, the problem you're seeing is exactly that which is discussed in the HOWTO link I posted last time. It's also explained by Jason's link. The idea is that packets TO the server are indeed being correctly mangled by the router, but return packets go directly from server to client. The client expects the reply from the router, sees some spurious traffic from the server, and drops the traffic.
The netfilter list sees some variation of this question once every week or so. You're definitely not alone. =)
Another attempt to explain it:
https://lists.netfilter.org/pipermail/netfilter/2005-July/061636.html
Signature · 2 lines
Ricardo J. Méndez http://ricardo.strangevistas.net/
Quoted 7 lines
Quoted 2 lines
iptables -t nat -A PREROUTING -d 1.2.3.4 -p tcp --dport 80 -j DNAT --to 192.168.1.202
The roule should look like this:
iptables -t nat -A PREROUTING -d 1.2.3.4 -p tcp --dport 80 -j DNAT --to-destination 192.168.1.202
Or just --to-dest ;-)
Jan Engelhardt
Quoted 23 lines · Ricardo J. Méndez
Hi,
I've got a network setup where the internal router is a Linux box running iptables. External interface is eth0, internal eth1. I'm attempting to forward an external IP address (say, 1.2.3.4) to an internal machine.
The rule I added is:
iptables -t nat -A PREROUTING -d 1.2.3.4 -p tcp --dport 80 -j DNAT --to 192.168.1.202
However, attempting to
telnet 1.2.3.4 80
does not work. It's clear that the rule is being applied, because the web server running on the external machine is not responding unless I telnet from the router itself, but unfortunately I'm not getting into 192.168.1.202 either. Attempting to
telnet 192.168.1.202 80
Quoted 11 lines
does work as expected.
What am I missing? Any pointers are welcome. Thanks,
Ricardo J. Méndez
http://ricardo.strangevistas.net/
Whats the Gateway set to on 192.168.1.202 80?
Quoted 4 lines · Patrick Nelson
Quoted 1 line
Whats the Gateway set to on 192.168.1.202 80?
192.168.1.202's gateway is the same as the rest of the network - the linux box doing the routing.
Ricardo J. Méndez
http://ricardo.strangevistas.net/
Quoted 4 lines · Ricardo J. Méndez
192.168.1.202's gateway is the same as the rest of the network - the linux box doing the routing
Is that the 1.2.3.4 system? I think it would need to be.
Quoted 21 lines · Ricardo J. Méndez
Hi,
I've got a network setup where the internal router is a Linux box running iptables. External interface is eth0, internal eth1. I'm attempting to forward an external IP address (say, 1.2.3.4) to an internal machine.
The rule I added is:
iptables -t nat -A PREROUTING -d 1.2.3.4 -p tcp --dport 80 -j DNAT --to 192.168.1.202
However, attempting to
telnet 1.2.3.4 80
does not work. It's clear that the rule is being applied, because the web server running on the external machine is not responding unless I telnet from the router itself, but unfortunately I'm not getting into 192.168.1.202 either. Attempting to
Quoted 5 lines
telnet 192.168.1.202 80
does work as expected.
What am I missing? Any pointers are welcome. Thanks,
http://marc.theaimsgroup.com/?l=netfilter&m=112110769302639&w=2
-j
Signature · 1 line
Jason Opperisano <[email protected]>