Home router/ko

This document details how to turn an old Gentoo machine into a router for connecting your home network to the internet.

도입부
오래된 부품으로 라우터를 구축하는 작업은 Linksys에서 깡통처럼 만들어둔 걸 사는 것보다 여러 면에서 장점을 지니고 있습니다. 특장점이라면 연결을 전반적으로 취급할 수 있다는 점입니다. 다른 장점은 여러분의 상상에 맏깁니다. 어떤 것이든 필요한 요소로 이루어진 시나리오를 통해 가능합니다.

이 안내서에선 네트워크 주소 변환(NAT) 기능을 라우터(커널 및 iptables)에서 설정하는 방법, 일반적인 서비스(dnsmasq를 통한 도메인 이름 체계(DNS)설정, dhcpcd를 통한 dhcp 사용, ppp를 통한 ADSL연결)를 추가하고 설정하는 방법을 안내하며, 해낼 수 있는 보다 정교한 재미거리(포트 포워딩, 트래픽 셰이핑, 프록시/캐싱, 등...)로 마무리 하겠습니다.

시작하기 전에, 몇가지 알아야 할 기본 요구사항이 있습니다. 먼저 여러분의 카드에 적어도 두 개 이상의 네트워크 인터페이스 카드(NICs)가 있어야 합니다. 그 다음 인터넷 연결을 설정해야 합니다(아마 IP/DNS/게이트웨이/사용자 이름/암호가 포함될지도 모릅니다). 마지막으로 약간의 여유 시간과 젠투에 대한 애정이 필요합니다.

이 안내서에서 따를 관례는 다음과 같습니다:


 * eth0 - 지역 네트워크(LAN)에 연결한 NIC
 * eth1 - 광역 네트워크(WAN)에 연결한 NIC
 * LAN은 192.168.0.xxx 네트워크로 동작함
 * 라우터는 표준 192.168.0.1 IP로 고정함
 * 라우터는 Linux 2.4또는 2.6커널에서 동작합니다. 2.0/2.2 커널을 사용중이라고 (가정) 합니다

커널 설정(너 자신을 알라)
커널에는 보유한 각각의 NIC를 동작케 하는 드라이버가 필요합니다. 카드를 이미 설정했다면 를 실행하기만 하면 됩니다. 다음의 과정과는 나온 내용이 약간 다르겠지만, 괜찮습니다. 다루어야 할 문제는 모든 인터페이스가 화면에 나타나야 한다는 것입니다.

두 네트워크 카드가 나타나지 않고, 어떤 카드를 붙였는지 알 수 없다면,  을 실행해보십시오. 로 프로그램을 가져올 수 있습니다. 이 정보를 끌어오고 나서는 커널 설정으로 가서 올바른 드라이버 지원을 추가하십시오.

그 다음 필요한 것은 iptables와 NAT(그리고 원할 경우 패킷 셰이핑) 지원입니다. 다음 목록은 항상 필요한 것(*), PPPoE를 통한 ADSL연결시(a), 모든 경우에 대해 추천(x), 셰이퍼(s) 기능용으로 나뉩니다. 기능을 커널에 포함을 하든 모듈로 빌드하든 상관 없기에 기능이 필요할 때면 올바른 모듈을 불러옵니다(모듈 불러오기는 어쨌거나 독자의 흥미 거리로 남겨둡니다).

도입부
인터넷에 연결하는 방법은 여러가지가 있습니다. 따라서 가장 익숙한 방법을 다루겠습니다. ADSL(PPPoE)과 케이블 모뎀(동적/정적)도 있습니다. 다른 방법이 있다면 약간의 설명을 적어 전자메일로 언제든 보내주세요. 해당 사항이 없으면 이 장을 어찌 됐든 건너뛰셔도 됩니다. 이 장은 eth1을 통해 인터넷으로 연결한 라우터를 만드는 방법을 다룹니다.

