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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.34 - (hide annotations) (download) (as text)
Tue Oct 11 01:02:53 2005 UTC (8 years, 11 months ago) by vapier
Branch: MAIN
Changes since 1.33: +8 -3 lines
File MIME type: application/xml
add example for Xbox Live from Chris Slycord

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

  ViewVC Help
Powered by ViewVC 1.1.20