/[gentoo]/xml/htdocs/doc/en/home-router-howto.xml
Gentoo

Diff of /xml/htdocs/doc/en/home-router-howto.xml

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 1.15 Revision 1.56
1<?xml version='1.0' encoding='UTF-8'?> 1<?xml version='1.0' encoding='UTF-8'?>
2<!-- $Header: /var/cvsroot/gentoo/xml/htdocs/doc/en/home-router-howto.xml,v 1.15 2004/08/12 03:37:25 vapier Exp $ -->
3<!DOCTYPE guide SYSTEM "/dtd/guide.dtd"> 2<!DOCTYPE guide SYSTEM "/dtd/guide.dtd">
3<!-- $Header: /var/cvsroot/gentoo/xml/htdocs/doc/en/home-router-howto.xml,v 1.56 2007/03/07 21:30:18 nightmorph Exp $ -->
4 4
5<guide link="/doc/en/home-router-howto.xml"> 5<guide link="/doc/en/home-router-howto.xml" lang="en">
6
7<title>Home Router Guide</title> 6<title>Home Router Guide</title>
8 7
9<author title="Author"> 8<author title="Author">
10 <mail link="vapier@gentoo.org">Mike Frysinger</mail> 9 <mail link="vapier@gentoo.org">Mike Frysinger</mail>
11</author> 10</author>
13<abstract> 12<abstract>
14This document details how to turn an old Gentoo machine into a router 13This document details how to turn an old Gentoo machine into a router
15for connecting your home network to the internet. 14for connecting your home network to the internet.
16</abstract> 15</abstract>
17 16
17<!-- The content of this document is released into the public domain -->
18<license/>
19
18<version>1.1</version> 20<version>1.35</version>
19<date>July 21, 2004</date> 21<date>2007-03-07</date>
20 22
21<chapter> 23<chapter>
22<title>Introduction</title> 24<title>Introduction</title>
23<section> 25<section>
24<body> 26<body>
25 27
26<p> 28<p>
27Building your own router out of old spare parts has many advantages 29Building your own router out of old spare parts has many advantages over buying
28over buying a pre-made canned router by say Linksys. The biggest one by 30a pre-made canned router by say Linksys. The biggest one by far is control
29far is control over the connection. The other advantages are left up to 31over the connection. The other advantages are left up to your imagination;
30your imagination; just about anything can be done in this scenario, 32just about anything can be done in this scenario, it's just a matter of needing
31it's just a matter of needing it. 33it.
32</p>
33
34<p> 34</p>
35
36<p>
35This guide will show you how to setup Network Address Translation (NAT) 37This guide will show you how to setup Network Address Translation (NAT) on the
36on the router (kernel and iptables), add and configure common services 38router (kernel and iptables), add and configure common services (Domain Name
37(Domain Name System (DNS) via dnsmasq, dhcp via dhcpcd, ADSL via 39System (DNS) via dnsmasq, dhcp via dhcpcd, ADSL via rp-pppoe), and conclude
38rp-pppoe), and conclude with more elaborate and fun things that can be 40with more elaborate and fun things that can be done (port forwarding, traffic
39done (port forwarding, traffic shaping, proxies/caching, etc...). 41shaping, proxies/caching, etc...).
40</p>
41
42<p> 42</p>
43
44<p>
43Before getting started, there's a few basic requirements you must meet. 45Before getting started, there's a few basic requirements you must meet. First,
44First, you'll need a computer that has at least 2 Network Interface 46you'll need a computer that has at least 2 Network Interface Cards (NICs) in
45Cards (NICs) in it. Next, you'll need the configuration settings for 47it. Next, you'll need the configuration settings for your internet connection
46your internet connection (may include things like 48(may include things like IP/DNS/Gateway/username/password). Finally, you'll
47IP/DNS/Gateway/username/password). Finally, you'll need a bit of spare 49need a bit of spare time and some Gentoo loving.
48time and some Gentoo loving.
49</p> 50</p>
50 51
51<p> 52<p>
52The conventions used in this guide are: 53The conventions used in this guide are:
53</p> 54</p>
55
54<ul> 56<ul>
55 <li>eth0 - NIC connected to the Local Area Network (LAN)</li> 57 <li>eth0 - NIC connected to the Local Area Network (LAN)</li>
56 <li>eth1 - NIC connected to the Wide Area Network (WAN)</li> 58 <li>eth1 - NIC connected to the Wide Area Network (WAN)</li>
57 <li>LAN utilizes the private 192.168.0.xxx network</li> 59 <li>LAN utilizes the private 192.168.0.xxx network</li>
58 <li>router is hardcoded to the standard 192.168.0.1 IP</li> 60 <li>router is hardcoded to the standard 192.168.0.1 IP</li>
59 <li>router is running Linux 2.4 or 2.6; you're on your own with 2.0/2.2</li> 61 <li>router is running Linux 2.4 or 2.6; you're on your own with 2.0/2.2</li>
60</ul> 62</ul>
61 63
62<impo> 64<impo>
63Due to security precautions, I would highly suggest you shut down any 65Due to security precautions, I would highly suggest you shut down any unneeded
64unneeded services on the router until we have a chance to get the 66services on the router until we have a chance to get the firewall up and
65firewall up and rolling. To view the currently running services, just 67rolling. To view the currently running services, just run <c>rc-status</c>.
66run <c>rc-status</c>.
67</impo> 68</impo>
68 69
69</body> 70</body>
70</section> 71</section>
71</chapter> 72</chapter>
74<title>Kernel setup (know thyself first)</title> 75<title>Kernel setup (know thyself first)</title>
75<section> 76<section>
76<body> 77<body>
77 78
78<p> 79<p>
79Your kernel needs to have the drivers running for both your NICs. To 80Your kernel needs to have the drivers running for both your NICs. To see if
80see if your cards are already setup, just run <c>ifconfig</c>. Your 81your cards are already setup, just run <c>ifconfig</c>. Your output may differ
81output may differ slightly from the following, that's fine. What 82slightly from the following, that's fine. What matters is that the interface
82matters is that the interface shows up at all. 83shows up at all.
83</p> 84</p>
85
84<pre caption="Checking NICs"> 86<pre caption="Checking NICs">
85# <i>ifconfig -a</i> 87# <i>ifconfig -a</i>
86eth0 Link encap:Ethernet HWaddr 00:60:F5:07:07:B8 88eth0 Link encap:Ethernet HWaddr 00:60:F5:07:07:B8
87 BROADCAST MULTICAST MTU:1500 Metric:1 89 BROADCAST MULTICAST MTU:1500 Metric:1
88 RX packets:0 errors:0 dropped:0 overruns:0 frame:0 90 RX packets:0 errors:0 dropped:0 overruns:0 frame:0
97 TX packets:0 errors:0 dropped:0 overruns:0 carrier:0 99 TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
98 collisions:0 txqueuelen:1000 100 collisions:0 txqueuelen:1000
99 RX bytes:0 (0.0 b) TX bytes:0 (0.0 b) 101 RX bytes:0 (0.0 b) TX bytes:0 (0.0 b)
100 Interrupt:10 Base address:0x9400 102 Interrupt:10 Base address:0x9400
101</pre> 103</pre>
104
102<p> 105<p>
103If you do not see your two cards showing up and you're not sure what 106If you do not see your two cards showing up and you're not sure what kind of
104kind of cards you have, try running <c>lspci</c>. You can get that from 107cards you have, try running <c>lspci | grep Ethernet</c>. You can get that
105<c>emerge pciutils</c>. Look for "Ethernet controller" in the output. 108from <c>emerge pciutils</c>. Once you have this information, go into your
106Once you have this information, go into your kernel and add support for 109kernel and add support for the correct drivers.
107the correct drivers.
108</p>
109
110<p> 110</p>
111
112<p>
111The next thing you'll need is support for iptables and NAT (and packet 113The next thing you'll need is support for iptables and NAT (and packet shaping
112shaping if you want). The following list is split up into required 114if you want). The following list is split up into always required (*),
113(*), suggested (x), and shaper (s) features. It does not matter whether 115required only for adsl via PPPoE (a), suggested for everyone (x), and only
114you build the features into the kernel or as a module so long as when 116for shaper (s) features. It does not matter whether you build the features
115the feature is needed, the correct module(s) are loaded (module loading 117into the kernel or as a module so long as when the feature is needed, the
116is left to the reader as a fun exercise however). 118correct module(s) are loaded (module loading is left to the reader as a fun
119exercise however).
117</p> 120</p>
121
118<pre caption="Network Options"> 122<pre caption="Network Options">
119<i>Networking options ---&gt;</i> 123Networking options ---&gt;
120<i> [*] TCP/IP networking</i> 124 [*] TCP/IP networking
121<i> [*] IP: advanced router</i> 125 [*] IP: advanced router
122<i> [*] Network packet filtering (replaces ipchains)</i> 126 [*] Network packet filtering (replaces ipchains)
127<comment>If you use 2.4.x, you have to enable the following for DHCP:</comment>
128 [*] Socket Filtering
123 129
124<i> IP: Netfilter Configuration ---&gt;</i> 130 IP: Netfilter Configuration ---&gt;
125<i> [*] Connection tracking (required for masq/NAT)</i> 131 [*] Connection tracking (required for masq/NAT)
126<i> [x] FTP protocol support</i> 132 [x] FTP protocol support
127<i> [x] IRC protocol support</i> 133 [x] IRC protocol support
128<i> [*] IP tables support (required for filtering/masq/NAT)</i> 134 [*] IP tables support (required for filtering/masq/NAT)
129<i> [*] IP range match support</i> 135 [*] IP range match support
130<i> [x] MAC address match support</i> 136 [x] MAC address match support
131<i> [*] Multiple port match support</i> 137 [*] Multiple port match support
132<i> [*] Packet filtering</i> 138 [*] Packet filtering
133<i> [*] REJECT target support</i> 139 [*] REJECT target support
134<i> [x] REDIRECT target support</i> 140 [x] REDIRECT target support
135<i> [*] Full NAT</i> 141 [*] Full NAT
136<i> [*] MASQUERADE target support</i> 142 [*] MASQUERADE target support
137<i> [s] Packet mangling</i> 143 [s] Packet mangling
138<i> [s] MARK target support</i> 144 [s] MARK target support
139<i> [x] LOG target support</i> 145 [x] LOG target support
140 146
141<i> QoS and/or fair queueing ---&gt;</i> 147 QoS and/or fair queueing ---&gt;
142<i> [s] QoS and/or fair queueing</i> 148 [s] QoS and/or fair queueing
143<i> [s] HTB packet scheduler</i> 149 [s] HTB packet scheduler
144<i> [s] Ingress Qdisc</i> 150 [s] Ingress Qdisc
151
152 [a] PPP (point-to-point protocol) support
153 [a] PPP filtering
154 [a] PPP support for async serial ports
155 [a] PPP support for sync tty ports
156 [a] PPP Deflate compression
157 [a] PPP BSD-Compress compression
158 [a] PPP over Ethernet
145</pre> 159</pre>
160
146<note> 161<note>
147Somethings may be slightly different in a 2.4 vs 2.6 kernel, but you 162Some things may be slightly different in a 2.4 vs 2.6 kernel, but you should be
148should be able to figure it out :). 163able to figure it out :). Even among 2.6 kernels, these options have a
164tendency to move around. Good luck!
149</note> 165</note>
150 166
151</body> 167</body>
152</section> 168</section>
153</chapter> 169</chapter>
156<title>Hug the WAN (a.k.a. The Internet)</title> 172<title>Hug the WAN (a.k.a. The Internet)</title>
157 173
158<section> 174<section>
159<title>Intro</title> 175<title>Intro</title>
160<body> 176<body>
177
161<p> 178<p>
162There are many ways to connect to the internet so I'll just cover the 179There are many ways to connect to the internet so I'll just cover the ones I'm
163ones I'm familiar with. That leaves us with ADSL (PPPoE) and cable 180familiar with. That leaves us with ADSL (PPPoE) and cable modems
164modems (static/dynamic). If there are other methods out there, feel 181(static/dynamic). If there are other methods out there, feel free to write up
165free to write up a little blurb and e-mail me. Feel free to skip any of 182a little blurb and e-mail me. Feel free to skip any of the following sections
166the following sections in this chapter that don't apply to you. This 183in this chapter that don't apply to you. This chapter is just about getting
167chapter is just about getting the router connected to the internet via 184the router connected to the internet via eth1.
168eth1.
169</p> 185</p>
170</body>
171</section>
172 186
187</body>
188</section>
173<section> 189<section>
174<title>ADSL and PPPoE</title> 190<title>ADSL and PPPoE</title>
175<body> 191<body>
176 192
177<p> 193<p>
178All the fancy PPPoE software has been bundled up into one little nice 194All the fancy PPPoE software has been bundled up into one little nice package
179package nowadays called <uri link="http://www.roaringpenguin.com/">Roaring Penguin</uri>. 195nowadays called <uri link="http://www.roaringpenguin.com/">Roaring
180Simply <c>emerge rp-pppoe</c> and you'll be on your way. Remember how 196Penguin</uri>. Simply <c>emerge rp-pppoe</c> and you'll be on your way.
181I said you'll need username/password information? Well I wasn't lying 197Remember how I said you'll need username/password information? Well I wasn't
182so I hope you have it now! Load up <path>/etc/ppp/pppoe.conf</path> in 198lying so I hope you have it now! Load up <path>/etc/ppp/pppoe.conf</path> in
183your favorite editor and set it up. 199your favorite editor and set it up.
184</p> 200</p>
185 201
186<note> 202<note>
187In order for the following net.eth1 settings to work, you must have 203In order for the following net settings to work, you must have
188baselayout-1.10.1 or later installed on your system. 204baselayout-1.11.14 or later installed on your system.
189</note> 205</note>
190 206
191<pre caption="Setting up eth1"> 207<pre caption="Setting up eth1">
192<comment>(Replace 'vla9h924' with your username and 'password' with your password)</comment> 208<comment>(Replace 'vla9h924' with your username and 'password' with your password)</comment>
193 209
194# <i>nano /etc/ppp/pppoe.conf</i>
195<comment># Ethernet card connected to ADSL modem
196ETH=eth1
197# ADSL user name.
198USER=vla9h924</comment>
199# <i>nano /etc/ppp/pap-secrets</i> 210# <i>nano /etc/ppp/pap-secrets</i>
200<comment># client server secret 211<comment># client server secret</comment>
201"vla9h924" * "password"</comment> 212"vla9h924" * "password"
202# <i>nano /etc/conf.d/net</i> 213# <i>nano /etc/conf.d/net</i>
203<comment>Add an entry for ifconfig_eth1 and set it to adsl: 214<comment>Tell baselayout to use adsl for your eth1:</comment>
204ifconfig_eth1=( "adsl" )</comment> 215config_eth1=( "adsl" )
216user_eth1=( "vla9h924" )
205# <i>ln -s net.eth0 /etc/init.d/net.eth1</i> 217# <i>ln -s net.lo /etc/init.d/net.eth1</i>
206# <i>rc-update add net.eth1 default</i> 218# <i>rc-update add net.eth1 default</i>
207# <i>/etc/init.d/net.eth1 start</i> 219# <i>/etc/init.d/net.eth1 start</i>
208</pre> 220</pre>
209 221
210<warn> 222<warn>
211When the DSL interface comes up, it will create ppp0. Although your NIC 223When the DSL interface comes up, it will create ppp0. Although your NIC is
212is called eth1, the IP is actually bound to ppp0. From now on, when you 224called eth1, the IP is actually bound to ppp0. From now on, when you see
213see examples that utilize 'eth1', substitute with 'ppp0'. 225examples that utilize 'eth1', substitute with 'ppp0'.
214</warn> 226</warn>
215 227
216</body> 228</body>
217</section> 229</section>
218 230
228 240
229<pre caption="Setting up eth1"> 241<pre caption="Setting up eth1">
230<comment>Dynamic IP Users:</comment> 242<comment>Dynamic IP Users:</comment>
231# <i>emerge dhcpcd</i> 243# <i>emerge dhcpcd</i>
232# <i>nano /etc/conf.d/net</i> 244# <i>nano /etc/conf.d/net</i>
233<comment>You'll need an entry like so: 245<comment>You'll need an entry like so:</comment>
234ifconfig_eth1=( "dhcp" )</comment> 246config_eth1=( "dhcp" )
235 247
236<comment>Static IP Users:</comment> 248<comment>Static IP Users:</comment>
237# <i>nano /etc/conf.d/net</i> 249# <i>nano /etc/conf.d/net</i>
238<comment>You'll need entries like so: 250<comment>You'll need entries like so:</comment>
239ifconfig_eth1=( "66.92.78.102 broadcast 66.92.78.255 netmask 255.255.255.0" ) 251config_eth1=( "66.92.78.102 broadcast 66.92.78.255 netmask 255.255.255.0" )
240routes_eth1=( "default gw 66.92.78.1" )</comment> 252routes_eth1=( "default gw 66.92.78.1" )
241# <i>nano /etc/resolv.conf</i> 253# <i>nano /etc/resolv.conf</i>
242<comment>Add one line per DNS server: 254<comment>Add one line per DNS server:</comment>
243nameserver 123.123.123.123</comment> 255nameserver 123.123.123.123
244 256
245<comment>Dynamic and Static Setup:</comment> 257<comment>Dynamic and Static Setup:</comment>
246# <i>ln -s net.eth0 /etc/init.d/net.eth1</i> 258# <i>ln -s net.lo /etc/init.d/net.eth1</i>
247# <i>rc-update add net.eth1 default</i> 259# <i>rc-update add net.eth1 default</i>
248# <i>/etc/init.d/net.eth1 start</i> 260# <i>/etc/init.d/net.eth1 start</i>
249</pre> 261</pre>
250 262
251<p> 263<p>
265This step is a breeze compared to the previous one. 277This step is a breeze compared to the previous one.
266</p> 278</p>
267 279
268<pre caption="Setting up eth0"> 280<pre caption="Setting up eth0">
269# <i>nano /etc/conf.d/net</i> 281# <i>nano /etc/conf.d/net</i>
270<comment>Add a line like the following: 282<comment>Add a line like the following:</comment>
271ifconfig_eth0=( "192.168.0.1 broadcast 192.168.0.255 netmask 255.255.255.0" )</comment> 283config_eth0=( "192.168.0.1 broadcast 192.168.0.255 netmask 255.255.255.0" )
272# <i>rc-update add net.eth0 default</i> 284# <i>rc-update add net.eth0 default</i>
273# <i>/etc/init.d/net.eth0 start</i> 285# <i>/etc/init.d/net.eth0 start</i>
274</pre> 286</pre>
275 287
276</body> 288</body>
281<title>LAN Services (because we're nice people)</title> 293<title>LAN Services (because we're nice people)</title>
282 294
283<section> 295<section>
284<title>DHCP Server</title> 296<title>DHCP Server</title>
285<body> 297<body>
298
286<p> 299<p>
287I bet it'd be nice if everyone else in your house could just plug 300I bet it'd be nice if everyone else in your house could just plug their
288their computers into the network and things would just work. No need to 301computers into the network and things would just work. No need to remember
289remember mind-numbing details or make them stare at confusing 302mind-numbing details or make them stare at confusing configuration screens!
290configuration screens! Life would be grand eh? Introducing the Dynamic 303Life would be grand eh? Introducing the Dynamic Host Configuration Protocol
291Host Configuration Protocol (DHCP) and why you should care. 304(DHCP) and why you should care.
292</p> 305</p>
293 306
294<p> 307<p>
295DHCP is exactly what its name implies. It's a protocol that allows you 308DHCP is exactly what its name implies. It's a protocol that allows you
296to dynamically configure other hosts automatically. You run a DHCP 309to dynamically configure other hosts automatically. You run a DHCP server on
297server on the router (dhcpd), give it all the information about your 310the router, give it all the information about your network (valid IPs,
298network (valid IPs, DNS servers, gateways, etc...), and then when the 311DNS servers, gateways, etc...), and then when the other hosts start up, they
299other hosts start up, they run a DHCP client to automatically configure 312run a DHCP client to automatically configure themselves. No fuss, no muss!
300themselves. No fuss, no muss! For more information about DHCP, you can 313For more information about DHCP, you can always visit <uri
301always visit <uri link="http://en.wikipedia.org/wiki/DHCP">Wikipedia</uri>. 314link="http://en.wikipedia.org/wiki/DHCP">Wikipedia</uri>.
302</p>
303
304<pre caption="Setting up dhcpd">
305# <i>emerge dhcp</i>
306# <i>nano /etc/dhcp/dhcpd.conf</i>
307<comment>Here is a sample configuration file:
308authoritative;
309subnet 192.168.0.0 netmask 255.255.255.0 {
310 range 192.168.0.100 192.168.0.250;
311 default-lease-time 259200;
312 max-lease-time 518400;
313 option subnet-mask 255.255.255.0;
314 option broadcast-address 192.168.0.255;
315 option routers 192.168.0.1;
316 option domain-name-servers 192.168.0.1;
317}
318</comment>
319# <i>nano /etc/conf.d/dhcp</i>
320<comment>Set IFACE="eth0"</comment>
321# <i>rc-update add dhcp default</i>
322# <i>/etc/init.d/dhcp start</i>
323</pre>
324
325<p> 315</p>
326Now your little router is a bona-fide DHCP server! Plugin those 316
327computers and watch them work! With Windows systems you should go into
328the TCP/IP Properties and select the 'Obtain an IP address
329automatically' and 'Obtain DNS server address automatically' options.
330Sometimes the changes aren't instantaneous, so you may have to run a
331command prompt and run <c>ipconfig /release</c> and <c>ipconfig
332/renew</c>. But enough about Windows, let's get back to our favorite
333penguin.
334</p> 317<p>
335</body> 318We'll use a package called dnsmasq which provides both DHCP and DNS services.
336</section> 319For now lets just focus on the DHCP aspect. Note that if you want to run a
337 320different DHCP server, you can find another example in the Fun Things chapter.
338<section> 321Also, if you wish to tinker with the DHCP server settings, just read the
339<title>DNS Server</title> 322comments in <path>/etc/dnsmasq.conf</path>. All the defaults should work fine
340<body> 323though.
341<p> 324</p>
342When people want to visit a place on the internet, they remember names,
343not a string of useless numbers. After all, what's easier to remember,
344ebay.com or 66.135.192.87? This is where the DNS steps in. DNS servers
345run all over the internet, and whenever someone wants to visit 'ebay.com',
346these servers turn 'ebay.com' (what we understand) into '66.135.192.87'
347(what our computers understand). For more information about DNS, you can
348always visit <uri link="http://en.wikipedia.org/wiki/DNS">Wikipedia</uri>.
349</p>
350 325
351<p>
352You may have noticed in the previous section that we told the DHCP
353clients we have a DNS server at 192.168.0.1. You may also remember that
354192.168.0.1 is our little router that we're making. I don't remember
355setting up a DNS server ... so let's do so now!
356</p>
357
358<pre caption="Setting up dnsmasq"> 326<pre caption="Setting up a DHCP server">
359# <i>emerge dnsmasq</i> 327# <i>emerge dnsmasq</i>
360# <i>nano /etc/conf.d/dnsmasq</i> 328# <i>nano /etc/dnsmasq.conf</i>
361<comment>Add "-i eth1" to DNSMASQ_OPTS</comment> 329<comment>Add this line to enable dhcp:</comment>
330dhcp-range=192.168.0.100,192.168.0.250,72h
331<comment>Restrict dnsmasq to just the LAN interface</comment>
332interface=eth0
333
362# <i>rc-update add dnsmasq default</i> 334# <i>rc-update add dnsmasq default</i>
363# <i>/etc/init.d/dnsmasq start</i> 335# <i>/etc/init.d/dnsmasq start</i>
364</pre> 336</pre>
365 337
366<p> 338<p>
367Well that was quick, but what did we do? The great thing is, we didn't 339Now your little router is a bona-fide DHCP server! Plugin those computers and
368have to do very much! You're welcome to choose other DNS servers if 340watch them work! With Windows systems you should go into the TCP/IP Properties
369you're more comfortable with them, but the reason dnsmasq is great is 341and select the 'Obtain an IP address automatically' and 'Obtain DNS server
370because it was designed to do exactly what we want and nothing more. 342address automatically' options. Sometimes the changes aren't instantaneous, so
371It's a little DNS caching/forwarding server for local networks. We're 343you may have to open a command prompt and run <c>ipconfig /release</c> and
372not looking to provide DNS for our own domain here, just offer simple DNS 344<c>ipconfig /renew</c>. But enough about Windows, let's get back to our
345favorite penguin.
346</p>
347
348</body>
349</section>
350
351<section>
352<title>DNS Server</title>
353<body>
354
355<p>
356When people want to visit a place on the internet, they remember names, not a
357string of funky numbers. After all, what's easier to remember, ebay.com or
35866.135.192.87? This is where the DNS steps in. DNS servers run all over the
359internet, and whenever someone wants to visit 'ebay.com', these servers turn
360'ebay.com' (what we understand) into '66.135.192.87' (what our computers
361understand). For more information about DNS, you can always visit <uri
362link="http://en.wikipedia.org/wiki/DNS">Wikipedia</uri>.
363</p>
364
365<p>
366Since we're using dnsmasq for our DHCP server, and it includes a DNS server,
367you've got nothing left to do here! Your little router is already providing
368DNS to its DHCP clients. Bet you wish everything was this easy ;).
369</p>
370
371<p>
372You're welcome to choose other DNS servers if you're more comfortable with
373them, but the reason dnsmasq is great is because it was designed to do exactly
374what we want and nothing more. It's a little DNS caching/forwarding server for
375local networks. We're not looking to provide DNS for our own domain here, just
373services to everyone else on our LAN. 376offer simple DNS services to everyone else on our LAN.
374</p> 377</p>
375 378
376</body> 379</body>
377</section> 380</section>
378 381
379<section> 382<section>
380<title>NAT (a.k.a. IP-masquerading)</title> 383<title>NAT (a.k.a. IP-masquerading)</title>
381<body> 384<body>
382 385
383<p> 386<p>
384At this point, people on your network can talk to each other and they 387At this point, people on your network can talk to each other and they can look
385can look up hostnames via DNS, but they still can't actually connect to 388up hostnames via DNS, but they still can't actually connect to the internet.
386the internet. While you may think that's great (more bandwidth for 389While you may think that's great (more bandwidth for you!), I bet they're not
387you!), I bet they're not too happy just yet. 390too happy just yet.
388</p>
389
390<p> 391</p>
391This is where NAT steps in. NAT is a way of connecting multiple computers 392
392in a private LAN to the internet when you only have a smaller number of 393<p>
393IP addresses availabe to you. Typically you were given 1 IP by your ISP, 394This is where Network Address Translation (NAT) steps in. NAT is a way of
395connecting multiple computers in a private LAN to the internet when you have a
396smaller number of public IP addresses available to you. Typically you are given
394but you want to let your whole house connect to the internet. NAT is the 3971 IP by your ISP, but you want to let your whole house connect to the internet.
395magic that makes this possible. For more information about NAT, you can 398NAT is the magic that makes this possible. For more information about NAT, you
396always visit <uri link="http://en.wikipedia.org/wiki/NAT">Wikipedia</uri>. 399can always visit <uri link="http://en.wikipedia.org/wiki/NAT">Wikipedia</uri>.
397</p> 400</p>
398 401
399<note> 402<note>
400Before we get started, make sure you have iptables on your system. Although 403Before we get started, make sure you have iptables on your system. Although it
401it is automatically installed on most systems, you may not have it. If you 404is automatically installed on most systems, you may not have it. If you don't,
402don't, just run <c>emerge iptables</c>. 405just run <c>emerge iptables</c>.
403</note> 406</note>
404 407
405<pre caption="Setting up iptables"> 408<pre caption="Setting up iptables">
406<comment>First we flush our current rules</comment> 409<comment>First we flush our current rules</comment>
407# <i>iptables -F</i> 410# <i>iptables -F</i>
408# <i>iptables -t nat -F</i> 411# <i>iptables -t nat -F</i>
409 412
413<comment>Setup default policies to handle unmatched traffic</comment>
414# <i>iptables -P INPUT ACCEPT</i>
415# <i>iptables -P OUTPUT ACCEPT</i>
416# <i>iptables -P FORWARD DROP</i>
417
418<comment>Copy and paste these examples ...</comment>
419# <i>export LAN=eth0</i>
420# <i>export WAN=eth1</i>
421
410<comment>Then we lock our services so they only work from the LAN</comment> 422<comment>Then we lock our services so they only work from the LAN</comment>
411# <i>iptables -I INPUT 1 -i eth0 -j ACCEPT</i> 423# <i>iptables -I INPUT 1 -i ${LAN} -j ACCEPT</i>
412# <i>iptables -I INPUT 1 -i lo -j ACCEPT</i> 424# <i>iptables -I INPUT 1 -i lo -j ACCEPT</i>
413# <i>iptables -A INPUT -p UDP --dport bootps -i ! eth0 -j REJECT</i> 425# <i>iptables -A INPUT -p UDP --dport bootps -i ! ${LAN} -j REJECT</i>
414# <i>iptables -A INPUT -p UDP --dport domain -i ! eth0 -j REJECT</i> 426# <i>iptables -A INPUT -p UDP --dport domain -i ! ${LAN} -j REJECT</i>
427
428<comment>(Optional) Allow access to our ssh server from the WAN</comment>
429# <i>iptables -A INPUT -p TCP --dport ssh -i ${WAN} -j ACCEPT</i>
415 430
416<comment>Drop TCP / UDP packets to privileged ports</comment> 431<comment>Drop TCP / UDP packets to privileged ports</comment>
417# <i>iptables -A INPUT -p TCP -i ! eth0 -d 0/0 --dport 0:1023 -j DROP</i> 432# <i>iptables -A INPUT -p TCP -i ! ${LAN} -d 0/0 --dport 0:1023 -j DROP</i>
418# <i>iptables -A INPUT -p UDP -i ! eth0 -d 0/0 --dport 0:1023 -j DROP</i> 433# <i>iptables -A INPUT -p UDP -i ! ${LAN} -d 0/0 --dport 0:1023 -j DROP</i>
419 434
420<comment>Finally we add the rules for NAT</comment> 435<comment>Finally we add the rules for NAT</comment>
421# <i>iptables -I FORWARD -i eth0 -d 192.168.0.0/255.255.0.0 -j DROP</i> 436# <i>iptables -I FORWARD -i ${LAN} -d 192.168.0.0/255.255.0.0 -j DROP</i>
422# <i>iptables -A FORWARD -i eth0 -s 192.168.0.0/255.255.0.0 -j ACCEPT</i> 437# <i>iptables -A FORWARD -i ${LAN} -s 192.168.0.0/255.255.0.0 -j ACCEPT</i>
423# <i>iptables -A FORWARD -i eth1 -d 192.168.0.0/255.255.0.0 -j ACCEPT</i> 438# <i>iptables -A FORWARD -i ${WAN} -d 192.168.0.0/255.255.0.0 -j ACCEPT</i>
424# <i>iptables -t nat -A POSTROUTING -o eth1 -j MASQUERADE</i> 439# <i>iptables -t nat -A POSTROUTING -o ${WAN} -j MASQUERADE</i>
425<comment>Tell the kernel that ip forwarding is OK</comment> 440<comment>Tell the kernel that ip forwarding is OK</comment>
426# <i>echo 1 > /proc/sys/net/ipv4/ip_forward</i> 441# <i>echo 1 > /proc/sys/net/ipv4/ip_forward</i>
427# <i>for f in /proc/sys/net/ipv4/conf/*/rp_filter ; do echo 1 > $f ; done</i> 442# <i>for f in /proc/sys/net/ipv4/conf/*/rp_filter ; do echo 1 > $f ; done</i>
428 443
429<comment>This is so when we boot we don't have to run the rules by hand</comment> 444<comment>This is so when we boot we don't have to run the rules by hand</comment>
430# <i>/etc/init.d/iptables save</i> 445# <i>/etc/init.d/iptables save</i>
431# <i>rc-update add iptables default</i> 446# <i>rc-update add iptables default</i>
432# <i>nano /etc/sysctl.conf</i> 447# <i>nano /etc/sysctl.conf</i>
433<comment>Add/Uncomment the following lines: 448<comment>Add/Uncomment the following lines:</comment>
434net.ipv4.ip_forward = 1 449net.ipv4.ip_forward = 1
435net.ipv4.conf.default.rp_filter = 1</comment> 450net.ipv4.conf.default.rp_filter = 1
436</pre>
437 451
452<comment>If you have a dynamic internet address you probably want to enable this:</comment>
453net.ipv4.ip_dynaddr = 1
454</pre>
455
438<p> 456<p>
439Once you've typed out all of that, the rest of your network should now 457Once you've typed out all of that, the rest of your network should now be able
440be able to use the internet as if they were directly connected 458to use the internet as if they were directly connected themselves.
441themselves. 459</p>
460
461<p>
462The ip_dynaddr option is useful for dial on demand systems or when your ISP
463gives out dynamic addresses. This works around the problem where a connection
464is attempted before the internet interface is fully setup. Really this just
465provides for a smoother network experience for users behind your router.
442</p> 466</p>
443 467
444</body> 468</body>
445</section> 469</section>
446</chapter> 470</chapter>
449<title>Fun Things (for a rainy day)</title> 473<title>Fun Things (for a rainy day)</title>
450 474
451<section> 475<section>
452<title>Intro</title> 476<title>Intro</title>
453<body> 477<body>
478
454<p> 479<p>
455Believe it or not, you're done :). From here on out, I'll cover a bunch 480Believe it or not, you're done :). From here on out, I'll cover a bunch of
456of common topics that may interest you. Everything in this chapter is 481common topics that may interest you. Everything in this chapter is completely
457completely optional. 482optional.
458</p> 483</p>
484
459</body> 485</body>
460</section> 486</section>
461 487
462<section> 488<section>
463<title>Port Forwarding</title> 489<title>Port Forwarding</title>
464<body> 490<body>
491
465<p> 492<p>
466Sometimes you would like to be able to host services on a computer behind 493Sometimes you would like to be able to host services on a computer behind the
467the router, or just to make your life easier when connecting remotely. 494router, or just to make your life easier when connecting remotely. Perhaps you
468Perhaps you want to run a FTP, HTTP, SSH, or VNC server on one or more 495want to run a FTP, HTTP, SSH, or VNC server on one or more machines behind your
469machines behind your router and be able to connect to them all. The only 496router and be able to connect to them all. The only caveat is that you can
470caveat is that you can only have one service/machine combo per port. 497only have one service/machine combo per port. For example, there is no
471For example, there is no practical way to setup three FTP servers behind 498practical way to setup three FTP servers behind your router and then try to
472your router and then try to connect to them all through port 21; only one 499connect to them all through port 21; only one can be on port 21 while the
473can be on port 21 while the others would have to be on say port 123 and 500others would have to be on say port 123 and port 567.
474port 567.
475</p>
476
477<p> 501</p>
502
503<p>
478All the port forwarding rules are of the form <c>iptables -t nat -A PREROUTING 504All the port forwarding rules are of the form <c>iptables -t nat -A PREROUTING
479[-p protocol] --dport [external port on router] -i eth1 -j DNAT --to [ip/port 505[-p protocol] --dport [external port on router] -i ${WAN} -j DNAT --to [ip/port
480to forward to]</c>. iptables does not accept hostnames when port forwarding. 506to forward to]</c>. Unfortunately, iptables does not accept hostnames when port
481If you are forwarding an external port to the same port on the internal machine, 507forwarding. If you are forwarding an external port to the same port on the
482you can omit the destination port. See the iptables(8) page for more information. 508internal machine, you can omit the destination port. See the iptables(8) man
509page for more information.
483</p> 510</p>
484 511
485<pre> 512<pre caption="Running the iptables commands">
513<comment>Copy and paste these examples ...</comment>
514# <i>export LAN=eth0</i>
515# <i>export WAN=eth1</i>
516
486<comment>Forward port 2 to ssh on an internal host</comment> 517<comment>Forward port 2 to ssh on an internal host</comment>
487# <i>iptables -t nat -A PREROUTING -p tcp --dport 2 -i eth1 -j DNAT --to 192.168.0.2:22</i> 518# <i>iptables -t nat -A PREROUTING -p tcp --dport 2 -i ${WAN} -j DNAT --to 192.168.0.2:22</i>
488 519
489<comment>FTP forwarding to an internal host</comment> 520<comment>FTP forwarding to an internal host</comment>
490# <i>iptables -t nat -A PREROUTING -p tcp --dport 21 -i eth1 -j DNAT --to 192.168.0.56</i> 521# <i>iptables -t nat -A PREROUTING -p tcp --dport 21 -i ${WAN} -j DNAT --to 192.168.0.56</i>
491 522
492<comment>HTTP forwarding to an internal host</comment> 523<comment>HTTP forwarding to an internal host</comment>
493# <i>iptables -t nat -A PREROUTING -p tcp --dport 80 -i eth1 -j DNAT --to 192.168.0.56</i> 524# <i>iptables -t nat -A PREROUTING -p tcp --dport 80 -i ${WAN} -j DNAT --to 192.168.0.56</i>
494 525
495<comment>VNC forwarding for internal hosts</comment> 526<comment>VNC forwarding for internal hosts</comment>
496# <i>iptables -t nat -I PREROUTING -p tcp --dport 5900 -i eth1 -j DNAT --to 192.168.0.2</i> 527# <i>iptables -t nat -I PREROUTING -p tcp --dport 5900 -i ${WAN} -j DNAT --to 192.168.0.2</i>
497# <i>iptables -t nat -I PREROUTING -p tcp --dport 5901 -i eth1 -j DNAT --to 192.168.0.3:5900</i> 528# <i>iptables -t nat -I PREROUTING -p tcp --dport 5901 -i ${WAN} -j DNAT --to 192.168.0.3:5900</i>
498<comment>If you want to VNC in to 192.168.0.3, then just add ':1' to the router's hostname</comment> 529<comment>If you want to VNC in to 192.168.0.3, then just add ':1' to the router's hostname</comment>
499 530
531<comment>SAMBA forwarding to an internal host (excess ports to cover Windows)</comment>
532# <i>iptables -t nat -I PREROUTING -p tcp --dport 135 -i ${WAN} -j DNAT --to 192.168.0.2</i>
533# <i>iptables -t nat -I PREROUTING -p tcp --dport 139 -i ${WAN} -j DNAT --to 192.168.0.2</i>
534# <i>iptables -t nat -I PREROUTING -p tcp --dport 445 -i ${WAN} -j DNAT --to 192.168.0.2</i>
535# <i>iptables -t nat -I PREROUTING -p udp --dport 137:138 -i ${WAN} -j DNAT --to 192.168.0.2</i>
536# <i>iptables -t nat -I PREROUTING -p udp --dport 445 -i ${WAN} -j DNAT --to 192.168.0.2</i>
537
500<comment>Bittorrent forwarding</comment> 538<comment>Bittorrent forwarding</comment>
501# <i>iptables -t nat -A PREROUTING -p tcp --dport 6881:6889 -i eth1 -j DNAT --to 192.168.0.2</i> 539# <i>iptables -t nat -A PREROUTING -p tcp --dport 6881:6889 -i ${WAN} -j DNAT --to 192.168.0.2</i>
540
541<comment>eDonkey/eMule forwarding</comment>
542# <i>iptables -t nat -A PREROUTING -p tcp --dport 4662 -i ${WAN} -j DNAT --to 192.168.0.55</i>
502 543
503<comment>Game Cube Warp Pipe support</comment> 544<comment>Game Cube Warp Pipe support</comment>
504# <i>iptables -t nat -A PREROUTING -p udp --dport 4000 -i eth1 -j DNAT --to 192.168.0.56</i> 545# <i>iptables -t nat -A PREROUTING -p udp --dport 4000 -i ${WAN} -j DNAT --to 192.168.0.56</i>
505 546
506<comment>Playstation2 Online support</comment> 547<comment>Playstation 2 Online support</comment>
507# <i>iptables -t nat -A PREROUTING -p tcp --dport 10070:10080 -i eth1 -j DNAT --to 192.168.0.11</i> 548# <i>iptables -t nat -A PREROUTING -p tcp --dport 10070:10080 -i ${WAN} -j DNAT --to 192.168.0.11</i>
508# <i>iptables -t nat -A PREROUTING -p udp --dport 10070:10080 -i eth1 -j DNAT --to 192.168.0.11</i> 549# <i>iptables -t nat -A PREROUTING -p udp --dport 10070:10080 -i ${WAN} -j DNAT --to 192.168.0.11</i>
550
551<comment>Xbox Live</comment>
552# <i>iptables -t nat -A PREROUTING -p tcp --dport 3074 -i ${WAN} -j DNAT --to 192.168.0.69</i>
553# <i>iptables -t nat -A PREROUTING -p udp --dport 3074 -i ${WAN} -j DNAT --to 192.168.0.69</i>
554# <i>iptables -t nat -A PREROUTING -p udp --dport 88 -i ${WAN} -j DNAT --to 192.168.0.69</i>
509</pre> 555</pre>
510 556
511<note> 557<note>
512If you have other common / cool examples, please <uri link="mailto:vapier@gentoo.org">e-mail me</uri>. 558If you have other common / cool examples, please <mail
559link="vapier@gentoo.org">e-mail me</mail>.
513</note> 560</note>
561
514</body> 562</body>
515</section> 563</section>
516 564
517<section> 565<section>
518<title>Identd (for IRC)</title> 566<title>Identd (for IRC)</title>
519<body> 567<body>
568
520<p> 569<p>
521Internet Relay Chat utilizes the ident service pretty heavily. Now that 570Internet Relay Chat utilizes the ident service pretty heavily. Now that the
522the IRC clients are behind the router, we need a way to host ident for 571IRC clients are behind the router, we need a way to host ident for both the
523both the router and the clients. One such server has been created 572router and the clients. One such server has been created called
524called <c>midentd</c>. 573<c>midentd</c>.
525</p> 574</p>
526 575
527<pre caption="Setting up ident"> 576<pre caption="Setting up ident">
528# <i>emerge midentd</i> 577# <i>emerge midentd</i>
529# <i>rc-update add midentd default</i> 578# <i>rc-update add midentd default</i>
530# <i>/etc/init.d/midentd start</i> 579# <i>/etc/init.d/midentd start</i>
531</pre> 580</pre>
532 581
533<p> 582<p>
534There are a few other ident servers in portage. Depending on your needs, 583There are a few other ident servers in portage. Depending on your needs, I
535I would recommend checking out <c>oidentd</c> and <c>fakeidentd</c>. 584would recommend checking out <c>oidentd</c> and <c>fakeidentd</c>.
536</p> 585</p>
586
537</body> 587</body>
538</section> 588</section>
539 589
540<!-- 590<!--
541<section> 591<section>
611--> 661-->
612 662
613<section> 663<section>
614<title>Time Server</title> 664<title>Time Server</title>
615<body> 665<body>
666
616<p> 667<p>
617Keeping your system time correct is essential in maintaing a healthy 668Keeping your system time correct is essential in maintaining a healthy system.
618system. One of the most common ways of accomplishing this is with 669One of the most common ways of accomplishing this is with the Network Time
619the Network Time Protocol [NTP] and the ntp package (which provides 670Protocol (NTP) and the ntp package (which provides implementations for both
620implementations for both server and client). 671server and client).
621</p>
622
623<p> 672</p>
673
674<p>
624Many people run ntp clients on their computers. Obviously, the more 675Many people run ntp clients on their computers. Obviously, the more clients in
625clients in the world, the larger the load the ntp servers need to 676the world, the larger the load the ntp servers need to shoulder. In
626shoulder. In environments like home networks though, we can help 677environments like home networks though, we can help keep the load down on
627keep the load down on public servers while still providing the proper 678public servers while still providing the proper time to all our computers. As
628time to all our computers. As an added bonus, our private updates 679an added bonus, our private updates will be a lot faster for the clients too!
629will be a lot faster for the clients too! All we have to do is run 680All we have to do is run a ntp server on our router that synchronizes itself
630a ntp server on our router that synchronizes itself with the public
631internet servers while providing the time to the rest of the computers 681with the public internet servers while providing the time to the rest of the
632in the network. To get started, simply <c>emerge ntp</c> on the 682computers in the network. To get started, simply <c>emerge ntp</c> on the
633router. 683router.
634</p> 684</p>
635 685
636<pre caption="Setting up the NTP server"> 686<pre caption="Setting up the NTP server">
637# <i>nano /etc/conf.d/ntp-client</i> 687# <i>nano /etc/conf.d/ntp-client</i>
638<comment>Customize if you wish but the defaults should be fine</comment> 688<comment>Customize if you wish but the defaults should be fine</comment>
639# <i>rc-update add ntp-client default</i> 689# <i>rc-update add ntp-client default</i>
640 690
641# <i>nano /etc/ntp.conf</i> 691# <i>nano /etc/ntp.conf</i>
642<comment>Add the follwing lines: 692<comment>Add the follwing lines:</comment>
643restrict default ignore 693restrict default ignore
644restrict 192.168.0.0 mask 255.255.255.0 notrust nomodify notrap 694restrict 192.168.0.0 mask 255.255.255.0 notrust nomodify notrap
645These will allow only ntp clients with an IP address in the 192.168.0.xxx range to use your ntp server</comment> 695<comment>These will allow only ntp clients with an IP
696address in the 192.168.0.xxx range to use your ntp server</comment>
646# <i>nano /etc/conf.d/ntpd</i> 697# <i>nano /etc/conf.d/ntpd</i>
647<comment>Customize if you wish but the defaults should be fine</comment> 698<comment>Customize if you wish but the defaults should be fine</comment>
699# <i>rc-update add ntpd default</i>
648 700
649# <i>/etc/init.d/ntp-client start</i> 701# <i>/etc/init.d/ntp-client start</i>
650# <i>/etc/init.d/ntpd start</i> 702# <i>/etc/init.d/ntpd start</i>
651</pre> 703</pre>
652 704
705<note>
706You should make sure that you allow inbound and outbound communication on the
707ntp port (123/udp) when setting up the server. The client just needs outbound
708access on port 123 over udp.
709</note>
710
653<p> 711<p>
654Now, on your clients, have them <c>emerge ntp</c> also. However, 712Now, on your clients, have them <c>emerge ntp</c> also. However, we will just
655we will just run the ntp client so setup is a lot simpler. 713run the ntp client so setup is a lot simpler.
656</p> 714</p>
657 715
658<pre caption="Setting up a NTP client"> 716<pre caption="Setting up a NTP client">
659# <i>nano /etc/conf.d/ntp-client</i> 717# <i>nano /etc/conf.d/ntp-client</i>
660<comment>Change the 'pool.ntp.org' server in the NTPCLIENT_OPTS variable to '192.168.0.1'</comment> 718<comment>Change the 'pool.ntp.org' server in the NTPCLIENT_OPTS variable to '192.168.0.1'</comment>
661# <i>rc-update add ntp-client default</i> 719# <i>rc-update add ntp-client default</i>
662# <i>/etc/init.d/ntp-client start</i> 720# <i>/etc/init.d/ntp-client start</i>
663</pre> 721</pre>
722
723</body>
724</section>
725
726<section>
727<title>Rsync Server</title>
728<body>
729
730<p>
731For those who run multiple Gentoo boxes on the same lan, you often want to
732keep from having every machine running <c>emerge sync</c> with remote
733servers. By setting up a local rsync, you save on both your bandwidth and
734the Gentoo rsync servers' bandwidth. It's pretty simple to do.
735</p>
736
737<note>
738For a much more in-depth rsync guide, please see the official <uri
739link="/doc/en/rsync.xml#local">rsync guide</uri>.
740</note>
741
742<p>
743Since every Gentoo machine requires rsync, theres no need to emerge it. Edit
744the default <path>/etc/rsyncd.conf</path> config file, uncomment the
745<c>[gentoo-portage]</c> section, and make sure you add an <c>address</c>
746option. All the other defaults should be fine.
747</p>
748
749<pre caption="Rsync server config">
750pid file = /var/run/rsyncd.pid
751use chroot = yes
752read only = yes
753address = 192.168.0.1
754
755[gentoo-portage]
756 path = /mnt/space/portage
757 comment = Gentoo Linux Portage tree
758 exclude = /distfiles /packages
759</pre>
760
761<p>
762Then you need to start the service (again, the defaults are OK).
763</p>
764
765<pre caption="Starting the rsync server">
766# <i>/etc/init.d/rsyncd start</i>
767# <i>rc-update add rsyncd default</i>
768</pre>
769
770<p>
771Only thing left is to set tell your clients to sync against the router.
772</p>
773
774<pre caption="Client SYNC settings in make.conf">
775SYNC="rsync://192.168.0.1/gentoo-portage"
776</pre>
777
664</body> 778</body>
665</section> 779</section>
666 780
667<section> 781<section>
668<title>Mail Server</title> 782<title>Mail Server</title>
669<body> 783<body>
784
670<p> 785<p>
671Sometimes it's nice to run your own Simple Mail Transfer Protocol (SMTP) 786Sometimes it's nice to run your own Simple Mail Transfer Protocol (SMTP) server
672server on the router. You may have your own reason for wanting to do so, 787on the router. You may have your own reason for wanting to do so, but I run it
673but I run it so that the users see mail as being sent instantly and the 788so that the users see mail as being sent instantly and the work of
674work of retrying/routing is left up to the mail server. Some ISPs also 789retrying/routing is left up to the mail server. Some ISPs also don't allow for
675don't allow for mail relaying for accounts that aren't part of their 790mail relaying for accounts that aren't part of their network (like Verizon).
676network (like Verizon). Also, you can easily throttle the delivery of 791Also, you can easily throttle the delivery of mail so that large attachments
677mail so that large attachments won't seriously lag your connection for 792won't seriously lag your connection for half an hour.
678half an hour.
679</p> 793</p>
680 794
681<pre caption="Setting up SMTP"> 795<pre caption="Setting up SMTP">
682# <i>emerge qmail</i> 796# <i>emerge netqmail</i>
683<comment>make sure the output of `hostname` is correct</comment> 797<comment>make sure the output of `hostname` is correct</comment>
684# <i>ebuild /var/db/pkg/*-*/qmail-1.03-r*/*.ebuild config</i> 798# <i>emerge --config netqmail</i>
685# <i>iptables -I INPUT -p tcp --dport smtp -i ! eth0 -j REJECT</i> 799# <i>iptables -I INPUT -p tcp --dport smtp -i ! ${LAN} -j REJECT</i>
686# <i>ln -s /var/qmail/supervise/qmail-send /service/qmail-send</i> 800# <i>ln -s /var/qmail/supervise/qmail-send /service/qmail-send</i>
687# <i>ln -s /var/qmail/supervise/qmail-smtpd /service/qmail-smtpd</i> 801# <i>ln -s /var/qmail/supervise/qmail-smtpd /service/qmail-smtpd</i>
688<!-- 802<!--
689# <i>cd /etc/tcprules.d</i> 803# <i>cd /etc/tcprules.d</i>
690# <i>nano tcp.qmail-smtp</i> 804# <i>nano tcp.qmail-smtp</i>
691--> 805-->
692# <i>cd /etc</i> 806# <i>cd /etc</i>
693# <i>nano tcp.smtp</i> 807# <i>nano tcp.smtp</i>
694<comment>Add an entry like so to the allow section: 808<comment>Add an entry like so to the allow section:</comment>
695192.168.0.:allow,RELAYCLIENT=""</comment> 809192.168.0.:allow,RELAYCLIENT=""
696<!-- 810<!--
697# <i>tcprules tcp.qmail-qmtp.cdb rules.tmp &lt; tcp.qmail-smtp</i> 811# <i>tcprules tcp.qmail-qmtp.cdb rules.tmp &lt; tcp.qmail-smtp</i>
698--> 812-->
699# <i>tcprules tcp.smtp.cdb rules.tmp &lt; tcp.smtp</i> 813# <i>tcprules tcp.smtp.cdb rules.tmp &lt; tcp.smtp</i>
700# <i>rc-update add svscan default</i> 814# <i>rc-update add svscan default</i>
701# <i>/etc/init.d/svscan start</i> 815# <i>/etc/init.d/svscan start</i>
702</pre> 816</pre>
703 817
704<p> 818<p>
705I'm a huge fan of qmail, but you're free to use a different mta :). 819I'm a huge fan of netqmail, but you're free to use a different mta :). When you
706When you setup e-mail on the hosts in your network, tell them that 820setup e-mail on the hosts in your network, tell them that their SMTP server is
707their SMTP server is 192.168.0.1 and everything should be peachy. 821192.168.0.1 and everything should be peachy. You might want to visit the <uri
708You might want to visit the <uri link="http://qmail.org/">qmail 822link="http://netqmail.org/">netqmail homepage</uri> for more documentation.
709homepage</uri> for more documentation.
710</p> 823</p>
824
711</body> 825</body>
712</section> 826</section>
713 827
714<!-- 828<!--
715<section> 829<section>
728 842
729</body> 843</body>
730</section> 844</section>
731--> 845-->
732 846
847<section>
848<title>Full DHCP Server</title>
849<body>
850
851<p>
852Earlier we used dnsmasq to provide DHCP service to all our clients. For most
853people with a simple small LAN, this is perfect. But you may need something
854with more features. Thus we turn to a full-featured DHCP server as provided
855by the <uri link="http://www.isc.org/products/DHCP">ISC</uri> folks.
856</p>
857
858<pre caption="Setting up dhcpd">
859# <i>emerge dhcp</i>
860# <i>nano /etc/dhcp/dhcpd.conf</i>
861<comment>(Here is a sample configuration file:)</comment>
862authoritative;
863ddns-update-style interim;
864subnet 192.168.0.0 netmask 255.255.255.0 {
865 range 192.168.0.100 192.168.0.250;
866 default-lease-time 259200;
867 max-lease-time 518400;
868 option subnet-mask 255.255.255.0;
869 option broadcast-address 192.168.0.255;
870 option routers 192.168.0.1;
871 option domain-name-servers 192.168.0.1;
872}
873# <i>nano /etc/conf.d/dhcpd</i>
874<comment>(Set IFACE="eth0")</comment>
875# <i>rc-update add dhcpd default</i>
876# <i>/etc/init.d/dhcpd start</i>
877</pre>
878
879<p>
880This is the minimal setup required to replace the dnsmasq DHCP functionality
881that we used earlier. Speaking of which, you did remember to disable the DHCP
882features in dnsmasq didn't you? If not, you should do so now (just comment
883out the <c>dhcp-range</c> setting in <path>/etc/dnsmasq.conf</path> and restart
884the service).
885</p>
886
887</body>
888</section>
889
890<section>
891<title>Connect Another LAN (or two or three or ...)</title>
892<body>
893
894<p>
895Sometimes you have need of connecting the router to another LAN. Maybe you
896want to hook up a group of friends temporarily, or you're a neat freak and
897want to section off different groups of computers, or you're just really
898really bored. Whatever the reasons, extending the router to other LAN
899networks should be pretty straightforward. In the following examples, I will
900assume that this new network is connected via a third ethernet card, namely
901<c>eth2</c>.
902</p>
903
904<p>
905First you need to configure the interface. Just take the instructions in the
906<uri link="#doc_chap4_pre1">4.1 code listing</uri> and replace <c>eth0</c>
907with <c>eth2</c> and <c>192.168.0</c> with <c>192.168.1</c>.
908</p>
909
910<p>
911Then you need to tweak dnsmasq to service the new interface. Just edit the
912<path>/etc/conf.d/dnsmasq</path> file again and append <c>-i eth2</c> to
913DNSMASQ_OPTS; using -i multiple times is OK. Then edit
914<path>/etc/dnsmasq.conf</path> and add another line like the dhcp-range line
915in the <uri link="#doc_chap5_pre1">5.1 code listing</uri>, replacing
916<c>192.168.0</c> with <c>192.168.1</c>. Having multiple dhcp-range lines is
917OK too.
918</p>
919
920<p>
921Finally, see the rules in the <uri link="#doc_chap5_pre2">5.2 code
922listing</uri> and duplicate the rules that have <c>-i ${LAN}</c> in them. You
923may want to create another variable, say <c>LAN2</c>, to make things easier.
924</p>
925
926</body>
927</section>
928
929</chapter>
930
931<chapter>
932<title>Troubleshooting</title>
933
934<section>
935<title>Useful Tools</title>
936<body>
937
938<p>
939If you're having trouble getting your computers to communicate, you may way to
940try out the following tools (they can all be found in the <c>net-analyzer</c>
941portage category):
942</p>
943
944<table>
945<tr>
946 <th>Utility</th>
947 <th>Description</th>
948</tr>
949<tr>
950 <ti>wireshark</ti>
951 <ti>GUI tool to view all raw network data according to filters</ti>
952</tr>
953<tr>
954 <ti>tcpdump</ti>
955 <ti>Console tool to dump all raw network data according to filters</ti>
956</tr>
957<tr>
958 <ti>iptraf</ti>
959 <ti>ncurses based IP LAN monitor</ti>
960</tr>
961<tr>
962 <ti>ettercap</ti>
963 <ti>ncurses based network monitor/control</ti>
964</tr>
965</table>
966
967</body>
968</section>
969
970<section>
971<title>DHCP Fails To Start</title>
972<body>
973
974<p>
975When starting the dhcp init.d script for the first time, it may fail to load
976but neglect to give you any useful info.
977</p>
978
979<pre caption="DHCP Failing Example">
980# <i>/etc/init.d/dhcp start</i>
981 * Setting ownership on dhcp.leases ... [ ok ]
982 * Starting dhcpd ... [ !! ]
983</pre>
984
985<p>
986The trick is to know where dhcpd is sending its output. Simply browse to
987<path>/var/log</path> and read the log files. Since the exact log file depends
988on the package you are using as a syslog, try running <c>grep -Rl dhcpd
989/var/log</c> to narrow down the possibilities. Chances are you made a typo in
990your config file. You could also try running <c>dhcpd -d -f</c> (short for
991debug / foreground) and debug the error based upon the output.
992</p>
993
994</body>
995</section>
996
997<section>
998<title>Incorrect MTU Value</title>
999<body>
1000
1001<p>
1002If you experience odd errors (such as not being able to access some webpages
1003while others load fine), you may be having Path MTU Discovery trouble. The
1004quick way to test is to run this iptables command:
1005</p>
1006
1007<pre caption="Circumvent MTU issues">
1008# <i>iptables -A FORWARD -p tcp --tcp-flags SYN,RST SYN -j TCPMSS --clamp-mss-to-pmtu</i>
1009</pre>
1010
1011<p>
1012This will affect all new connections, so just refresh the website you're having
1013problems with in order to test. In case it helps, the standard MTU value for
1014100mbit ethernet connections is <c>1500</c>; this value also applies to PPPoA.
1015For PPPoE connections it is <c>1492</c>. For more info, you should read Chapter
101615 of the <uri link="http://lartc.org/howto/">Linux Advanced Routing &amp;
1017Traffic Control HOWTO</uri>.
1018</p>
1019
1020</body>
1021</section>
1022
1023<section>
1024<title>Unable to connect two machines directly</title>
1025<body>
1026
1027<p>
1028If (for whatever reason) you want to connect two machines directly together
1029without a hub or switch, a regular ethernet cable will likely not work, unless
1030you have an Auto MDI/MDI-X (also known as "autosensing") capable network
1031adapter. You will need a different cable called a crossover cable. This <uri
1032link="http://en.wikipedia.org/wiki/Ethernet_crossover_cable">Wikipedia</uri>
1033page explains the low level details.
1034</p>
1035
1036</body>
1037</section>
1038
733</chapter> 1039</chapter>
734 1040
735<chapter> 1041<chapter>
736<title>Final Notes</title> 1042<title>Final Notes</title>
737<section> 1043<section>
738<body> 1044<body>
1045
739<p> 1046<p>
740I have no final notes other than if you experience any troubles with the guide, 1047I have no final notes other than if you experience any troubles with the guide,
741please contact <mail link="vapier@gentoo.org">me</mail> or file a bug with 1048please contact <mail link="vapier@gentoo.org">me</mail> or file a bug with <uri
742<uri link="http://bugs.gentoo.org/">Gentoo's Bugtracking Website</uri>. If 1049link="http://bugs.gentoo.org/">Gentoo's Bugtracking Website</uri>. If you have
743you have some interesting bits you think would enhance this guide, by all means 1050some interesting bits you think would enhance this guide, by all means send it
744send it my way for inclusion. 1051my way for inclusion.
745</p> 1052</p>
1053
746</body> 1054</body>
747</section> 1055</section>
748</chapter> 1056</chapter>
749</guide> 1057</guide>

Legend:
Removed from v.1.15  
changed lines
  Added in v.1.56

  ViewVC Help
Powered by ViewVC 1.1.20