ADSL과 PPPoE
rp-pppoe(Roaring Penguin)에서 보통 제공하는 매력적인 모든 PPPoE 프로그램은 표준 PPP 패키지에 통합했습니다. 간단하게 를 실행하면 여러분의 뜻대로 됩니다. 여러분이 사용자 이름/암호 정보가 필요하다는 사실을 어떻게 말했는지 기억하시죠? 글쎄요, 전 뻥을 안쳤으니까 여러분이 그걸 지금 자각하고 있길 바랍니다. 여러분이 주로 쓰는 편집기에서 을 불러오고 설정해보세요.

다음 예제에서 'vla9h924'를 사용자 이름으로, 'boogie'를 암호로 바꾸세요.

케이블 또는 동적/정적 IP
고정 IP를 받았다면 동적 IP를 보유하고 있을 때보다 꼼꼼하게 더 해야 할 일이 있습니다. 정적 IP 사용자는 IP, 게이트웨이, DNS 서버 주소가 필요합니다.

동적 IP 사용자:

정적 IP 사용자:

동적 및 정적 설정:

모든 설정이 여기까지 해서 제대로 동작해야 합니다.

(일부 친구를 데려오는)LAN을 내 것으로 만들기
이 과정은 앞의 과정보다는 좀 더 수월합니다.

DHCP 서버
다른 사람들이 여러분의 집에 찾아와서 네트워크에 컴퓨터를 연결하고 바로 동작한다면 상당히 근사할거라 봅니다. 구체적인걸 생각하느라 멍때릴 필요도 없고 혼란스러운 설정 화면을 쳐다보게 할 필요도 없습니다! 인생은 뽀대가 나야 하니까요 (읭?) 동적 호스트 설정 프로토콜(DHCP)과 왜 이걸 다루어야 하는지 설명하도록 하겠습니다.

DHCP는 정확하게 말하자면 이 이름이 함축하는 그대로입니다. 모든 호스트를 동적으로 자동으로 설정하게끔 하는 프로토콜입니다. DHCP 서버를 라우터에서 실행하면 네트워크의 모든 정보(유효 IP, DNS 서버, 게이트웨이, 등...)를 제공하고, 다른호스트가 시작하면 DHCP 클라이언트를 자체적으로 자동으로 설정하게끔합니다. 난리날 일도 없고, 혼란스러워질 일도 없습니다! DHCP에 대한 더 많은 이야기를 알아보시려 한다면 언제든 Wikipedia를 찾아보실 수 있습니다.

DHCP와 DNS 서비스를 제공하는 dnsmasq 패키지를 활용하겠습니다. 이제 DHCP의 양상에 집중하겠습니다. 다른 DHCP 서버를 실행하시려 한다면 재미 거리 장에서 다른 예제를 찾아보시면 됩니다. 또한 DHCP 서버 설정에 손을 대보려 한다면 의 주석만을 읽어보세요. 모든 기본 설정은 있는 그대로 동작합니다.

Now your little router is a bona-fide DHCP server! Plugin those computers and watch them work! With Windows systems you should go into the TCP/IP Properties and select the 'Obtain an IP address automatically' and 'Obtain DNS server address automatically' options. Sometimes the changes aren't instantaneous, so you may have to open a command prompt and run  and. But enough about Windows, let's get back to our favorite penguin.

DNS Server
When people want to visit a place on the internet, they remember names, not a string of funky numbers. After all, what's easier to remember, ebay.com or 66.135.192.87? This is where the DNS steps in. DNS servers run all over the internet, and whenever someone wants to visit 'ebay.com', these servers turn 'ebay.com' (what we understand) into '66.135.192.87' (what our computers understand). For more information about DNS, you can always visit Wikipedia.

Since we're using dnsmasq for our DHCP server, and it includes a DNS server, you've got nothing left to do here! Your little router is already providing DNS to its DHCP clients. Bet you wish everything was this easy ;).

You're welcome to choose other DNS servers if you're more comfortable with them, but the reason dnsmasq is great is because it was designed to do exactly what we want and nothing more. It's a little DNS caching/forwarding server for local networks. We're not looking to provide DNS for our own domain here, just offer simple DNS services to everyone else on our LAN.

