The Perfect SOHO router - Part 2
чети на
This is the second part of series of articles in which i will explain how to create the perfect SOHO router. I have to note that this is my idea of a perfect router with all the good and bad points stemming from it.
The series will comprise of the following articles:
- Basic hints, ideas, needed services and some thoughts - Here i will try to argument myself upon the choice of software and services for the router
- Base install - i will describe the way our system will be installed and minimized
- Configuration of DNS and DHCP services - here i will describe with arguments what i think is the best configs for the task
- Configure the routing - here is the heart of our router. I will suggest some tricks that make the life easier, also some pointers for more specific stuff
- Configuring very basic monitoring system
- Extending our router - i will describe some small things that make our life tad easier, smooth and not so demanding
In this part we will install our router, we will remove all that is unneeded and will install the software we need for the tasks at hand. The idea behind this is to minimize the disk usage and disk utilization. With this we will also minimize the installed software which will make the maintenance easier.
Hardware
For this project we are using the following
Compaq Deskpro series small factor machine
CPU: 333 mhz
RAM: 256 mb
HDD: 6,4 GB
LAN: 1 x Intel Ether Express (onboard), 1 x Davicom.
All in all this is one quite indecent machine by today’s standards, but it will suffice for our tasks. Due to the fact that the network card Davicom is not quite good or at the pace we will use it as an internal, because there it will handle less problems.
Install of the base system
This is prety straightforward process. Find your favourite CD with debian 3.1 and let’s get started. The first important point at hand is how to divide the harddisk space. I recommend the following layout:
/boot - 100 MB
/ - 2 GB
swap - 256 MB
/home - REST
This separation will give us some place for development.
Another important point is which NIC to be connected. As we stated above due to defficiencies on one of the nics it will be used as an internal, and the onboard one will be used for external. The basic principle is that the nic which we will use as an external should be connected during the install. It is not impossible to do the other thing around but it involves a bit of work afterwards.
Now we have to install the system itself. I recomend the testing branch, as it has newer versions of the software and is stable enough for our purposes. During the install do not pick any profile from the suggested ones, chose a good password for root, and skip creating additional user as we will be creating our own.
Minimization
As we have already installed the base system now we will have to minimize it. For this task we will use the package deborphan. It can be used to show which packages are not used in our install. With its help we will remove everything we don’t need. For the purpose we will execute the following command few times
apt-get remove --purge \
`deborphan -a --no-show-section --guess-all | \
grep -v "ssh\|deborphan\|bash\|apt\|nano\|kernel\|ssl"`The line is shown separated here for better readability
The idea of this line is to remove all packages that are unneeded skipping packages with ssh, deborphan or bash in it’s name.
It is needed this command to be executed multiple times as the software is not recursive. This step is not really necessary but helps.
Additionally we install the package localepurge With which help we will remove unneded locales. In it’s configuration pick the same languages as during the install.
Install our needed software
First let’s get the system to it’s latest state
apt-get update apt-get --purge dist-upgrade apt-get --purge dist-upgrade -f
Now we will remove all kernels and install one we like/need. For debian the kernel is located in a package called kernel-image, linux-image. Find all such packages and remove them
apt-get remove --purge [package list]
Now we will install kernel to our liking. We will use a stock one comming from the project debian as it is fast enough and gives us all we need.
apt-get install linux-image-2.6.18-4-686
The kernel is fast and versatile enough to cover our needs.
Due to the services chosen we will have to install a bit of software
apt-get install iptables iproute bind9 bind9-host dhcp lighttpd php4-cgi php4-cli phpsysinfo mrtg samba ntp ntpdate proftpd ncftp vim logwatch rkhunter denyhosts iptraf mtr-tiny snmp snmpd iputils-ping lsof openssh-server visudo
In the process of instalation additional software will be pulled to satisfy dependencies.
The last task at this stage is to add our management user with its own ssh key for increased security and grant him the right to execute commands trough sudo system.
adduser managementuser
cd ~managementuser/
mkdir .ssh
cat /root/managementuser-key.pub > .ssh/authorized_keys2
chown -R managementuser:managementuser .ssh
usermod -G sudo managementuser
visudoNote: the file /root/managementuser-key.pub is the public ssh key which we have generated previously and somehow copied onto our router. Keys are easily generated with ssh-keygen.
The visudo command edits the /etc/sudoers file. There we should add/uncomment the line
%sudo ALL=NOPASSWD: ALL
which allows everyone in the sudo group to execute all commands without password.
Conclusion
This is our base install. From now on it has to be configured. All other tasks we will execute trough ssh by first connecting with our user managementuser and then changing to root by sudo su -
The Series continues with The Perfect SOHO router - Part 3









