Linux Home Networking
Linux Home Networking
What Do I Need?
◮ You will need a machine that runs Linux. For very simple
setups a Pentium 1 should work, but the more you want to do
(security for wireless, web filtering, complex firewall rules) the
faster your processor should be. 400 MHz is sufficient for the
more complex setups.
◮ You will need to be comfortable running a system without X,
familiar with kernel settings, and some familiarity with a
scripting language.
◮ You will need to pick a distro that can handle running on a
slower machine. SuSE, Fedora, Gentoo, and Unbuntu are
probably bad choices. I recommend Debian.
◮ You’ll probably want to do a minimum install.
Home Networking In Linux
Introduction
Preparing the Machine
Kernel Configuration
◮ After installing Linux onto the box, you’ll want to be sure that
your kernel has a few standard options set.
◮ Under Networking--->Networking options you’ll want to enable:
◮ IP: TCP syncookie support
◮ Network Packet filtering
◮ Under Network Packet filtering--->Core Netfilter Configuration
◮ Netfilter Xtables support
◮ MARK, CLASSIFY, NFQUEUE, comment, conntrack, limit,
max, state
◮ Under IP: Netfilter Configuration
◮ Connection tracking: FTP, IRC
◮ IP tables support: range, multiple port, TOS, recent, packet
filtering, LOG, NAT (MASQUERADE, REDIRECT), mangling
Home Networking In Linux
Basic Networking
Basic Networking
◮ Usually, an ISP will provide us with a single address to use when connecting to
their network. To have multiple computers go through the one address we need
to NAT (Network Address Translation).
◮ Usually, you assign machines on your LAN a private IP address, the avalible
subnets are:
Subnet IP Range Addresses
10.0.0.0/8 10.0.0.0 – 10.255.255.255 1677216
172.16.0.0/12 172.16.0.0 – 172.31.255.255 1048576
192.168.0.0/16 192.168.0.0 – 192.168.255.255 65536
Most consumer routers use a 24-bit subnet in the 192.168.0.0/16 block, so it is
usually safe to use one within your ISP’s network. It is not unusual that an ISP
will use a subnet in 10.0.0.0/8. The 172.16.0.0/12 range is fairly rare to come
by, so a subnet in there should be safe as well. There are no rules governing the
use of private subnets, so your ISP might use subnets from all of them. You
might have to experiment to find an unused subnet.
◮ If you have to pick a private subnet, I would recommend one of the early 24-bit
subnets in 192.168.0.0/16, like 192.168.1.0/24 or 192.168.2.0/24.
Home Networking In Linux
Basic Networking
Subnet Usage
Iptables: Introduction
◮ Iptables is the current method of implementing a Linux
firewall. It succeeds ipchains, and is avalible in the 2.4 and
default in the 2.6 kernel series.
◮ Firewall rules are inserted into the kernel in various tables,
setup as chains of rules.
◮ With iptables you specify the table you are adding the rule to,
and the chain you wish to put the rule in. There are a number
of default tables, but we will only worry about two of them:
◮ filter – The default table, containing the chains INPUT,
OUTPUT, and FORWARD.
◮ nat – Used to alter packets before or after the filter table,
contains the chains PREROUTING, OUTPUT, and
POSTROUTING.
Home Networking In Linux
Basic Iptables
Iptables: Introduction
◮ In each table there are chains of rules. These chains execute
rules in order.
◮ Each chain has a default policy for determining what to do
with a packet it encounters. The policy can be any of the
possible TARGETs. Some useful ones are:
◮ ACCEPT – Let the packet through.
◮ DROP – Drop the packet, no notification, just toss it aside.
◮ REJECT – Reject the packet, with an error message.
◮ REDIRECT – Send the packet else where.
◮ Each rule has a number of parameters it tries to match. If the
packet is a match the rule applies to that packet.
◮ To allow all SSH traffic in to the firewall machine you would:
# iptables -A INPUT -p tcp --dport 22 -j ACCEPT
Home Networking In Linux
Basic Iptables
◮ For example:
# iptables -p tcp -h
# iptables -m state -h
# iptables -j REJECT -h
# iptables -m recent -h
◮ Be sure to read the man page, and look at the example scripts
that should be included with this presentation.
◮ Also you can use iptables -L to view the rules in the tables.
(iptables -t nat -L)
Home Networking In Linux
Basic Iptables
An Example Script
echo 0 > /proc/sys/net/ipv4/ip_forward
iptables --flush
iptables -t nat --flush
iptables --delete-chain
iptables -t nat --delete-chain
A Comment on NATing
◮ If you NAT your machines, the SNAT target works great if you
have a static IP. Most broadband ISPs offer static IPs. Even
when they won’t offer one, you usually will have a relatively
static IP. Comcast has been a change about every 2 months.
◮ To help keep your IP the same, be sure you DHCP client stays
running so you keep requesting the same address.
◮ But if your IP changes, you have to change your SNAT
statement in your scripts.
◮ iptables provides the MASQUERADE target for dynamic IPs,
simply replace your SNAT line with:
iptables -t nat -A POSTROTING -o eth0 -j MASQUERADE
Home Networking In Linux
Wireless Access Point
◮ To act as your own access point, you need a network card that can be
switched into master mode under Linux.
◮ The following cards are currently (December 10, 2006) supported:
Security Options
Using WEP
Using WPA
OpenVPN
@ IN NS mystuff.example.com.
IN A 192.168.1.1
mybox IN A 192.168.1.15
another IN A 192.168.1.25
Bind Notes
◮ Please note, I’ve glossed over some details if you running your
own bind server.
◮ You need a file to reference other servers to pull down DNS
information from, most distros probably come with this in the
default configuration files.
◮ You will need to have a reverse lookup file for 127.0.0, once
again this is often included.
◮ Finally, you will need to make a reverse lookup file for your
LAN if you choose to use DNS to give names to your
machines.
◮ If all works correctly a host mybox will resolve to
mybox.mystuff.example.com which will be 192.168.1.15.
Home Networking In Linux
Services
Web Filtering: Dansguardian
Installing
DansGuardian Configuration
Notes on Hardware
Notes on Machines
Resources
◮ General References:
1. Configuring a Linux Wireless Router
(http://martybugs.net/wireless/router.cgi).
2. Firewall and Proxy Server HOWTO
(http://www.tldp.org/HOWTO/Firewall-HOWTO-6.html).
◮ Iptables:
1. Using Linux iptables or ipchains to set up an internet gateway
(http://yolinux.com/TUTORIALS/
LinuxTutorialIptablesNetworkGateway.html).
2. Iptables Tutorial
(http://iptables-tutorial.frozentux.net/iptables-tutorial.html),
3. O’Reilly’s Linux Server Security, by Michael D. Bauer.
4. Troubleshooting Linux Firewalls by Michael and Scott Shinn.
Home Networking In Linux
Resources
Resources
◮ BIND:
1. DNS HOWTO
(http://tldp.org/HOWTO/DNS-HOWTO-3.html).
2. Bind Administrator Reference Manual
(http://www.bind9.net/manual/bind/9.3.2/Bv9ARM.ch01.html).
3. O’Reilly’s DNS and BIND by Paul Albitz and Cricket Liu.