IP masquerading and second ISP line questions
Hello all,
I am running iptables on my fedora box to do ip masquerading for my internal network as well as 1 to 1 NAT for two windows terminal servers. Here is a general layout of my network:
INTERNET
|
(serial interface)
Cisco router
(real ip (1.2.3.4 on fast ethernet interface)
|
(eth0 with real ip (1.2.3.5))
Linux Box w/ IP Tables --also runs squid, httpd, etc.
(eth1 with internal ip (192.168.0.1)
|
Private Network (192.168.0.0/27)
(included in this network are two Windows terminal server boxes. They are 192.168.0.2 and 192.168.0.100. Both of these have 1:1 NATS)
Here is my iptables-config file:
# Generated by iptables-save v1.2.9 on Wed May 12 08:19:27 2004 *nat
:PREROUTING ACCEPT [924:149516]
:POSTROUTING ACCEPT [434:32409]
:OUTPUT ACCEPT [236:14561]
-A PREROUTING -p tcp -m tcp --dport 139 -j DROP
-A PREROUTING -p icmp -j DROP
-A PREROUTING -d 1.2.3.6 -i eth0 -j DNAT --to-destination 192.168.0.100 -A PREROUTING -d 1.2.3.7 -i eth0 -j DNAT --to-destination 192.168.0.2 -A PREROUTING -i eth1 -p tcp -m tcp -d ! 1.2.3.5 --dport 80 -j REDIRECT --to-ports 3128
-A POSTROUTING -s 192.168.0.100 -o eth0 -j SNAT --to-source 1.2.3.6 -A POSTROUTING -s 192.168.0.2 -o eth0 -j SNAT --to-source 1.2.3.7 -A POSTROUTING -o eth0 -j MASQUERADE
COMMIT
# Completed on Wed May 12 08:19:27 2004
# Generated by iptables-save v1.2.9 on Wed May 12 08:19:27 2004 *filter
:INPUT DROP [67:5874]
:FORWARD ACCEPT [34716:47614943]
:OUTPUT ACCEPT [5645:2441647]
-A INPUT -p udp -m udp --dport 22 -j ACCEPT
-A INPUT -p tcp -m tcp --dport 22 -j ACCEPT
-A INPUT -p tcp -m tcp --dport 53 -j ACCEPT
-A INPUT -p udp -m udp --dport 53 -j ACCEPT
-A INPUT -p tcp -m multiport --dports 80,443 -j ACCEPT
-A INPUT -i eth0 -m state --state RELATED,ESTABLISHED -j ACCEPT -A INPUT -s 192.168.0.0/255.255.255.0 -j ACCEPT
-A INPUT -s 127.0.0.1 -d 127.0.0.1 -i lo -j ACCEPT
-A FORWARD -i eth1 -j ACCEPT
COMMIT
# Completed on Wed May 12 08:19:27 2004
I have a few questions that I hope somebody might be able to help me out with.
#1, I am using a Checkpoint SecureClient to log into my VPN at my office (not on one of the two terminal servers). Since I switched to iptables to handle my ip masquerading, it has periodically booted me out of my network forcing me to re-authenticate. I had heard that there were more than one ways to do IP sharing/masquerading. Is the -A POSTROUTING -o eth0 -j MASQUERADE the preferred method to do this?
#2, I hope this is feasible--it is kind of a tricky one. I have a third interface on my iptables box (not indicated on my diagram) that is connected to a cable modem (as a backup). Since it is just sitting there all day long not doing anything, I would love to use it from a few of my boxes to handle my bittorrent/ftp traffic. Is it possible to do a similar thing to what I am doing with my squid proxy to automatically route bittorrent or ftp traffic through eth2 instead of the default eth0? Could somebody shed some light on that one for me?
Props to everybody on the netfilter team. This firewall is awesome! I have done quite a bit with Cisco PIX firewalls, but as I get more and more familiar with iptables I realize that in many places where PIXes have been implemented that an iptables firewall could do the job just fine. Keep up the good work!
Thanks in advance for what ever help anybody can give! Ryan Hatch
PS. Any other tips/advice/suggestions on no-no's or things I could do to improve what I have would be greatly appreciated! Thanks!
------------------------------------------
Information wants to be anthropomorphized.
------------------------------------------
Quoted 7 lines · Ryan Hatch
Hello all,
I am running iptables on my fedora box to do ip masquerading for my internal network as well as 1 to 1 NAT for two windows terminal servers.
#1, I am using a Checkpoint SecureClient to log into my VPN at my office (not on one of the two terminal servers). Since I switched to iptables to
Switched from what? (Just out of interest, I don't think it matters to this
question.)
Quoted 4 lines
handle my ip masquerading, it has periodically booted me out of my network forcing me to re-authenticate. I had heard that there were more than one ways to do IP sharing/masquerading. Is the -A POSTROUTING -o eth0 -j MASQUERADE the preferred method to do this?
It's generally recommended that if you have a static IP address (which you appear to have), then you use SNAT instead of MASQUERADE, however this is purely for a (very modest) performance improvement; it doesn't change the functionality in any way.
If you actually have a dynamic IP address on your external interface, then you have to use MASQUERADE, but this fact would also be the cause of you losing authentication on the SecureClient as well, because it would suddenly find itself talking to a new address from time to time.
Quoted 8 lines
#2, I hope this is feasible--it is kind of a tricky one. I have a third interface on my iptables box (not indicated on my diagram) that is connected to a cable modem (as a backup). Since it is just sitting there all day long not doing anything, I would love to use it from a few of my boxes to handle my bittorrent/ftp traffic. Is it possible to do a similar thing to what I am doing with my squid proxy to automatically route bittorrent or ftp traffic through eth2 instead of the default eth0? Could somebody shed some light on that one for me?
Yes. Set up another route using the iproute2 tools available from
http://lartc.org - for what you want, the best solution is probably to MARK the packets you want to go up the cable modem in netfilter, and then route the marked packets with the appropriate iproute2 tables.
Regards,
Antony.
Signature · 6 lines
Anyone that's normal doesn't really achieve much.
- Mark Blair, Australian rocket engineer
Please reply to the list;
please don't CC me.Quoted 5 lines
Quoted 5 lines
Hello all,
I am running iptables on my fedora box to do ip masquerading for my internal network as well as 1 to 1 NAT for two windows terminal servers.
Quoted 7 lines
Quoted 2 lines
#1, I am using a Checkpoint SecureClient to log into my VPN at my office (not on one of the two terminal servers). Since I switched to iptables
to
Switched from what? (Just out of interest, I don't think it matters to
this
question.)
I should have made that more clear...I switched from PIX!
Quoted 4 lines
Quoted 2 lines
handle my ip masquerading, it has periodically booted me out of my
network
Quoted 1 line
forcing me to re-authenticate. I had heard that there were more than
Quoted 9 lines
one
Quoted 2 lines
ways to do IP sharing/masquerading. Is the -A POSTROUTING -o eth0 -j MASQUERADE the preferred method to do this?
It's generally recommended that if you have a static IP address (which you appear to have), then you use SNAT instead of MASQUERADE, however this is purely for a (very modest) performance improvement; it doesn't change the functionality in any way.
So, in order to do this sort of static NATing, what sort of command would I use to to replace the -A POSTROUTING -o eth0 -j MASQUERADE? Would sensibily, it seems like I should do something like this:
-A POSTROUTING -s 192.168.0.0/24 -j SNAT -o eth1 --to-source 1.2.3.5
Is that more or less what you were talking about?
Quoted 6 lines
If you actually have a dynamic IP address on your external interface, then you
have to use MASQUERADE, but this fact would also be the cause of you losing
authentication on the SecureClient as well, because it would suddenly find itself talking to a new address from time to time.
Yeah, I actually do have a bunch of statics. I don't think that my SecureClient problem is a function of the IP addresses. I think that it has to do with NAT. From what I can tell, it is a common problem that many IPSec VPN clients have when working behind firewalls/routers using masquerading NAT. Its seems that the common workaround is to do UDP encapsulation--something that my particular client does not support. I might end up trying to do 1:1 on it.
Quoted 10 lines
Quoted 4 lines
#2, I hope this is feasible--it is kind of a tricky one. I have a third interface on my iptables box (not indicated on my diagram) that is connected to a cable modem (as a backup). Since it is just sitting
there
Quoted 2 lines
all day long not doing anything, I would love to use it from a few of my boxes to handle my bittorrent/ftp traffic. Is it possible to do a
similar
Quoted 2 lines
thing to what I am doing with my squid proxy to automatically route bittorrent or ftp traffic through eth2 instead of the default eth0?
Quoted 8 lines
Could
Quoted 1 line
somebody shed some light on that one for me?
Yes. Set up another route using the iproute2 tools available from
http://lartc.org - for what you want, the best solution is probably to MARK
the packets you want to go up the cable modem in netfilter, and then route the marked packets with the appropriate iproute2 tables.
Yeah, I've looked there....it seems like a slightly complex process. Perhaps a project for next weekend!
Thanks,
Ryan
Quoted 5 lines · Ryan Hatch
Quoted 4 lines
It's generally recommended that if you have a static IP address (which you appear to have), then you use SNAT instead of MASQUERADE, however this is purely for a (very modest) performance improvement; it doesn't change the functionality in any way.
Quoted 7 lines
So, in order to do this sort of static NATing, what sort of command would I use to to replace the -A POSTROUTING -o eth0 -j MASQUERADE? Would sensibily, it seems like I should do something like this:
-A POSTROUTING -s 192.168.0.0/24 -j SNAT -o eth1 --to-source 1.2.3.5
Is that more or less what you were talking about?
Exactly.
Quoted 7 lines
Yeah, I actually do have a bunch of statics. I don't think that my SecureClient problem is a function of the IP addresses. I think that it has to do with NAT. From what I can tell, it is a common problem that many IPSec VPN clients have when working behind firewalls/routers using masquerading NAT. Its seems that the common workaround is to do UDP encapsulation--something that my particular client does not support. I might end up trying to do 1:1 on it.
I'm not aware of this "common problem", however I only use IPsec (through NAT) in tunnel mode between networks, not in transport mode with a client-gateway arrangement.
Quoted 7 lines
Quoted 4 lines
Yes. Set up another route using the iproute2 tools available from
http://lartc.org - for what you want, the best solution is probably to MARK the packets you want to go up the cable modem in netfilter, and then route the marked packets with the appropriate iproute2 tables.Yeah, I've looked there....it seems like a slightly complex process. Perhaps a project for next weekend!
Yes. It looks slightly complex - but it isn't. You almost certainly have
all the tools you need already on your system (you just never typed the "ip" command before...)
Read about it, try it, and you'll find it's a lot easier than you think :)
Regards.
Antony.
Signature · 10 lines
In science, one tries to tell people
in such a way as to be understood by everyone
something that no-one ever knew before.
In poetry, it is the exact opposite.
- Paul Dirac
Please reply to the list;
please don't CC me.Quoted 3 lines · Antony Stone
I'm not aware of this "common problem", however I only use IPsec (through NAT) in tunnel mode between networks, not in transport mode with a client-gateway arrangement.
<FYI>
NAT obviously breaks IPSEC using AH header, and it also breaks transport mode ESP.
When you set transport mode ESP, you don't cipher packet header for the IPSEC destination (declared as IPSEC gateway) is the same than the encapsulated packet destination, so only IP payload is ESP encapsulated. For TCP/UDP checksum is computed against a pseudo header that includes IP source and destination, NAT breaks checksum for pseudo header, after ESP decasulation, has been modified. TCP is for the more affected as it is not very wise to desactivate checksum verification just like it is possible for UDP.
</FYI>
However, there's often a way to work aournd this kind of issue using a tunnel mode by adressing packets to an aliased IP.
Signature · 2 lines
http://www.netexit.com/~sid/ PGP KeyID: 157E98EE FingerPrint: FA62226DA9E72FA8AECAA240008B480E157E98EE
Quoted 2 lines
Quoted 2 lines
Hi! I'm your friendly neighbourhood signature virus. Copy me to your signature file and help me spread!