DNAT question..
Dear all,
I describe first about my network:
INTERNET --- eth0 [ NAT+Firewall Linux ] eth1 --- LAN
eth0 would be my public ip = 211.1.1.10
eth1 would be my private ip = 192.168.1.1
On NAT+Firewall Linux i applied this rule:
iptables -t nat -A PREROUTING -p tcp -d 211.1.1.10 --dport 80 -j DNAT --to 192.168.1.2:80
This is rule for redirecting to local webserver.
I tried to test it from outside network (internet), surf to http://211.1.1.10
and it succeed.
But from inside LAN network (192.168.1.3) i am unable to browse to
http://211.1.1.10
Let me know how to make this also worked from inside LAN Network. Thanks ..
Regards,
Rio Martin.
Signature · 1 line
Don't cook tonight -- starve a rat today!
Quoted 8 lines · Rio Martin.
Dear all,
I describe first about my network:INTERNET --- eth0 [ NAT+Firewall Linux ] eth1 --- LAN
eth0 would be my public ip = 211.1.1.10
eth1 would be my private ip = 192.168.1.1
Quoted 6 lines
On NAT+Firewall Linux i applied this rule:
iptables -t nat -A PREROUTING -p tcp -d 211.1.1.10 --dport 80 -j DNAT --to 192.168.1.2:80 This is rule for redirecting to local webserver.I tried to test it from outside network (internet), surf to http://211.1.1.10 and it succeed. But from inside LAN network (192.168.1.3) i am unable to browse to http://211.1.1.10
You need to SNAT internal connections so that replies go via the firewall instead of directly to the client, otherwise the firewall cannot reverse the DNAT and the client drops the reply packet.
Try this rule:
iptables -t nat -A POSTROUTING -p tcp -s 192.168.1.0/24 -d 192.168.1.2 --dport 80 -j SNAT --to 192.168.1.1
Signature · 2 lines
Philip Craig - [email protected] - http://www.SnapGear.com SnapGear - Custom Embedded Solutions and Security Appliances
Quoted 14 lines · you
Quoted 5 lines · Rio Martin.
Dear all,
I describe first about my network:
INTERNET --- eth0 [ NAT+Firewall Linux ] eth1 --- LAN eth0 would be my public ip = 211.1.1.10
eth1 would be my private ip = 192.168.1.1Quoted 8 lines
On NAT+Firewall Linux i applied this rule:
iptables -t nat -A PREROUTING -p tcp -d 211.1.1.10 --dport 80 -j DNAT --to 192.168.1.2:80
This is rule for redirecting to local webserver.
I tried to test it from outside network (internet), surf to
http://211.1.1.10 and it succeed.
But from inside LAN network (192.168.1.3) i am unable to browse to
http://211.1.1.10
Quoted 6 lines
You need to SNAT internal connections so that replies go via the firewall instead of directly to the client, otherwise the firewall cannot reverse the DNAT and the client drops the reply packet. Try this rule:
iptables -t nat -A POSTROUTING -p tcp -s 192.168.1.0/24 -d 192.168.1.2 --dport 80 -j SNAT --to 192.168.1.1
i dont know, i tried but it still wont connect to webserver. Connection Refused.
Regards,
Rio Martin.
Signature · 3 lines
You can measure a programmer's perspective by noting his attitude on the continuing viability of FORTRAN. -- Alan Perlis
Hi Rio,
Quoted 9 lines
Quoted 6 lines
You need to SNAT internal connections so that replies go via the firewall instead of directly to the client, otherwise the firewall cannot reverse the DNAT and the client drops the reply packet. Try this rule:
iptables -t nat -A POSTROUTING -p tcp -s 192.168.1.0/24 -d 192.168.1.2 --dport 80 -j SNAT --to 192.168.1.1i dont know, i tried but it still wont connect to webserver. Connection Refused.
Is it possible that an earlier rule in the POSTROUTING chain is overriding this one? Could you try:
iptables -t nat -I POSTROUTING -s 192.168.1.0/24 -d 192.168.1.2 -p tcp --dport 80 -j MASQUERADE
If that doesn't work, please send your ruleset (iptables -L -n -v; iptables -t nat -L -n -v) and tcpdump of packets on the internal interface of your firewall when you try to connect.
Cheers, Chris.
Signature · 4 lines
___ __ _ / __// / ,__(_)_ | Chris Wilson -- UNIX Firewall Lead Developer | / (_ / ,\/ _/ /_ \ | NetServers.co.uk http://www.netservers.co.uk | \ _//_/_/_//_/___/ | 21 Signet Court, Cambridge, UK. 01223 576516 |
Hi Rio,
I think the problem is in the destination IP address, you have to use the
external IP, so i think the rule should be:
iptables -t nat -A POSTROUTING -p tcp -s 192.168.1.0/24 -d 211.1.1.10
--dport 80 -j SNAT --to 192.168.1.1
Hope this help
Federico.
Quoted 28 lines · Chris Wilson
Hi Rio,
Quoted 9 lines
Quoted 6 lines
You need to SNAT internal connections so that replies go via the firewall instead of directly to the client, otherwise the firewall cannot reverse the DNAT and the client drops the reply packet. Try this rule:
iptables -t nat -A POSTROUTING -p tcp -s 192.168.1.0/24 -d 192.168.1.2 --dport 80 -j SNAT --to 192.168.1.1i dont know, i tried but it still wont connect to webserver. Connection Refused.
Is it possible that an earlier rule in the POSTROUTING chain is overriding this one? Could you try:
iptables -t nat -I POSTROUTING -s 192.168.1.0/24 -d 192.168.1.2 -p tcp --dport 80 -j MASQUERADEIf that doesn't work, please send your ruleset (iptables -L -n -v; iptables -t nat -L -n -v) and tcpdump of packets on the internal interface of your firewall when you try to connect.
Cheers, Chris.
--
___ __ _/ __// / ,__(_)_ | Chris Wilson -- UNIX Firewall Lead Developer | / (_ / ,\/ _/ /_ \ | NetServers.co.uk http://www.netservers.co.uk | \ _//_/_/_//_/___/ | 21 Signet Court, Cambridge, UK. 01223 576516 |
Quoted 4 lines · Federico
I think the problem is in the destination IP address, you have to use the
external IP, so i think the rule should be:
iptables -t nat -A POSTROUTING -p tcp -s 192.168.1.0/24 -d 211.1.1.10
--dport 80 -j SNAT --to 192.168.1.1
Don't think so. In POSTROUTING chain, DNAT has already occured, then original destination (211.1.1.10) has already been changed to 192.168.1.2.
Problem must sit elsewhere (next to the truth out there) ;)
Signature · 2 lines
http://www.netexit.com/~sid/ PGP KeyID: 157E98EE FingerPrint: FA62226DA9E72FA8AECAA240008B480E157E98EE
Not quite understanding DNAT
In reply to Rio Martin.I have set up a very basic firewall for our system.
We have 126 addresses to be used to/from the outside world (204.48.178.0/25) and are using 10.x numbers on the inside.
It is working almost as I expected except for the following. The DNAT connections come into the system fine but are seen as originating from the eth0 interface rather than their eth0:x interface. So, when attaching to a linux cpu with ssh I am needing to place the ip# for the eth0 interface in the hosts.allow file rather than the much more restrictive eth0:x ip#. Can it be set up so the connection is between the external eth0:x ip# and its linked internal ip#?
Any help or suggestions would be greatly appreciated.
Thanks
============ Start iptables script ================ #!/bin/sh/root/bin/NatReset
# First the "outside" eth0 interface on the firewall
/sbin/ifconfig eth0 204.48.178.2 netmask 255.255.255.128 \
broadcast 204.48.178.127 up### Now add aliases to eth0 to users/hosts from the outside.
/sbin/ifconfig eth0:3 204.48.178.3 netmask 255.255.255.128 \
broadcast 204.48.178.127 up
/sbin/ifconfig eth0:4 204.48.178.4 netmask 255.255.255.128 \
broadcast 204.48.178.127 up
/sbin/ifconfig eth0:4 204.48.178.5 netmask 255.255.255.128 \
broadcast 204.48.178.127 up### ethernet "eth1", i.e. the "inside" interface for the firewall
/sbin/ifconfig eth1 10.0.0.1 netmask 255.255.255.248 \
broadcast 10.0.0.7 up## Set up outside access to the mainframe
/sbin/iptables --table nat --append PREROUTING --destination 204.48.178.3 \
--jump DNAT --to 10.5.2.104## Set up outside access to a Windows 2000 cpu
/sbin/iptables --table nat --append PREROUTING --destination 204.48.178.4 \
--jump DNAT --to 10.5.2.105# Set up inside and outside 1 to 1 mapping for W2K user
/sbin/iptables --table nat --append PREROUTING --destination 204.48.178.5 \
--jump DNAT --to 10.5.2.107
/sbin/iptables --table nat --append POSTROUTING --source 10.5.2.107/32 \
--jump SNAT --to 204.48.178.5## Setup NAT from entire WAN to the outside world
/sbin/iptables --table nat --append POSTROUTING --source 0.0.0.0/0 \
--jump SNAT --to 204.48.178.2## Now set the genaral policies/sbin/iptables --policy INPUT DROP/sbin/iptables --policy FORWARD ACCEPT/sbin/iptables --policy OUTPUT DROP
echo 1 > /proc/sys/net/ipv4/ip_forward ============ End iptables script ================
"Experience is not what happens to you, it
is what you do with what happens to you"
-- Aldous Huxley (1894-1963)
Ashe Coutts ([email protected])
805.963.7751 Ext 260
Fax 805.884.1557
RE: Not quite understanding DNAT
Ethernet aliases - are just aliases - that means they are a different name for the same thing. So your eth0:x interface is actually eth0 to many services that run on linux. Netfilter (iptables) works perfectly well with aliases and you can specify rules with aliases.
It is the end server applications that are not very alias-friendly...FreeS/WAN is one of them - and like you said - SHH is one too.
-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of Coutts, Ashe (Testing Account)
Sent: Thursday, July 24, 2003 12:23 PM
To: [email protected]
I have set up a very basic firewall for our system.
We have 126 addresses to be used to/from the outside world (204.48.178.0/25)
and are using 10.x numbers on the inside.
It is working almost as I expected except for the following. The DNAT connections come into the system fine but are seen as originating from the eth0 interface rather than their eth0:x interface. So, when attaching to a linux
cpu with ssh I am needing to place the ip# for the eth0 interface in the hosts.allow file rather than the much more restrictive eth0:x ip#. Can it be set
up so the connection is between the external eth0:x ip# and its linked internal
ip#?
Any help or suggestions would be greatly appreciated.
Thanks
============ Start iptables script ================ #!/bin/sh/root/bin/NatReset
# First the "outside" eth0 interface on the firewall
/sbin/ifconfig eth0 204.48.178.2 netmask 255.255.255.128 \
broadcast 204.48.178.127 up### Now add aliases to eth0 to users/hosts from the outside.
/sbin/ifconfig eth0:3 204.48.178.3 netmask 255.255.255.128 \
broadcast 204.48.178.127 up
/sbin/ifconfig eth0:4 204.48.178.4 netmask 255.255.255.128 \
broadcast 204.48.178.127 up
/sbin/ifconfig eth0:4 204.48.178.5 netmask 255.255.255.128 \
broadcast 204.48.178.127 up### ethernet "eth1", i.e. the "inside" interface for the firewall
/sbin/ifconfig eth1 10.0.0.1 netmask 255.255.255.248 \
broadcast 10.0.0.7 up## Set up outside access to the mainframe/sbin/iptables --table nat --append PREROUTING --destination 204.48.178.3
\
--jump DNAT --to 10.5.2.104## Set up outside access to a Windows 2000 cpu/sbin/iptables --table nat --append PREROUTING --destination 204.48.178.4
\
--jump DNAT --to 10.5.2.105# Set up inside and outside 1 to 1 mapping for W2K user /sbin/iptables --table nat --append PREROUTING --destination 204.48.178.5
\
--jump DNAT --to 10.5.2.107
/sbin/iptables --table nat --append POSTROUTING --source 10.5.2.107/32
\
--jump SNAT --to 204.48.178.5## Setup NAT from entire WAN to the outside world /sbin/iptables --table nat --append POSTROUTING --source 0.0.0.0/0
\
--jump SNAT --to 204.48.178.2## Now set the genaral policies/sbin/iptables --policy INPUT DROP/sbin/iptables --policy FORWARD ACCEPT/sbin/iptables --policy OUTPUT DROP
echo 1 > /proc/sys/net/ipv4/ip_forward ============ End iptables script ================
"Experience is not what happens to you, it
is what you do with what happens to you"
-- Aldous Huxley (1894-1963)
Ashe Coutts ([email protected])
805.963.7751 Ext 260
Fax 805.884.1557
Re: Not quite understanding DNAT
In reply to Coutts, Ashe (Testing Account)Quoted 1 line · Ashe (Testing Account)
It is working almost as I expected except for the following. The DNAT connections come into the system fine but are seen as originating from the eth0 interface rather than their eth0:x interface. So, when attaching to a linux cpu with ssh I am needing to place the ip# for the eth0 interface in the hosts.allow file rather than the much more restrictive eth0:x ip#. Can it be set up so the connection is between the external eth0:x ip# and its linked internal ip#?
If all you are doing is DNATing, then the source address should be the real external source address, not eth0 *or* eth0:x.
Quoted 3 lines
## Setup NAT from entire WAN to the outside world
/sbin/iptables --table nat --append POSTROUTING --source 0.0.0.0/0 \ --jump SNAT --to 204.48.178.2
But here we see that you are SNATing everything. This is probably not what you want. I expect you only want to SNAT outgoing traffic:
## Setup NAT from entire WAN to the outside world
/sbin/iptables --table nat --append POSTROUTING --out-interface eth0 \
--jump SNAT --to 204.48.178.2With this rule, you should now place the real external hosts in your hosts.allow, rather than any IP address that belongs to the firewall.
Signature · 2 lines
Philip Craig - [email protected] - http://www.SnapGear.com SnapGear - Custom Embedded Solutions and Security Appliances
Re: Not quite understanding DNAT
In reply to Coutts, Ashe (Testing Account)Hi Ashe,
Quoted 11 lines
I have set up a very basic firewall for our system.
We have 126 addresses to be used to/from the outside world (204.48.178.0/25) and are using 10.x numbers on the inside.It is working almost as I expected except for the following. The DNAT connections come into the system fine but are seen as originating from the eth0 interface rather than their eth0:x interface. So, when attaching to a linux cpu with ssh I am needing to place the ip# for the eth0 interface in the hosts.allow file rather than the much more restrictive eth0:x ip#. Can it be set up so the connection is between the external eth0:x ip# and its linked internal ip#?
You could try:
route add <internal-server-10.0.0.x> dev eth0 \ gw <address-of-eth0:x>
Using an address of your own box as the gateway of a route will cause locally-generated traffic going down that route to come from that address, instead of the default address on the device. This should mean that the masquerading uses that address too, but I haven't tested it.
Cheers, Chris.
Signature · 4 lines
___ __ _ / __// / ,__(_)_ | Chris Wilson -- UNIX Firewall Lead Developer | / (_ / ,\/ _/ /_ \ | NetServers.co.uk http://www.netservers.co.uk | \ _//_/_/_//_/___/ | 21 Signet Court, Cambridge, UK. 01223 576516 |
Re: Not quite understanding DNAT
Quoted 7 lines · Chris Wilson
You could try:
route add <internal-server-10.0.0.x> dev eth0 \ gw <address-of-eth0:x>Using an address of your own box as the gateway of a route will cause locally-generated traffic going down that route to come from that address, instead of the default address on the device. This should mean that the masquerading uses that address too, but I haven't tested it.
I've just tested this, it does not work as I was expecting.
Therefore, you can use iproute2 to achieve this kind of behaviour. You can specify to use an arbitrary local IP as source for a given route. Ashe, you should try this :
ip route add $INSERV dev eth0 src $SRCIP
I use this quite often on net2net VPN using FreeS/WAN to force gateways to use their private IP when communicating through the tunnel.
Signature · 2 lines
http://www.netexit.com/~sid/ PGP KeyID: 157E98EE FingerPrint: FA62226DA9E72FA8AECAA240008B480E157E98EE