|
Ipchains: Easy Links to the Net
Multiple Machines, A Single ConnectionNow that the Internet has become a ubiquitous presence in our society, it seems only reasonable that every machine should have Internet access. And with a couple of Ethernet cards, some well-chosen software, and a little bit of brainpower, many people can manage to share a single Internet connection among more than one PC, whether that connection be a PPP dial-up connection, a DSL line, or a cable modem. In this case, the well-chosen software is ipchains. As described by its author, Paul Russell, ipchains "is an update to [and hopefully an improvement upon] the 2.0 Linux packet-filtering code, for the 2.2 Linux kernel." In a nutshell, it's a pretty neat way to make a firewall out of a 2.2 kernel Linux box, as well as providing access for multiple PCs using a single Internet connection. In this article, we will be talking about how to setup IP masquerading, allowing transparent proxying to the Internet. In order to get started with ipchains, you're going need a Linux box (in this case, we'll be using a freshly installed Slackware 4.0 distribution), preferably two NIC cards (one can be a PPP dialup interface), a copy ofipchains, and probably a copy of the source code for your kernel. Chances are most distributions of Linux should come preinstalled with ipchains; however, it can also be downloaded from here. A copy of the Linux kernel source may already be installed in /usr/src/linux. If you don't see a copy there, you can pick up a copy from here. At the time of this writing, the latest version of ipchains is 1.3.9 and the latest 2.2 kernel is 2.2.13. If you're trying to set up ipchains on Linux 2.0, you're going to need quite a bit more kernel configuration prior to setting up ipchains, a process that is outside the scope of this article. For the purpose of this article, we're going to assume you're doing everything as root, since most things here require it anyway.
Kernel ChangesBefore you can actually set up ipchains, you may have to recompile your kernel to support IP masquerading. But fear not! Some distributions nowadays may already have IP masquerading enabled in their kernels. In our distribution of Slackware 4.0, the IP masquerading settings were already enabled in the 2.2.6 kernel built and included with the distribution. If you want to check to see if you already have IP masquerading enabled, simply check for the existence of the /proc/sys/net/ipv4/ip_forward file: # cd /proc/sys/net/ipv4 The ip_forward file size being 0 is normal. If this file exists, your kernel is already set to do IP masquerading. If you don't see this, you're going to have to recompile your kernel. Recompiling your kernel isn't a terribly easy task, and we won't cover every step here (check your system documentation for more information). In brief, you will want to enable the following options: Prompt for development and/or incomplete code/drivers
(CONFIG_EXPERIMENTAL) Remember, as general rule when compiling a new kernel, keep a back-up copy of your old kernel and maybe even a Linux bootdisk.
Starting IpchainsIn order to have IP masquerading configured and started every system boot, create a start-up script or an rc.d script. Every time a system starts up, a set of scripts residing in /etc/rc.d/ are run. In these scripts are essential system services like the telnet daemon, ftp daemon, mount daemon and more. For our setup, eth0 will be connected to the internal network and eth1 will be connected to the Internet. If using a dial-up connection, such as ppp0, make sure to enable the line for dynaddr below. Here is a sample /etc/rc.d/rc.firewall file, where we'll keep all our IP masquerading startup commands. #!/bin/sh # The following are custom modules, which allows use of echo "1" > /proc/sys/net/ipv4/ip_forward
# Enables IP Forwarding! Important! /sbin/ipchains -M -S 7200 10 160 # Set timeouts on masquerading sessions. /sbin/ipchains -P forward DENY # By default, deny packet forwarding /sbin/ipchains -N infilt # create a new
"chain" named infilt Before adding this to our startup scripts, we will want to test it. To do this, simply execute /etc/rc.d/rc.firewall. If we see no output, it's pretty safe to say that the commands worked. To configure the client side, simply set the default gateway to that of your Linux machine. There are several tools available to monitor your IP masquerader. One of them is netstat. This tool will give a quick rundown of who is masquerading to where. Output may be similar to something like this: $ netstat -M Another tool is ipchains -L -v. This will give some overall statistics on the IP masquerading connection, including some basic bandwidth usage reports. So what's so cool about this? You can maintain a single Internet connection for multiple users on multiple operating systems, using Linux as the gateway to the Internet. Plus, because ipchains and Linux itself are low cost or free, creating and maintaining this setup is much easier, and in many cases more secure, than a more expensive Windows solution.
|