rameshpanuganty@myrealbox.com
Revision History | ||
---|---|---|
Revision v1 | 20 December 2001 | Revised by: rp |
This is the initial release. |
Copyright © 2001 Ramesh Panuganty. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.1 or any later version published by the Free Software Foundation; with no Invariant Sections, with no Front-Cover Texts, and with no Back-Cover Texts. A copy of the license can be found at the Free Software Foundation.
You need a NIC card one each on all your workstations (may be PCI, ISA, USB, wireless or built-int).
Iptables is actually a user interface tool and depends on the kernel implementation called netfilter. Netfilter includes support only for IPv4 and IPv6, and does not filter any other protocols. Hence if your system should run something like IPX, remember that the protocols other than IPv4 and IPv5 are not going to be filtered according to the iptables rules. User kerne 2.4.18 or above, if possible to have all the new features of netfilter.
Install the iptables software on your system (apt-get install iptables). Once you know that your kernel is configured with netfilter support, you need not worry about it at all. Just remember that iptables need the kernel support from netfilter.
Check if your kernel is configured for supporting iptables. Though most distributions include this support by default, do this quick test as root.
bash# modprobe ip_tables bash# lsmod | grep ip_tables |
If any of the above commands give an error or ip_tables doesn't show up in module listing, you must enable these options in the kernel configuration using make menuconfig or make xmenuconfig
Code maturity-level options for development and/or incomplete code/drivers
Network packet filtering in Networking options.
IP: Netfilter Configuration iin Networking options
select all these options as modules.
Table 1. Private IP Address assignments from RFC1918
IP Address Class | IP Address From | IP Address To | CIDR Notation | Subnet Mask |
---|---|---|---|---|
Class A | 10.0.0.0 | 10.255.255.255 | 10.0.0.0/8 | 255.0.0.0 |
Class B | 172.16.0.0 | 172.31.255.255 | 172.16.0.0/16 | 255.255.0.0 |
Class C | 192.168.0.0 | 192.168.255.255 | 192.168.0.0/24 | 255.255.255.0 |
auto eth0 iface eth0 inet static address 192.168.1.1 network 192.168.1.0 netmask 255.255.255.0 broadcast 192.168.1.255 |
auto eth0 iface eth0 inet dhcp auto eth1 iface eth1 inet static address 192.168.1.1 network 192.168.1.0 netmask 255.255.255.0 broadcast 192.168.1.255 |
Restart the network settings on your system by
bash# /etc/init.d/networking restart |
Create the file /etc/gateway.rules with the following initial ruleset,
/sbin/ipchains -M -S 7200 10 160 /sbin/ipchains -P input ACCEPT /sbin/ipchains -P output ACCEPT /sbin/ipchains -F input /sbin/ipchains -F output /sbin/ipchains -F forward /sbin/ipchains -P forward DENY /sbin/ipchains -A forward -i ppp0 -s 192.168.1.0/24 -j MASQ |
/sbin/iptables -F /sbin/iptables -t nat -F /sbin/iptables -t mangle -F #ignore if you get an error here /sbin/iptables -X #deletes every non-builtin chain in the table /sbin/iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT /sbin/iptables -A INPUT -m state --state NEW -i ! ppp0 -j ACCEPT # only if both of the above rules succeed, use /sbin/iptables -P INPUT DROP /sbin/iptables -A FORWARD -i ppp0 -o eth0 -m state --state ESTABLISHED,RELATED -j ACCEPT /sbin/iptables -A FORWARD -i eth0 -o ppp0 -j ACCEPT /sbin/iptables -t nat -A POSTROUTING -o ppp0 -j MASQUERADE /sbin/iptables -A FORWARD -i ppp0 -o ppp0 -j REJECT |
I am assuming that eth0 refers to the external interface and eth1 refers to the internal interface.
For users connecting to external network on ethernet & using ipchains:
/sbin/ipchains -M -S 7200 10 160 /sbin/ipchains -P input ACCEPT /sbin/ipchains -P output ACCEPT /sbin/ipchains -F input /sbin/ipchains -F output /sbin/ipchains -F forward /sbin/ipchains -P forward REJECT # use this line if you have a dynamic IP address (on DHCP or BOOTP) # configured from your ISP /sbin/ipchains -A input -j ACCEPT -i eth0 -s 0/0 67 -d 0/0 68 -p udp /sbin/ipchains -P forward DENY /sbin/ipchains -A forward -i eth0 -s 192.168.1.0/24 -j MASQ |
For users connecting to external network on ethernet & using iptables:
/sbin/iptables -F /sbin/iptables -t nat -F /sbin/iptables -t mangle -F #ignore if you get an error here /sbin/iptables -X #deletes every non-builtin chain in the table /sbin/iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT /sbin/iptables -A INPUT -m state --state NEW -i ! eth0 -j ACCEPT # only if both of the above rules succeed, use /sbin/iptables -P INPUT DROP /sbin/iptables -A FORWARD -i eth0 -o eth1 -m state --state ESTABLISHED,RELATED -j ACCEPT /sbin/iptables -A FORWARD -i eth1 -o eth0 -j ACCEPT # use this line if you have a static IP address from your ISP # replace your static IP with x.x.x.x /sbin/iptables -t nat -A POSTROUTING -o eth0 -j SNAT --to x.x.x.x # use this line only if you have dynamic IP address from your ISP /sbin/iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE /sbin/iptables -A FORWARD -i eth0 -o eth0 -j REJECT |
Create a script /etc/init.d/gateway
#! /bin/sh # If no rules, do nothing. [ -f /etc/gateway.rules ] || exit 0 case "$1" in start) echo -n "Turning on packet filtering:" /sbin/modprobe ip_masq_ftp #only if using ipchains /sbin/modprobe iptable_nat #only if using iptables /sbin/modprobe ipt_MASQUERADE #only if using iptables /sbin/ipchains-restore < /etc/ipchains.rules || exit 1 echo 1 > /proc/sys/net/ipv4/ip_forward # for RedHat users, the above line is not needed if you have # FORWARD_IPV4=true in /etc/sysconfig/network file echo "1" > /proc/sys/net/ipv4/ip_dynaddr # the above option is for Dynamic IP users (DHCP,PPP or BOOTP) echo "." ;; stop) echo -n "Turning off packet filtering:" echo 0 > /proc/sys/net/ipv4/ip_forward /sbin/ipchains -F /sbin/ipchains -X /sbin/ipchains -P input ACCEPT /sbin/ipchains -P output ACCEPT /sbin/ipchains -P forward ACCEPT echo "." ;; *) echo "Usage: /etc/init.d/gateway {start|stop}" exit 1 ;; esac exit 0 |
Give execute permissions to the startup scripts
bash# chmod 744 /etc/init.d/gateway |
Use rcconf or chkconfig to create startup links for this file.
The values that need to be set on your workstations are,
static IP address : 192.168.1.2 to 192.168.2.max-hosts subnet Mask : 255.255.255.0 Default gateway : 192.168.1.1 Primary DNS Server : <primary dns server as given by your ISP> Secondary DNS Server: <secondary dns server as given by your ISP> |
After doing all the settings as mentioned above, restart your networking with
bash# /etc/init.d/networking restart |
bash# route add -net 192.168.1.0 netmask 255.255.255.0 gw X.X.X.X dev eth1 |