/[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.30 - (hide annotations) (download) (as text)
Sun Aug 14 04:38:48 2005 UTC (8 years, 11 months ago) by vapier
Branch: MAIN
Changes since 1.29: +35 -27 lines
File MIME type: application/xml
replace eth0 with $LAN and eth1 with $WAN and rename Debugging section to Troubleshooting #102450 by Arnold Miller

1 vapier 1.1 <?xml version='1.0' encoding='UTF-8'?>
2 vapier 1.30 <!-- $Header: /var/cvsroot/gentoo/xml/htdocs/doc/en/home-router-howto.xml,v 1.29 2005/08/04 00:18:20 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.30 <version>1.10</version>
19     <date>2005-08-14</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     the router (dhcpd), give it all the information about your network (valid IPs,
303     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.1 <pre caption="Setting up dhcpd">
310     # <i>emerge dhcp</i>
311     # <i>nano /etc/dhcp/dhcpd.conf</i>
312 neysx 1.23 <comment>(Here is a sample configuration file:)</comment>
313 vapier 1.1 authoritative;
314 swift 1.26 ddns-update-style interim;
315 vapier 1.1 subnet 192.168.0.0 netmask 255.255.255.0 {
316 neysx 1.23 range 192.168.0.100 192.168.0.250;
317     default-lease-time 259200;
318     max-lease-time 518400;
319     option subnet-mask 255.255.255.0;
320     option broadcast-address 192.168.0.255;
321     option routers 192.168.0.1;
322     option domain-name-servers 192.168.0.1;
323 vapier 1.1 }
324     # <i>nano /etc/conf.d/dhcp</i>
325 neysx 1.23 <comment>(Set IFACE="eth0")</comment>
326 vapier 1.1 # <i>rc-update add dhcp default</i>
327     # <i>/etc/init.d/dhcp start</i>
328     </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     you may have to run a command prompt and run <c>ipconfig /release</c> and
336     <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     string of useless numbers. After all, what's easier to remember, ebay.com or
350     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 neysx 1.23 You may have noticed in the previous section that we told the DHCP clients we
359     have a DNS server at 192.168.0.1. You may also remember that 192.168.0.1 is
360     our little router that we're making. I don't remember setting up a DNS server
361     ... so let's do so now!
362 vapier 1.1 </p>
363    
364     <pre caption="Setting up dnsmasq">
365     # <i>emerge dnsmasq</i>
366     # <i>nano /etc/conf.d/dnsmasq</i>
367 vapier 1.18 <comment>Add "-i eth0" to DNSMASQ_OPTS</comment>
368 vapier 1.11 # <i>rc-update add dnsmasq default</i>
369 vapier 1.1 # <i>/etc/init.d/dnsmasq start</i>
370     </pre>
371    
372     <p>
373 neysx 1.23 Well that was quick, but what did we do? The great thing is, we didn't have to
374     do very much! You're welcome to choose other DNS servers if you're more
375     comfortable with them, but the reason dnsmasq is great is because it was
376     designed to do exactly what we want and nothing more. It's a little DNS
377     caching/forwarding server for local networks. We're not looking to provide DNS
378     for our own domain here, just offer simple DNS services to everyone else on our
379     LAN.
380 vapier 1.1 </p>
381    
382     </body>
383     </section>
384    
385     <section>
386 vapier 1.4 <title>NAT (a.k.a. IP-masquerading)</title>
387 vapier 1.1 <body>
388    
389     <p>
390 neysx 1.23 At this point, people on your network can talk to each other and they can look
391     up hostnames via DNS, but they still can't actually connect to the internet.
392     While you may think that's great (more bandwidth for you!), I bet they're not
393     too happy just yet.
394 vapier 1.1 </p>
395    
396 vapier 1.2 <p>
397 neysx 1.23 This is where NAT steps in. NAT is a way of connecting multiple computers in a
398     private LAN to the internet when you only have a smaller number of IP addresses
399     availabe to you. Typically you were given 1 IP by your ISP, but you want to
400     let your whole house connect to the internet. NAT is the magic that makes this
401     possible. For more information about NAT, you can always visit <uri
402     link="http://en.wikipedia.org/wiki/NAT">Wikipedia</uri>.
403 vapier 1.2 </p>
404    
405     <note>
406 neysx 1.23 Before we get started, make sure you have iptables on your system. Although it
407     is automatically installed on most systems, you may not have it. If you don't,
408     just run <c>emerge iptables</c>.
409 vapier 1.2 </note>
410    
411 vapier 1.1 <pre caption="Setting up iptables">
412     <comment>First we flush our current rules</comment>
413     # <i>iptables -F</i>
414     # <i>iptables -t nat -F</i>
415    
416 vapier 1.30 <comment>Copy and paste these examples ...</comment>
417     # <i>export LAN=eth0</i>
418     # <i>export WAN=eth1</i>
419    
420 vapier 1.1 <comment>Then we lock our services so they only work from the LAN</comment>
421 vapier 1.30 # <i>iptables -I INPUT 1 -i ${LAN} -j ACCEPT</i>
422 vapier 1.1 # <i>iptables -I INPUT 1 -i lo -j ACCEPT</i>
423 vapier 1.30 # <i>iptables -A INPUT -p UDP --dport bootps -i ! ${LAN} -j REJECT</i>
424     # <i>iptables -A INPUT -p UDP --dport domain -i ! ${LAN} -j REJECT</i>
425 vapier 1.1
426 vapier 1.21 <comment>(Optional) Allow access to our ssh server from the WAN</comment>
427 vapier 1.30 # <i>iptables -A INPUT -p TCP --dport ssh -i ${WAN} -j ACCEPT</i>
428 vapier 1.21
429 vapier 1.1 <comment>Drop TCP / UDP packets to privileged ports</comment>
430 vapier 1.30 # <i>iptables -A INPUT -p TCP -i ! ${LAN} -d 0/0 --dport 0:1023 -j DROP</i>
431     # <i>iptables -A INPUT -p UDP -i ! ${LAN} -d 0/0 --dport 0:1023 -j DROP</i>
432 vapier 1.1
433     <comment>Finally we add the rules for NAT</comment>
434 vapier 1.30 # <i>iptables -I FORWARD -i ${LAN} -d 192.168.0.0/255.255.0.0 -j DROP</i>
435     # <i>iptables -A FORWARD -i ${LAN} -s 192.168.0.0/255.255.0.0 -j ACCEPT</i>
436     # <i>iptables -A FORWARD -i ${WAN} -d 192.168.0.0/255.255.0.0 -j ACCEPT</i>
437     # <i>iptables -t nat -A POSTROUTING -o ${WAN} -j MASQUERADE</i>
438 vapier 1.1 <comment>Tell the kernel that ip forwarding is OK</comment>
439     # <i>echo 1 > /proc/sys/net/ipv4/ip_forward</i>
440     # <i>for f in /proc/sys/net/ipv4/conf/*/rp_filter ; do echo 1 > $f ; done</i>
441    
442     <comment>This is so when we boot we don't have to run the rules by hand</comment>
443     # <i>/etc/init.d/iptables save</i>
444     # <i>rc-update add iptables default</i>
445 vapier 1.14 # <i>nano /etc/sysctl.conf</i>
446     <comment>Add/Uncomment the following lines:
447     net.ipv4.ip_forward = 1
448     net.ipv4.conf.default.rp_filter = 1</comment>
449 vapier 1.1 </pre>
450    
451     <p>
452 neysx 1.23 Once you've typed out all of that, the rest of your network should now be able
453     to use the internet as if they were directly connected themselves.
454 vapier 1.1 </p>
455    
456 vapier 1.3 </body>
457     </section>
458     </chapter>
459    
460     <chapter>
461     <title>Fun Things (for a rainy day)</title>
462    
463     <section>
464     <title>Intro</title>
465     <body>
466 neysx 1.23
467 vapier 1.1 <p>
468 neysx 1.23 Believe it or not, you're done :). From here on out, I'll cover a bunch of
469     common topics that may interest you. Everything in this chapter is completely
470     optional.
471 vapier 1.1 </p>
472 neysx 1.23
473 vapier 1.3 </body>
474     </section>
475 vapier 1.1
476 vapier 1.3 <section>
477     <title>Port Forwarding</title>
478     <body>
479 neysx 1.23
480 vapier 1.3 <p>
481 neysx 1.23 Sometimes you would like to be able to host services on a computer behind the
482     router, or just to make your life easier when connecting remotely. Perhaps you
483     want to run a FTP, HTTP, SSH, or VNC server on one or more machines behind your
484     router and be able to connect to them all. The only caveat is that you can
485     only have one service/machine combo per port. For example, there is no
486     practical way to setup three FTP servers behind your router and then try to
487     connect to them all through port 21; only one can be on port 21 while the
488     others would have to be on say port 123 and port 567.
489 vapier 1.3 </p>
490    
491     <p>
492 neysx 1.23 All the port forwarding rules are of the form <c>iptables -t nat -A PREROUTING
493 vapier 1.30 [-p protocol] --dport [external port on router] -i ${WAN} -j DNAT --to [ip/port
494 neysx 1.23 to forward to]</c>. iptables does not accept hostnames when port forwarding.
495     If you are forwarding an external port to the same port on the internal
496     machine, you can omit the destination port. See the iptables(8) page for more
497     information.
498 vapier 1.3 </p>
499    
500 swift 1.28 <pre caption="Running the iptables commands">
501 vapier 1.30 <comment>Copy and paste these examples ...</comment>
502     # <i>export LAN=eth0</i>
503     # <i>export WAN=eth1</i>
504    
505 vapier 1.3 <comment>Forward port 2 to ssh on an internal host</comment>
506 vapier 1.30 # <i>iptables -t nat -A PREROUTING -p tcp --dport 2 -i ${WAN} -j DNAT --to 192.168.0.2:22</i>
507 vapier 1.3
508     <comment>FTP forwarding to an internal host</comment>
509 vapier 1.30 # <i>iptables -t nat -A PREROUTING -p tcp --dport 21 -i ${WAN} -j DNAT --to 192.168.0.56</i>
510 vapier 1.3
511     <comment>HTTP forwarding to an internal host</comment>
512 vapier 1.30 # <i>iptables -t nat -A PREROUTING -p tcp --dport 80 -i ${WAN} -j DNAT --to 192.168.0.56</i>
513 vapier 1.3
514     <comment>VNC forwarding for internal hosts</comment>
515 vapier 1.30 # <i>iptables -t nat -I PREROUTING -p tcp --dport 5900 -i ${WAN} -j DNAT --to 192.168.0.2</i>
516     # <i>iptables -t nat -I PREROUTING -p tcp --dport 5901 -i ${WAN} -j DNAT --to 192.168.0.3:5900</i>
517 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>
518    
519     <comment>Bittorrent forwarding</comment>
520 vapier 1.30 # <i>iptables -t nat -A PREROUTING -p tcp --dport 6881:6889 -i ${WAN} -j DNAT --to 192.168.0.2</i>
521 vapier 1.15
522     <comment>Game Cube Warp Pipe support</comment>
523 vapier 1.30 # <i>iptables -t nat -A PREROUTING -p udp --dport 4000 -i ${WAN} -j DNAT --to 192.168.0.56</i>
524 vapier 1.15
525     <comment>Playstation2 Online support</comment>
526 vapier 1.30 # <i>iptables -t nat -A PREROUTING -p tcp --dport 10070:10080 -i ${WAN} -j DNAT --to 192.168.0.11</i>
527     # <i>iptables -t nat -A PREROUTING -p udp --dport 10070:10080 -i ${WAN} -j DNAT --to 192.168.0.11</i>
528 vapier 1.3 </pre>
529    
530     <note>
531 neysx 1.23 If you have other common / cool examples, please <uri
532     link="mailto:vapier@gentoo.org">e-mail me</uri>.
533 vapier 1.3 </note>
534 neysx 1.23
535 vapier 1.3 </body>
536     </section>
537    
538     <section>
539     <title>Identd (for IRC)</title>
540     <body>
541 neysx 1.23
542 vapier 1.3 <p>
543 neysx 1.23 Internet Relay Chat utilizes the ident service pretty heavily. Now that the
544     IRC clients are behind the router, we need a way to host ident for both the
545     router and the clients. One such server has been created called
546     <c>midentd</c>.
547 vapier 1.3 </p>
548    
549     <pre caption="Setting up ident">
550     # <i>emerge midentd</i>
551     # <i>rc-update add midentd default</i>
552     # <i>/etc/init.d/midentd start</i>
553     </pre>
554    
555     <p>
556 neysx 1.23 There are a few other ident servers in portage. Depending on your needs, I
557     would recommend checking out <c>oidentd</c> and <c>fakeidentd</c>.
558 vapier 1.3 </p>
559 neysx 1.23
560 vapier 1.3 </body>
561     </section>
562    
563 vapier 1.5 <!--
564     <section>
565     <title>Traffic Shaping</title>
566     <body>
567     <p>
568     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>
569     found over at the TLDP. Feel free to refer to the original document
570     for more details.
571     </p>
572    
573     <p>
574     Here we will be setting up what some people refer to as a "Packet Shaper",
575     <uri link="http://en.wikipedia.org/wiki/Traffic_shaping">"Traffic Shaping"</uri>,
576     or <uri link="http://en.wikipedia.org/wiki/QoS">"Quality of Service"</uri>.
577     Simply put, we want to setup rules on our router that will slow down
578     certain activities (like sending large e-mails or downloading from P2P
579     networks) while keeping other activities (like browsing the web or playing
580     online video games) reasonably fast. A 30 second difference in a video
581     game is a lot worse than a 30 second difference in downloading large
582     files :).
583     </p>
584    
585     <p>
586     The first thing is to make sure your kernel has all the features added to
587     it. See the chapter on <uri link="#doc_chap2">Kernel setup</uri> for more
588     information. Next, you will need to <c>emerge iptables iputils</c> so that
589     you will have access to the <c>iptables</c>, <c>ip</c>, and <c>tc</c>
590     commands.
591     </p>
592    
593     <p>
594     Before we jump into the commands, let's cover a little of the theory. The
595     way this whole system works is to classify common network streams and then
596     to prioritize them. You use iptables to classify network streams, iputils
597     to define the different priority levels, and the kernel to adjust speeds.
598     Just remember that although you can control outbound traffic pretty tightly
599     (from the LAN to the WAN), your ability to control inbound traffic (from
600     the WAN to the LAN) is somewhat limited. Just remember that the following
601     examples are to get your feet wet; if you want more then I'd suggest
602     reading up on the subject. In this example, we will be using the
603     <uri link="http://luxik.cdi.cz/~devik/qos/htb/">Hierarchical Token Buckets (HTB)</uri>
604     packet scheduling algorithm. Still with me? Great, let's start shaping :).
605     </p>
606    
607     <pre caption="Setup">
608     DEV=eth1 <comment>NIC connected to WAN</comment>
609     RATE_OUT=100 <comment>Available outbound bandwidth (in kilobits [kb])</comment>
610     RATE_IN=1400 <comment>Available inbound bandwidth (in kb)</comment>
611    
612     <comment>Here we initialize the priority system. The 45 is used to set the default classification level.</comment>
613     ip link set dev ${DEV} qlen 30
614     tc qdisc add dev ${DEV} root handle 1: htb default 45
615     tc class add dev ${DEV} parent 1: classid 1:1 htb rate ${RATE_OUT}kbit
616     </pre>
617    
618     <p>
619     Here we initialized the system which will be used to prioritize all of
620     our network traffic. We created our queue, told it to use the HTB
621     algorithm, and set the default classification level to '45'. The
622     default is completely arbitrary, as are the levels we choose from
623     here on out. The only thing that matters is how the levels compare
624     relatively; a level '10' packet will be given preference over a
625     level '45' packet. Let's move on to declaring different levels.
626     </p>
627    
628     <pre caption="Declaring levels">
629     tc class add dev $DEV parent 1:1 classid 1:10 htb rate $rkbit ceil $tkbit prio $p
630     tc qdisc add dev $DEV parent 1:10 handle 10: sfq
631     </pre>
632     </body>
633     </section>
634     -->
635    
636 vapier 1.3 <section>
637 vapier 1.9 <title>Time Server</title>
638     <body>
639 neysx 1.23
640 vapier 1.9 <p>
641 vapier 1.24 Keeping your system time correct is essential in maintaining a healthy system.
642 neysx 1.23 One of the most common ways of accomplishing this is with the Network Time
643     Protocol (NTP) and the ntp package (which provides implementations for both
644     server and client).
645 vapier 1.9 </p>
646    
647     <p>
648 neysx 1.23 Many people run ntp clients on their computers. Obviously, the more clients in
649     the world, the larger the load the ntp servers need to shoulder. In
650     environments like home networks though, we can help keep the load down on
651     public servers while still providing the proper time to all our computers. As
652     an added bonus, our private updates will be a lot faster for the clients too!
653     All we have to do is run a ntp server on our router that synchronizes itself
654     with the public internet servers while providing the time to the rest of the
655     computers in the network. To get started, simply <c>emerge ntp</c> on the
656 vapier 1.9 router.
657     </p>
658    
659     <pre caption="Setting up the NTP server">
660     # <i>nano /etc/conf.d/ntp-client</i>
661     <comment>Customize if you wish but the defaults should be fine</comment>
662     # <i>rc-update add ntp-client default</i>
663    
664     # <i>nano /etc/ntp.conf</i>
665 neysx 1.23 <comment>Add the follwing lines:</comment>
666 vapier 1.9 restrict default ignore
667     restrict 192.168.0.0 mask 255.255.255.0 notrust nomodify notrap
668 neysx 1.23 <comment>These will allow only ntp clients with an IP
669     address in the 192.168.0.xxx range to use your ntp server</comment>
670 vapier 1.9 # <i>nano /etc/conf.d/ntpd</i>
671     <comment>Customize if you wish but the defaults should be fine</comment>
672 vapier 1.17 # <i>rc-update add ntpd default</i>
673 vapier 1.9
674     # <i>/etc/init.d/ntp-client start</i>
675     # <i>/etc/init.d/ntpd start</i>
676     </pre>
677    
678 vapier 1.22 <note>
679 neysx 1.23 You should make sure that you allow inbound and outbound communication on the
680     ntp port (123/udp) when setting up the server. The client just needs outbound
681     access on port 123 over udp.
682 vapier 1.22 </note>
683    
684 vapier 1.9 <p>
685 neysx 1.23 Now, on your clients, have them <c>emerge ntp</c> also. However, we will just
686     run the ntp client so setup is a lot simpler.
687 vapier 1.9 </p>
688    
689     <pre caption="Setting up a NTP client">
690     # <i>nano /etc/conf.d/ntp-client</i>
691     <comment>Change the 'pool.ntp.org' server in the NTPCLIENT_OPTS variable to '192.168.0.1'</comment>
692     # <i>rc-update add ntp-client default</i>
693     # <i>/etc/init.d/ntp-client start</i>
694     </pre>
695 neysx 1.23
696 vapier 1.9 </body>
697     </section>
698    
699     <section>
700 vapier 1.29 <title>Rsync Server</title>
701     <body>
702    
703     <p>
704     For those who run multiple Gentoo boxes on the same lan, you often want to
705     keep from having every machine running <c>emerge sync</c> with remote
706     servers. By setting up a local rsync, you save on both your bandwidth and
707     the Gentoo rsync servers' bandwidth. It's pretty simple to do.
708     </p>
709     <note>
710     For a much more in-depth rsync guide, please see the official <uri
711     link="/doc/en/rsync.xml#doc_chap4">rsync guide</uri>
712     </note>
713    
714     <p>
715     Since every Gentoo machine requires rsync, theres no need to emerge it. Edit
716     the default <path>/etc/rsyncd.conf</path> config file, uncomment the
717     <c>[gentoo-portage]</c> section, and make sure you add an <c>address</c>
718     option. All the other defaults should be fine.
719     </p>
720    
721     <pre caption="Rsync server config">
722     pid file = /var/run/rsyncd.pid
723     use chroot = yes
724     read only = yes
725     address = 192.168.0.1
726    
727     [gentoo-portage]
728     path = /mnt/space/portage
729     comment = Gentoo Linux Portage tree
730     exclude = /distfiles /packages
731     </pre>
732    
733     <p>
734     Then you need to start the service (again, the defaults are OK).
735     </p>
736    
737     <pre caption="Starting the rsync server">
738     # <i>/etc/init.d/rsyncd start</i>
739     # <i>rc-update add rsyncd default</i>
740     </pre>
741    
742     <p>
743     Only thing left is to set tell your clients to sync against the router.
744     </p>
745    
746     <pre caption="Client SYNC settings in make.conf">
747     SYNC="rsync://192.168.0.1/gentoo-portage"
748     </pre>
749    
750     </body>
751     </section>
752    
753     <section>
754 vapier 1.3 <title>Mail Server</title>
755     <body>
756 neysx 1.23
757 vapier 1.3 <p>
758 neysx 1.23 Sometimes it's nice to run your own Simple Mail Transfer Protocol (SMTP) server
759     on the router. You may have your own reason for wanting to do so, but I run it
760     so that the users see mail as being sent instantly and the work of
761     retrying/routing is left up to the mail server. Some ISPs also don't allow for
762     mail relaying for accounts that aren't part of their network (like Verizon).
763     Also, you can easily throttle the delivery of mail so that large attachments
764     won't seriously lag your connection for half an hour.
765 vapier 1.4 </p>
766    
767     <pre caption="Setting up SMTP">
768     # <i>emerge qmail</i>
769     <comment>make sure the output of `hostname` is correct</comment>
770     # <i>ebuild /var/db/pkg/*-*/qmail-1.03-r*/*.ebuild config</i>
771 vapier 1.30 # <i>iptables -I INPUT -p tcp --dport smtp -i ! ${LAN} -j REJECT</i>
772 vapier 1.4 # <i>ln -s /var/qmail/supervise/qmail-send /service/qmail-send</i>
773 vapier 1.10 # <i>ln -s /var/qmail/supervise/qmail-smtpd /service/qmail-smtpd</i>
774 vapier 1.13 <!--
775 vapier 1.4 # <i>cd /etc/tcprules.d</i>
776     # <i>nano tcp.qmail-smtp</i>
777 vapier 1.13 -->
778     # <i>cd /etc</i>
779     # <i>nano tcp.smtp</i>
780 neysx 1.23 <comment>Add an entry like so to the allow section:</comment>
781     192.168.0.:allow,RELAYCLIENT=""
782 vapier 1.13 <!--
783 vapier 1.4 # <i>tcprules tcp.qmail-qmtp.cdb rules.tmp &lt; tcp.qmail-smtp</i>
784 vapier 1.13 -->
785     # <i>tcprules tcp.smtp.cdb rules.tmp &lt; tcp.smtp</i>
786 vapier 1.4 # <i>rc-update add svscan default</i>
787     # <i>/etc/init.d/svscan start</i>
788     </pre>
789    
790     <p>
791 neysx 1.23 I'm a huge fan of qmail, but you're free to use a different mta :). When you
792     setup e-mail on the hosts in your network, tell them that their SMTP server is
793     192.168.0.1 and everything should be peachy. You might want to visit the <uri
794     link="http://qmail.org/">qmail homepage</uri> for more documentation.
795 vapier 1.3 </p>
796 neysx 1.23
797 vapier 1.3 </body>
798     </section>
799    
800 vapier 1.4 <!--
801 vapier 1.3 <section>
802 vapier 1.4 <title>E-mail Virus Scanning</title>
803 vapier 1.3 <body>
804     <p>
805 vapier 1.4 If you'd like to provide e-mail virus scanning for your users, but
806     don't want to have to install a virus scanner on every single machine,
807     then <c>pop3vscan</c> may just be the thing for you; a transparent
808     Post Office Protocol (POP) scanner.
809 vapier 1.3 </p>
810 vapier 1.4
811     <pre caption="Setting up pop3vscan">
812     TODO
813     </pre>
814    
815 vapier 1.3 </body>
816     </section>
817 vapier 1.4 -->
818 vapier 1.3
819 vapier 1.4 </chapter>
820    
821     <chapter>
822 vapier 1.30 <title>Troubleshooting</title>
823 vapier 1.27
824     <section>
825     <title>Useful Tools</title>
826     <body>
827    
828     <p>
829     If you're having trouble getting your computers to communicate, you may way to
830     try out the following tools (they can all be found in the <c>net-analyzer</c>
831     portage category):
832     </p>
833    
834     <table>
835     <tr>
836     <th>Utility</th>
837     <th>Description</th>
838     </tr>
839     <tr>
840     <ti>ethereal</ti>
841     <ti>GUI tool to view all raw network data according to filters</ti>
842     </tr>
843     <tr>
844     <ti>tcpdump</ti>
845     <ti>Console tool to dump all raw network data according to filters</ti>
846     </tr>
847     <tr>
848     <ti>iptraf</ti>
849     <ti>ncurses based IP LAN monitor</ti>
850     </tr>
851     <tr>
852     <ti>ettercap</ti>
853     <ti>ncurses based network monitor/control</ti>
854     </tr>
855     </table>
856    
857     </body>
858     </section>
859    
860     <section>
861     <title>Incorrect MTU Value</title>
862     <body>
863    
864     <p>
865     If you experience odd errors (such as not being some webpages while others
866     load fine), you may be having Path MTU Discovery trouble. The quick way to
867     test is to run this iptables command:
868     </p>
869    
870     <pre caption="Circumvent MTU issues">
871     # <i>iptables -A FORWARD -p tcp --tcp-flags SYN,RST SYN -j TCPMSS --clamp-mss-to-pmtu</i>
872     </pre>
873    
874     <p>
875     This will affect all new connections, so just refresh the website you're
876     having problems with in order to test. In case it helps, the standard MTU
877     value for 100mbit ethernet connections is <c>1500</c> while for PPPoE
878     connections it is <c>1492</c>. For more info, you should read Chapter 15
879     of the <uri link="http://lartc.org/howto/">Linux Advanced Routing &amp;
880     Traffic Control HOWTO</uri>.
881     </p>
882    
883     </body>
884     </section>
885    
886     </chapter>
887    
888     <chapter>
889 vapier 1.4 <title>Final Notes</title>
890 vapier 1.3 <section>
891     <body>
892 neysx 1.23
893 vapier 1.3 <p>
894 neysx 1.23 I have no final notes other than if you experience any troubles with the guide,
895     please contact <mail link="vapier@gentoo.org">me</mail> or file a bug with <uri
896     link="http://bugs.gentoo.org/">Gentoo's Bugtracking Website</uri>. If you have
897     some interesting bits you think would enhance this guide, by all means send it
898     my way for inclusion.
899 vapier 1.3 </p>
900 neysx 1.23
901 vapier 1.1 </body>
902     </section>
903     </chapter>
904     </guide>

  ViewVC Help
Powered by ViewVC 1.1.20