3 way masquerade

I have a redhat 6.1 machine that currently does NAT using IPCHAINS and IP Masquerade between two networks. It is the gateway for the internal network

eth0 (internal net) 172.20.1.15    netmask 255.255.255.0
eth1 (external net) 172.16.131.254 netmask 255.255.248.0

I need to add a ADSL connection so the internal network can access the internet and would like to do so by adding another NIC to this machine. I will be using a single fixed IP address.

eth2 (the internet) 2x4.25x.2xx.x  netmask 255.255.255.0

I have all three NIC's up and running. Looking aroung the web all the examples for 3 way systems I find are based on the DMZ concept which is not what I am looking for. I want the internal network (eth0)to be able to access both the external network (eth1) and the internet (eth2) primarily for http and mail. I DON'T want any unsolicited stuff coming into the internal network from either eth1 or eth2. I also don't want the external net (eth1) to be able to access the internet (eth2) or to be subjected to unsolicited stuff from the internet (eth2)

Thanks
LVL 7
lewisgAsked:
Who is Participating?
 
dcavanaughConnect With a Mentor Commented:
I screwed up!  It should be:

route add default eth2

Having  "default" and "0.0.0.0" was redundant (not to mention erroneous), having "netmask 0.0.0.0" is optional.

Specifying the gateway "gw x.x.x.x" is also optional.   If you were to include it, the command would be:

route add default gw x.x.x.x eth2

Where x.x.x.x is your ISP gateway.
0
 
lewisgAuthor Commented:
Edited text of question.
0
 
lewisgAuthor Commented:
Edited text of question.
0
Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

 
dcavanaughCommented:
Let's start with routing:

route add default 0.0.0.0 netmask 0.0.0.0 eth2
route add -net 172.20.1.0 netmask 255.255.255.0 eth0
route add -net 172.16.131.0 netmask 255.255.248.0 eth1

Check to be sure you don't have any extraneous routes that are in conflict with the 3 shown above.

Now we move on to masquerading, but only for the internal network:

/sbin/ipchains -A forward -i eth2 -s 172.20.1.0/24 -d 0.0.0.0/0 -j MASQ

Regarding your desire to filter "unsolicited stuff", I suggest you identify the port numbers you want to protect.  For example, let's say you want to block port 80 (http) access from the external net to the internal net, in which case you could try this:

/sbin/ipchains -A forward -s  172.16.131.0/21 -d 172.20.1.0/24 80 -j DENY

You should be able to modify this command to block access to whatever ports you want to protect on either the internal or external network, assuming this Linux box is the sole router between the two.  Where you see port 80, you can specify a range of ports in X:Y format.  

I suggest adding all of this stuff to a custom script file that you call yourself out of /etc/rc.d/rc.local.  Mine is /etc/rc.d/rc.localnet
When you upgrade, it's a one-liner to replace the call in /etc/rc.d/rc.local.

0
 
dcavanaughCommented:
Did it work?
0
 
lewisgAuthor Commented:
Sorry I have not been more prompt on this question... Other stuff got to be "more important".

When I enter:
route add default 0.0.0.0 netmask 0.0.0.0 eth2
I get back a nasty:
Usage: inet_route [-vF] del {-host|-net} Target[/prefix] [gw Gw] [metric M] [[de
v] If]
       inet_route [-vF] add {-host|-net} Target[/prefix] [gw Gw] [metric M]
                              [netmask N] [mss Mss] [window W] [irtt I]
                              [mod] [dyn] [reinstate] [[dev] If]
       inet_route [-vF] add {-host|-net} Target[/prefix] [metric M] reject
       inet_route [-FC] flush      NOT supported                      

Is this command attempting to add a route for all packets not covered in the next two "route add -net" statements? If so would this be more appropriate?

route add default gw 2x4.25x.2xx.1 eth2

where 2x4.25x.2xx.1 is the ISP's default gateway.

Thanks!
0
 
lewisgAuthor Commented:
Thanks for the help! I think I finally got it. The "route add default eth2" appears to be the only one needed since the others routes appear to already exist.

After much study I came up with the following for IPCHAINS. If you see a problem please let me know.

#!/bin/sh
#
#      rc.firewall for xxxxxxx 2/18/0

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

/sbin/ipchains -F input
/sbin/ipchains -P input REJECT
/sbin/ipchains -F output
/sbin/ipchains -P output ACCEPT
/sbin/ipchains -F forward
/sbin/ipchains -P forward REJECT