NAT (a.k.a. IP-masquerading)
At this point, people on your network can talk to each other and they can look up hostnames via DNS, but they still can't actually connect to the internet. While you may think that's great (more bandwidth for you!), I bet they're not too happy just yet.

This is where Network Address Translation (NAT) steps in. NAT is a way of connecting multiple computers in a private LAN to the internet when you have a smaller number of public IP addresses available to you. Typically you are given 1 IP by your ISP, but you want to let your whole house connect to the internet. NAT is the magic that makes this possible. For more information about NAT, you can always visit Wikipedia.

First we flush our current rules

Setup default policies to handle unmatched traffic

Copy and paste these examples ...

Then we lock our services so they only work from the LAN:

(Optional) Allow access to our ssh server from the WAN:

Drop TCP / UDP packets to privileged ports:

Finally we add the rules for NAT:

Tell the kernel that ip forwarding is OK:

This is so when we boot we don't have to run the rules by hand.

If you have a dynamic internet address you probably want to enable this:

Once you've typed out all of that, the rest of your network should now be able to use the internet as if they were directly connected themselves.

The ip_dynaddr option is useful for dial on demand systems or when your ISP gives out dynamic addresses. This works around the problem where a connection is attempted before the internet interface is fully setup. Really this just provides for a smoother network experience for users behind your router.

Intro
Believe it or not, you're done :). From here on out, I'll cover a bunch of common topics that may interest you. Everything in this chapter is completely optional.

Port Forwarding
Sometimes you would like to be able to host services on a computer behind the router, or just to make your life easier when connecting remotely. Perhaps you want to run a FTP, HTTP, SSH, or VNC server on one or more machines behind your router and be able to connect to them all. The only caveat is that you can only have one service/machine combo per port. For example, there is no practical way to setup three FTP servers behind your router and then try to connect to them all through port 21; only one can be on port 21 while the others would have to be on say port 123 and port 567.

All the port forwarding rules are of the form. Unfortunately, iptables does not accept hostnames when port forwarding. If you are forwarding an external port to the same port on the internal machine, you can omit the destination port. See the iptables(8) man page for more information.

Forward port 2 to ssh on an internal host:

FTP forwarding to an internal host:

HTTP forwarding to an internal host:

VNC forwarding for internal hosts:

If you want to VNC in to 192.168.0.3, then just add ':1' to the router's hostname.

SAMBA forwarding to an internal host (excess ports to cover Windows):

Bittorrent forwarding:

eDonkey/eMule forwarding:

Game Cube Warp Pipe support:

Playstation 2 Online support:

Xbox Live:

Identd (for IRC)
Internet Relay Chat utilizes the ident service pretty heavily. Now that the IRC clients are behind the router, we need a way to host ident for both the router and the clients. One such server has been created called.

There are a few other ident servers in portage. Depending on your needs, I would recommend checking out  and.

Time Server
Keeping your system time correct is essential in maintaining a healthy system. One of the most common ways of accomplishing this is with the Network Time Protocol (NTP) and the ntp package (which provides implementations for both server and client).

Many people run ntp clients on their computers. Obviously, the more clients in the world, the larger the load the ntp servers need to shoulder. In environments like home networks though, we can help keep the load down on public servers while still providing the proper time to all our computers. As an added bonus, our private updates will be a lot faster for the clients too! All we have to do is run a ntp server on our router that synchronizes itself with the public internet servers while providing the time to the rest of the computers in the network. To get started, simply  on the router and edit  to your liking.

These will allow only ntp clients with an IP address in the 192.168.0.xxx range to use your ntp server.

Now, on your clients, have them  also. However, we will just run the ntp client so setup is a lot simpler.

In, change the 'pool.ntp.org' server in the NTPCLIENT_OPTS variable to '192.168.0.1'.

Rsync Server
For those who run multiple Gentoo boxes on the same lan, you often want to keep from having every machine running  with remote servers. By setting up a local rsync, you save on both your bandwidth and the Gentoo rsync servers' bandwidth. It's pretty simple to do.