Здрасти,
2007-06-12 at 12.06 amмного яко начинание, с каквото мога бих помогнал/допринесъл.
Понеже в първа част спомена, че всичко трябва да се премисли преди инсталацията поне аз лично смятам, че /var трябва да ти/ние е в отделен дял.
Вар при дебиан е малко хищен и труден за защита. Причините за това са следните:
1) там са периодичните листи и свалените пакети за обновление и логовете и т.н. което дефинира като минимално място около 1 Г … не е проблем нека да е така
2) в момента в който го отделя изпитвам страхотната нужда да му се сложат опции “noexec,nosuid” но ако ги сложим не можем да инсталираме дебиански пакети. Взимайте тези две забележки под внимание и със два скрипта в структурата на apt-get може да се реализира.
Ще го опиша малко по късно след като тествам как точно се държи
2007-06-12 at 9.35 am1. За малка мрежа - до 30-50 компютъра бих препоръчал, използването на dnsmasq вместо bind и dhcpd тъй като е:
1.1. много леко
1.2. поддържа едновременно dnscache, dhcp
1.3. много лесно се настройва - чете от /etc/hosts и /etc/ethers и всичко работи перфектно.
2. Вместо denyhosts може да се използва blocksshd - пърл скрипт, който е вързан към firewall-а
може да праща мейли с whois на атакуващия. За повече инфо: http://webreality.org/content/view/18/34/ - има някои нови неща, статията не е за последната версия.
3. lighttpd е доста добър избор, но ако ще се използват php скриптове и/или скриптове, които имат модул за apache е много по добре да се сложи apache, особенно за работа на машина на 300mhz с 256mb памет, не че няма да работи, просто е по бързо и заема много по малко памет от статично заредени cgi-ки, също така има open_basepath в php.ini което за 1 юзър машина е сравнително сигурно(има още някоя друга опция за сигурност - за справка: http://georgi.unixsol.org/texts/presentations/php-security.pdf ).
ами… май е това като коментари - дано да са градивни :) и успех!
относно други дистрота: най лесния и евтин вариянт, който би уредил един офис по-малко 100кв.м. и по-малко 20-30 служителя - Linksys WRTG54L с инсталиран openwrt whiterussian и ajax интерфейса - върши перфеткна работа, 5 портов суич, ако фирмата иска файлов сървър, има такива wireless рутъри с usb2, на които просто им се включва usb диск и всичко работи на 6 :), харчи малко ток :), не заема място.
2007-06-12 at 11.12 amОтносно dnsmasq - добра забележка, бях забравил за него. Ще го добавя като алтернатива.
Относно denyhosts и blocksshd - сега ще погледна да видя какви са възможностите и дали няма да е по удачен. Ако се оттърва от python … бих казал че ще е добре :)
За Lighttpd - все още не съм убеден. Приемаме ситуацията че spawn-ваме само 2 инстанции на php, всички ненужни модули на lighttpd са изключени и в скриптовете си почистваме достатъчно добре променливите, а да и не ползваме нищо странно/критично. В такъв случай остава само memory usage-a да сравним
lighttpd + php-cgi
apache + mod_php
Статистиката е взета от top на машини с 45 дни uptime
2007-06-12 at 3.13 pmБих казал че апача яде повече рам. Вярно предоставя доста повече възможности но не ги ползваме.
по-добре вградената ланка да е към вътрешната мрежа.
2007-06-14 at 11.43 amНали си чувал “Когато гръм удари как суи4овете светят…”
Да речем че мрежата е свястно сглобена. Т.е. изцяло под земята, оптика до всеки блок, switch-а е в много добре изолирана кутия, на завет, сухо и т.н. и понеже сме умни сме си сложили гръморазрядна защита. В такъв случай е по удачно по стабилната, разбирай тази която пражи по малко проблеми, да е от външната страна.
2007-06-14 at 12.18 pmПокажи ми тази квартална мрежа в София и с удоволствие ще си закажа лаптопа директно, но докато говорим за реалността а не за рая на сисадмините - вградената ланка навътре :)
2007-06-14 at 12.27 pmи ще дам още 5 лева пове4е и ще си взема Realtec вместо Davicom :)
megalan
е оптиката не е до всеки блок ами на 2 - 4, мрежата е зарита под земята, външните кабели са не повече от 10 - 20 м и са прикожани към стената. В студентски град техните мрежи са дори още по-добри.
/офф: да не се караме за глупости. Напълно ясно ми е какви са последствията от закачането на вградена ланка на кофти кабел.
2007-06-14 at 12.42 pmЗдрасти пак,
за lighttpd, май си прав :), можеби единствения недостатък е, че спаунва сиджиайки, но здраве да е, едва ли рутъра
ще има сайт с 10000 посещения на ден :)
За blocksshd-то - пърл с 4-5 модулчета, определено по малко и по добро от питона за нещо толкова просто!
2007-06-18 at 1.48 pm[...] Base install - i will describe the way our system will be installed and minimized [...]
2007-09-11 at 11.02 am