/sbin/ipchains -M -S 7200 10 60

/sbin/ipchains -A input -s 0.0.0.0/0.0.0.0 -i lo -j ACCEPT
/sbin/ipchains -A input -s 0.0.0.0/0.0.0.0 -i eth0 -j ACCEPT

/sbin/ipchains -A input -s 0.0.0.0/0.0.0.0 -p 1 -j ACCEPT
/sbin/ipchains -A input -s 172.20.1.0/255.255.255.0 -i eth1 -j DENY
/sbin/ipchains -A input -s 172.20.1.0/255.255.255.0 -i eth2 -j DENY

/sbin/ipchains -A input -s 0.0.0.0/0.0.0.0 -d 0.0.0.0.0/0.0.0.0 1024:5999 -i eth1 -p 6 -j ACCEPT
/sbin/ipchains -A input -s 0.0.0.0/0.0.0.0 -d 0.0.0.0.0/0.0.0.0 6002:65535 -i eth1 -p 6 -j ACCEPT
/sbin/ipchains -A input -s 0.0.0.0/0.0.0.0 -d 0.0.0.0.0/0.0.0.0 1024:65535 -i eth1 -p 17 -j ACCEPT
/sbin/ipchains -A input -s 0.0.0.0/0.0.0.0 -d 0.0.0.0.0/0.0.0.0 53:53 -i eth1 -p 6 -j ACCEPT
/sbin/ipchains -A input -s 0.0.0.0/0.0.0.0 -d 0.0.0.0.0/0.0.0.0 53:53 -i eth1 -p 17 -j ACCEPT
/sbin/ipchains -A input -s 0.0.0.0/0.0.0.0 -d 0.0.0.0.0/0.0.0.0 25:25 -i eth1 -p 6 -j ACCEPT

/sbin/ipchains -A input -s 0.0.0.0/0.0.0.0 -d 0.0.0.0.0/0.0.0.0 1024:5999 -i eth2 -p 6 -j ACCEPT
/sbin/ipchains -A input -s 0.0.0.0/0.0.0.0 -d 0.0.0.0.0/0.0.0.0 6002:65535 -i eth2 -p 6 -j ACCEPT
/sbin/ipchains -A input -s 0.0.0.0/0.0.0.0 -d 0.0.0.0.0/0.0.0.0 1024:65535 -i eth2 -p 17 -j ACCEPT
/sbin/ipchains -A input -s 0.0.0.0/0.0.0.0 -d 0.0.0.0.0/0.0.0.0 53:53 -i eth2 -p 6 -j ACCEPT
/sbin/ipchains -A input -s 0.0.0.0/0.0.0.0 -d 0.0.0.0.0/0.0.0.0 53:53 -i eth2 -p 17 -j ACCEPT
/sbin/ipchains -A input -s 0.0.0.0/0.0.0.0 -d 0.0.0.0.0/0.0.0.0 25:25 -i eth2 -p 6 -j ACCEPT

/sbin/ipchains -A forward -s 172.20.1.0/24 -j MASQ

0
 
dcavanaughCommented:
Those rules look good to me; no obvious problems. Of course, the real test is how it works in action.  

If you are interested, there is a product called cheops, which you can get from www.rpmfind.net or www.marko.net .  This program will map an entire subnet for you.   You can also browse the MIB of any SNMP-managable stuff you might have (including Linux boxes with SNMP enabled).  

One of the provisions of the program is to do a port scan, which would help test your filters.  You could set this up on a crappy little 486 box, and use it on either of your networks to try a portscan on your masquerading box (or any valid IP address, for that matter).
0
 
lewisgAuthor Commented:
Did the install today. Everything went well until I hit a machine that does Point to Point Tunneling Protocol. It would connect then time out on verifying username and password. I checked with tech support at the origin of the tunnel and they speculated that the problem was most likely my firewall not passing PPTP packets. I checked the /etc/protocols file and can find no reference to PPTP.

What do you think...
0
 
dcavanaughCommented:
Which network has the PPTP machine?  

I think it's purely a routing issue.  If Linux is trying access networks that are connected via the PPTP machine, then you need a route to the remote PPTP network with a gateway that specifies the ethernet address of the PPTP machine (which needs to be in one of the subnets that Linux is directly connected to).

To really pursue the issue, I need to know what IP addresses the PPTP machine has for it's ethernet address and the interface address of the ppp interface as well as the network address of the PPTP remote network, along with the display of the routing table.  If you can produce all that, I can tell you what has to happen to make it all work.