Since every Gentoo machine requires rsync, theres no need to emerge it. Edit the default config file, uncomment the   section, and make sure you add an   option. All the other defaults should be fine.

Then you need to start the service (again, the defaults are OK).

Only thing left is to set tell your clients to sync against the router.

Mail Server
Sometimes it's nice to run your own Simple Mail Transfer Protocol (SMTP) server on the router. You may have your own reason for wanting to do so, but I run it so that the users see mail as being sent instantly and the work of retrying/routing is left up to the mail server. Some ISPs also don't allow for mail relaying for accounts that aren't part of their network (like Verizon). Also, you can easily throttle the delivery of mail so that large attachments won't seriously lag your connection for half an hour.

Make sure the output of `hostname` is correct

Edit and add an entry like so to the allow section:

I'm a huge fan of qmail, but you're free to use a different mta :). When you setup e-mail on the hosts in your network, tell them that their SMTP server is 192.168.0.1 and everything should be peachy. You might want to visit the netqmail homepage for more documentation.

Full DHCP Server
Earlier we used dnsmasq to provide DHCP service to all our clients. For most people with a simple small LAN, this is perfect. But you may need something with more features. Thus we turn to a full-featured DHCP server as provided by the ISC folks.

In set   to "eth0".

This is the minimal setup required to replace the dnsmasq DHCP functionality that we used earlier. Speaking of which, you did remember to disable the DHCP features in dnsmasq didn't you? If not, you should do so now (just comment out the  setting in  and restart the service).

Connect Another LAN (or two or three or ...)
Sometimes you have need of connecting the router to another LAN. Maybe you want to hook up a group of friends temporarily, or you're a neat freak and want to section off different groups of computers, or you're just really really bored. Whatever the reasons, extending the router to other LAN networks should be pretty straightforward. In the following examples, I will assume that this new network is connected via a third ethernet card, namely.

First you need to configure the interface. Just take the instructions in this section and replace  with   and   with.

Then you need to tweak dnsmasq to service the new interface. Just edit the file again and append   to DNSMASQ_OPTS; using -i multiple times is OK. Then edit and add another line like the dhcp-range line in this section, replacing   with. Having multiple dhcp-range lines is OK too.

Finally, see the rules in this section and duplicate the rules that have  in them. You may want to create another variable, say, to make things easier.

Useful Tools
If you're having trouble getting your computers to communicate, you may way to try out the following tools (they can all be found in the  portage category):

DHCP Fails To Start
When starting the dhcp init.d script for the first time, it may fail to load but neglect to give you any useful info.

The trick is to know where dhcpd is sending its output. Simply browse to and read the log files. Since the exact log file depends on the package you are using as a syslog, try running  to narrow down the possibilities. Chances are you made a typo in your config file. You could also try running  (short for debug / foreground) and debug the error based upon the output.

Incorrect MTU Value
If you experience odd errors (such as not being able to access some webpages while others load fine), you may be having Path MTU Discovery trouble. The quick way to test is to run this iptables command:

This will affect all new connections, so just refresh the website you're having problems with in order to test. In case it helps, the standard MTU value for 100mbit ethernet connections is ; this value also applies to PPPoA. For PPPoE connections it is. For more info, you should read Chapter 15 of the Linux Advanced Routing & Traffic Control HOWTO.

If that command does not work for you, you may want to try putting the rule into the mangle table. Simply add  to the command.

Unable to connect two machines directly
If (for whatever reason) you want to connect two machines directly together without a hub or switch, a regular ethernet cable will likely not work, unless you have an Auto MDI/MDI-X (also known as "autosensing") capable network adapter. You will need a different cable called a crossover cable. This Wikipedia page explains the low level details.

Final Notes
I have no final notes other than if you experience any troubles with the guide, please contact or file a bug with Gentoo's Bugtracking Website. If you have some interesting bits you think would enhance this guide, by all means send it my way for inclusion.

Acknowledgements
We would like to thank the following authors and editors for their contributions to this guide: