{"id":9,"date":"2011-03-12T08:43:00","date_gmt":"2011-03-12T16:43:00","guid":{"rendered":"http:\/\/samueldotj.com\/blog\/?p=9"},"modified":"2013-08-26T18:22:45","modified_gmt":"2013-08-27T01:22:45","slug":"wirless-router-network-storage-and-media-server-software-pieces","status":"publish","type":"post","link":"http:\/\/samueldotj.com\/blog\/wirless-router-network-storage-and-media-server-software-pieces\/","title":{"rendered":"DIY &#8211; Wirless Router and NAS: Software Pieces"},"content":{"rendered":"<p>This is the followup post of <a href=\"http:\/\/samueldotj.com\/blog\/?p=10\">DIY &#8211; RCN<\/a>. Here I document about the different software used to make my RCN.<\/p>\n<h2>Operating System<\/h2>\n<p><a href=\"http:\/\/samueldotj.com\/blog\/wp-content\/uploads\/2011\/03\/linux-ubuntu2.gif\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/samueldotj.com\/blog\/wp-content\/uploads\/2011\/03\/linux-ubuntu2.gif\" alt=\"linux-ubuntu\" width=\"48\" height=\"48\" class=\"alignright size-full wp-image-81\" \/><\/a> There are two open source choices <a href=\"http:\/\/www.freebsd.org\/\">BSD<\/a>(FreeBSD) or <a href=\"http:\/\/www.ubuntu.com\/\">Linux<\/a>(ubuntu). After few days of analysis I decided to go with Linux &#8211; because in my work I use FreeBSD. In either case I did not want to use <a href=\"http:\/\/freenas.org\/\">FreeNAS<\/a> or <a href=\"http:\/\/www.openfiler.com\/\">OpenFiler<\/a> or any other ready made distro. Since I am familiar with Ubuntu, I decided to use the <a href=\"http:\/\/www.ubuntu.com\/business\/server\/overview\">Ubuntu server<\/a> version.<\/p>\n<h3>File System<\/h3>\n<p>Wanted to use <a href=\"http:\/\/en.wikipedia.org\/wiki\/ZFS\">ZFS <\/a>on my main storage disk but it is not available on Linux yet, so decided to go with <a href=\"http:\/\/en.wikipedia.org\/wiki\/XFS\">XFS<\/a>.  EXT3\/4 on the boot disk because it is natively supported and no extra package needed. The boot media is 8GB flash disk.<\/p>\n<h2>Installation<\/h2>\n<p>Since there is no optical disk drive, installation should be through network or USB. Since most of the Linux distributions supports that I decided to use USB.<\/p>\n<ol>\n<li>Download <a href=\"http:\/\/www.ubuntu.com\/business\/get-ubuntu\/download\">Ubuntu 10.10 server<\/a><\/li>\n<li>Download <a href=\"http:\/\/www.pendrivelinux.com\/universal-usb-installer-easy-as-1-2-3\/\">Universal USB installer<\/a><\/li>\n<li>Create bootable install media using the installer<\/li>\n<li>Boot the system with boot media<\/li>\n<\/ol>\n<h3>Partitions<\/h3>\n<p>Although no data is going to be stored in the boot media, it would be good to have separate partitions to store the config files and home directory. Otherwise re-installation would wipe out all the data.<\/p>\n<p>I chose to create 5 partitions<br \/>\n[shell]<br \/>\n\/     &#8211; EXT4 &#8211; 2GB<br \/>\n\/usr  &#8211; EXT4 &#8211; 2GB<br \/>\n\/var  &#8211; EXT4 &#8211; 2GB<br \/>\n\/home &#8211; EXT4 &#8211; 1GB<br \/>\nswap  &#8211;      &#8211; 1GB<br \/>\n[\/shell]<\/p>\n<h2>Management<\/h2>\n<p>Since this device will run headless only way to communicate with the system is through network interface. Having SSH access is good but still having a web interface for common administration access is better. Few Linux applications are available for that my choice is <a href=\"http:\/\/www.webmin.com\/\">Webmin<\/a>.<br \/>\n[shell]<br \/>\nsudo vi \/etc\/apt\/sources.list<br \/>\nwget http:\/\/www.webmin.com\/jcameron-key.asc<br \/>\nsudo apt-key add jcameron-key.asc<br \/>\nsudo apt-get update<br \/>\nsudo apt-get install webmin<br \/>\n[\/shell]<br \/>\nAfter this the machine can be controlled from local network &#8211; https:\/\/hostname:10000\/<\/p>\n<h3>Shutdown<\/h3>\n<p>Shutting down the system should be easy. Since the storage is connected to the system it cant be power off directly. The file system data should be syncd first and using command line or web interface is not realistic. So programming the ATX power switch is the only way &#8211; acpid does that.<br \/>\n[shell]<br \/>\nsudo apt-get install acpid<br \/>\n[\/shell]<\/p>\n<h2>Storage<\/h2>\n<p>The goal was to create file based storage which is accessible from my home network. The <a href=\"http:\/\/en.wikipedia.org\/wiki\/Network-attached_storage\">NAS server<\/a> should be big enough for at least next 2 years(1TB). It should be fast enough to view videos from it without flickering(64MB ondisk buffer). It should have hardware fault tolerance(<a href=\"http:\/\/en.wikipedia.org\/wiki\/RAID\">RAID<\/a>).<\/p>\n<p>Although few of my desktop boards had RAID option in the BIOS menu, I never used it and never explored it. I thought RAID chipsets in a motherboard is equivalent to RAID controllers\/adapters. It was one of the decideding factor I favoured for Gigabyte(GA-D425TUD) motherboard with JMicron RAID chipset over Intel(D525MO) motherboard.<\/p>\n<p>After configuring RAID in the BIOS and starting Linux I realized it is not true raid. Because Linux recognized as fakeraid. In simple terms fakeraid is a firmware based RAID. That is all the work is still to be done in software yielding no performance benefit. Advantage of fakeraid is multiple OS which runs on same box can utiltize the same RAID. Since my setup wont have multiboot option, I dont want the fakeraid so decided to go with pure software RAID 0. Here is the steps to create software raid 0.<\/p>\n<ol>\n<li>Create software raid using multiple devices(md) interface.<\/li>\n<p>       [shell]mdadm &#8211;create &#8211;verbose \/dev\/md0 &#8211;level=1 &#8211;raid-devices=2 \/dev\/sda \/dev\/sdb[\/shell]<\/p>\n<li>The above command will take some time (around 6 hours) because it needs to sync the contents of both disks.<br \/>\n       While it is doing that the status can be checked by using the following command.<\/li>\n<p>       [shell]cat \/proc\/mdstat[\/shell]<\/p>\n<li>Then create a XFS file system on the md device<\/li>\n<p>       [shell]mkfs.xfs \/dev\/md0[\/shell]<\/p>\n<li>Store the configuration<\/li>\n<p>       [shell]<b>mdadm &#8211;detail &#8211;scan > \/etc\/mdadm\/mdadm.conf[\/shell]<\/p>\n<li>Create mount point and add the mount information in the \/etc\/fstab<\/li>\n<p>   [shell]<br \/>\n     mkdir \/mnt\/raid<br \/>\n     echo &#8220;\/dev\/md0        \/mnt\/raid       xfs     defaults            1       2&#8221; >> \/etc\/fstab<br \/>\n   [\/shell]\n<\/ol>\n<h3>Windows File Sharing<\/h3>\n<p>After this \/mnt\/raid can be made accessible to remote machines through either NFS or through Windows File Sharing.\u00a0For Windows File Sharing\u00a0<a href=\"http:\/\/www.samba.org\/\">samba <\/a>service needed to installed. The following command installs samba server.<br \/>\n[shell]sudo apt-get install samba[\/shell]<\/p>\n<p>After installing samba server it can be configured using webmin. Use webmin to configure samba \u201cServers\u201d->\u201dSamba File sharing\u201d. Add the storage mount point here.<\/p>\n<h2>Router<\/h2>\n<p>The routing functionality is very simple &#8211; handle all 3 interfaces with some limitations.<br \/>\n<a href=\"http:\/\/samueldotj.com\/blog\/wp-content\/uploads\/2011\/03\/RCN.png\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/samueldotj.com\/blog\/wp-content\/uploads\/2011\/03\/RCN-300x148.png\" alt=\"RCN\" width=\"300\" height=\"148\" class=\"alignright size-medium wp-image-85\" srcset=\"http:\/\/samueldotj.com\/blog\/wp-content\/uploads\/2011\/03\/RCN-300x148.png 300w, http:\/\/samueldotj.com\/blog\/wp-content\/uploads\/2011\/03\/RCN.png 427w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<ul>\n<li>First interface eth0 is a Gigabit ethernet interface which is directly connected to the a desktop computer.<\/li>\n<li>Second interface eth1 is a Fast ethernet interface which is directly connected to internet(connected to a ADSL modem).<\/li>\n<li>Third interface is 802.11n wireless network.<\/li>\n<\/ul>\n<h3>Network and IP<\/h3>\n<p>All interfaces are in different networks. All interface should get static IPv4 address while booting up. This router should provide dynamic IP to the other machines.<\/p>\n<p>Modify network interface and dhcp configurations<br \/>\n[codegroup]<br \/>\n[shell tab=&#8221;\/etc\/network\/interface&#8221;]<br \/>\n# This file describes the network interfaces available on your system<br \/>\n# and how to activate them. For more information, see interfaces(5).<\/p>\n<p># The loopback network interface<br \/>\nauto lo<br \/>\niface lo inet loopback<\/p>\n<p># The primary network interface<br \/>\nauto eth0<br \/>\niface eth0 inet static<br \/>\naddress 192.168.1.2<br \/>\nnetmask 255.255.255.0<br \/>\ngateway 192.168.100.2<br \/>\npost-up iptables-restore < \/etc\/iptables.up.rules\nup \/etc\/init.d\/dhcp3-server start\n\n#wireless network\nauto wlan0\niface wlan0 inet static\naddress 192.168.2.1\nnetmask 255.255.255.0\ngateway 192.168.100.2\nup \/etc\/init.d\/dhcp3-server start\n\n#wan interface\nauto eth1\niface eth1 inet static\naddress 192.168.100.2\nnetmask 255.255.255.0\ngateway 192.168.100.1\n[\/shell]\n\n[shell tab='\/etc\/dhcp3\/dhcpd.conf']\nsubnet 192.168.1.0 netmask 255.255.255.0 {\nrange 192.168.1.100 192.168.1.200;\noption domain-name-servers 208.67.222.222, 208.67.220.220;\noption routers 192.168.1.2;\noption broadcast-address 192.168.1.255;\ndefault-lease-time 600;\nmax-lease-time 7200;\n}\nsubnet 192.168.2.0 netmask 255.255.255.0 {\nrange 192.168.2.100 192.168.2.200;\noption domain-name-servers 208.67.222.222, 208.67.220.220;\noption routers 192.168.2.1;\noption broadcast-address 192.168.2.255;\ndefault-lease-time 600;\nmax-lease-time 7200;\n}\n[\/shell]\n[\/codegroup]\n\nFinally enable forwarding in Linux kernel by setting a system tunable.\n[shell]echo 1 > \/proc\/sys\/net\/ipv4\/ip_forward[\/shell]<\/p>\n<p>To set it during boot modify <b>\/etc\/sysctl.conf<\/b><\/p>\n<h3><a href=\"http:\/\/en.wikipedia.org\/wiki\/Network_address_translation\">NAT &#8211; Network Address Translation<\/a><\/h3>\n<p>NAT is required on eth1 to translate addresses on any outgoing packets and incoming packets. For the iptable rules should be set correctly, the following script does that.<br \/>\n[shell]<br \/>\nINTIF=&#8221;eth0&#8243;<br \/>\nEXTIF=&#8221;eth1&#8243;<\/p>\n<p>#set default polices and flush<br \/>\niptables -P INPUT ACCEPT<br \/>\niptables -F INPUT<br \/>\niptables -P OUTPUT ACCEPT<br \/>\niptables -F OUTPUT<br \/>\niptables -P FORWARD DROP<br \/>\niptables -F FORWARD<br \/>\n#setup NAT<br \/>\niptables -t nat -F<br \/>\niptables -t nat -A POSTROUTING -o $EXTIF -j MASQUERADE<\/p>\n<p>iptables -A FORWARD -i $EXTIF -o $INTIF -m state &#8211;state ESTABLISHED,RELATED -j ACCEPT<br \/>\niptables -A FORWARD -i $INTIF -o $EXTIF -j ACCEPT<\/p>\n<p>INTIF1=&#8221;wlan0&#8243;<br \/>\niptables -A FORWARD -i $EXTIF -o $INTIF1 -m state &#8211;state ESTABLISHED,RELATED -j ACCEPT<br \/>\niptables -A FORWARD -i $INTIF1 -o $EXTIF -j ACCEPT<\/p>\n<p>iptables -A FORWARD -i $INTIF -o $INTIF1 -j ACCEPT<br \/>\niptables -A FORWARD -i $INTIF1 -o $INTIF -j ACCEPT<\/p>\n<p>#unblock certain services<br \/>\n#webmin<br \/>\niptables -A INPUT -p tcp -m tcp &#8211;dport 10000 -j ACCEPT<br \/>\n[\/shell]<\/p>\n<h3>Wireless<\/h3>\n<p><a href=\"http:\/\/samueldotj.com\/blog\/wp-content\/uploads\/2011\/03\/wifi.jpg\"><img decoding=\"async\" src=\"http:\/\/samueldotj.com\/blog\/wp-content\/uploads\/2011\/03\/wifi.jpg\" alt=\"wifi\" width=\"125\" class=\"alignright size-medium wp-image-82\" \/><\/a>Now it is time to setup the wireless interface. Assuming the wireless are drivers are present in the kernel.<br \/>\nThe other tool required is <b>hostapd<\/b>. hostapd\u00a0implements IEEE 802.11 access point management.<br \/>\nhostapd configuration<br \/>\n[shell]<br \/>\ninterface=wlan0<br \/>\ndriver=nl80211<\/p>\n<p>ctrl_interface=\/var\/run\/hostapd<br \/>\nctrl_interface_group=0<\/p>\n<p>ssid=rcnap<br \/>\nhw_mode=g<br \/>\nchannel=11<\/p>\n<p>ieee80211n=1<br \/>\n#ht_capab=[HT40-][SHORT-GI-40]<\/p>\n<p>wpa_pairwise=TKIP CCMP<br \/>\nwpa=1<br \/>\n[\/shell]<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This is the followup post of DIY &#8211; RCN. Here I document about the different software used to make my RCN. Operating System There are two open source choices BSD(FreeBSD) or Linux(ubuntu). After few days of analysis I decided to go with Linux &#8211; because in my work I use FreeBSD. In either case I [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8,7],"tags":[],"class_list":["post-9","post","type-post","status-publish","format-standard","hentry","category-router-nas-linux","category-softwares"],"_links":{"self":[{"href":"http:\/\/samueldotj.com\/blog\/wp-json\/wp\/v2\/posts\/9","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/samueldotj.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/samueldotj.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/samueldotj.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/samueldotj.com\/blog\/wp-json\/wp\/v2\/comments?post=9"}],"version-history":[{"count":6,"href":"http:\/\/samueldotj.com\/blog\/wp-json\/wp\/v2\/posts\/9\/revisions"}],"predecessor-version":[{"id":129,"href":"http:\/\/samueldotj.com\/blog\/wp-json\/wp\/v2\/posts\/9\/revisions\/129"}],"wp:attachment":[{"href":"http:\/\/samueldotj.com\/blog\/wp-json\/wp\/v2\/media?parent=9"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/samueldotj.com\/blog\/wp-json\/wp\/v2\/categories?post=9"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/samueldotj.com\/blog\/wp-json\/wp\/v2\/tags?post=9"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}