I have a Linux box that makes a PPTP connection to an NT server at my office.  I had to masquerade the PPTP network because the hosts on the remote network did not have a route to return packets to my private network.  By masquerading, I made it look like all the activity came from the ppp interface on the Linux box (that was in the same subnet as the remote PPTP network, after all.  
0
 
lewisgAuthor Commented:
The problem is that a machine on the  internal net (eth0 172.20.1.x) cannot connect to a PPTP server(?) across the Internet (eth3 -> ADSL). This application is web browser on an internal machine accessing remote confidential records via the Internet.

I don't have all the numbers available right now. However there are no ppp interfaces involved. I am a little confused...
0
 
dcavanaughCommented:
OK, that explains a little more.  The PPTP connection doesn't work because the internal machine does not have a "real" IP address.  Because it's connection to the Internet is masqueraded, all outgoing packets have the address of eth2.

PPTP does not masquerade very well, but then again, it doesn't really have to.

Depending on how you feel about security in general, you <could> have the Linux box make the PPTP connection to this PPTP server, and then add a static route to the network that becomes reachable via PPTP.  The Linux box is everyone's default gateway anyway, so static routes on that machine will allow anyone to reach the remote PPTP network.  You can use Ipchains to tighten the forwarding so that only the right machine can reach the PPTP network.  Let me know if you want more information on setting this up.

One question I would ask: Is the remote PPTP server the same machine (web server) that you need to reach?  Or is it acting as a router to enable access to a network that includes the web server in question?  The configuration is a little easier if the PPTP server is also the web server.

There is probably a way to make this work with ipmasqadm and autofw, but my experience is with using the Linux box to handle all of the tricky stuff that works better with a "real" IP address and leaving the masquerading to the common IP applications (web,pop3,ftp,telnet,etc.)
0
 
lewisgAuthor Commented:
I think the remote PPTP server is also the webserver. It is no big deal if everyone on the internal network can reach the PPTP server. The remote PPTP server appears to have a static IP. I think I already tried the obvious:

/sbin/ipchains -A input -s 1.2.3.4 -i eth2 -j ACCEPT
(where 1.2.3.4 is the IP of the PPTP server)

I read somewhere that PPTP uses TCP on port 1723 and IP on port 47. However neither of these appear in /etc/services. Is that a problem.

The internal network is all W95 and private IP's

Thanks for all of your help with this. You are a wizard!
0
 
dcavanaughCommented:
To make this work with Linux, you would first set up the /etc/ppp/chap-secrets file.  If the PPTP server is going to authenticate you as username "BCLINTON" and password "funwithmonica" then the file would look like this:

# Secrets for authentication using CHAP
# client  server  secret  IP addresses
BCLINTON      *   funwithmonica

Next, you need PPTP CLIENT software for Linux, available at http://www.moretonbay.com/vpn/pptp.html This site is a great source of VPN information.  I learned a great deal from it.

In this example, I have a local private network that is 192.168.1.0/24, My PPTP server is at w.x.y.z and offers a route to the 10.1.1.0/24 network.  The script (run as root) looks like this:

/sbin/ifconfig ppp0 down
/sbin/route del -net 10.1.1.0
rm -rf /var/run/pptp/*
/usr/bin/pptp w.x.y.z name BCLINTON debug netmask
sleep 5
/sbin/route add -net 10.1.1.0 netmask 255.255.255.0 ppp0
ipchains -A forward -i ppp0 -s 192.168.1.0/24 -d 10.1.1.0/24 -j MASQ

If anything unusual happens, the results will be somewhere in /var/log, according to whatever you have specified in /etc/syslog.conf (try /var/log/messages).

Following my example, the script runs and makes the PPTP connection.  At that point, my entire 192.168.1.0 local network can connect anywhere on the 10.1.1.0 private network.  

Notice the use of IP masquerade on the ipchains forwarding to the PPTP network.  Those IP addresses on the remote PPTP network have no routing information that would get packets delivered back to the private network that originated them, hence the need for masquerade.  This way, it looks like all this activity originates from an address that is ppp0 (which picks up an address in the PPTP network's subnet, so routing is not a problem).  

Other people may have ideas on allowing the PPTP traffic to be originated on the private network and forwarded  via  Linux.  You might want to post that as a new question if you want to explore the concept.
0
All Courses

From novice to tech pro — start learning today.