Ubuntu 10.04 Lucid Print and File Server for the Home Network
Having officially moved to a new laptop, and having given away the desktop, I’ve been a little short on projects around here lately. I looked around at some media server options, thought about doing a media server build, but cant see spending the money on it, particularly when there’s nothing to connect the HTPC to the televisions without setting up some thin clients, of which I have all of none.
I did have my old HP ze4400 laying around collecting dust and cat- fur though. Now I know that Lucid is technically still beta, but screw it, this notebooks been BSOD’d and reformatted more times than I can remember, and my fingers are itchin.
A Cheap Home Print and File Server
For a long time now Ive wanted to set up some kind of Network Attached Storage (NAS) device, and Ive looked at some pretty neat options, but couldnt bring myself to spend the money on it when Ive got so many spare parts laying around the house waiting to be brought back from exile.
I’ve also wanted to set up a print server, because when youre mainly working on a laptop, and youre not the home-office type, youre probably hanging out with the laptop wherever’s comfortable, which is definitely not where the printer is. With the rapidly approaching release of the next Long Term Support (LTS) Release of Ubuntu Server Edition, now seemed like a good time to take a glimpse at the release-candidate.
Install the Server
The server installation process is incredibly simple, completing in about 20 minutes on my old hardware. I chose defaults for the network configuration (DHCP), then selected the software packages for print and file-server, and SSH for remote administration. Ubuntu uses Samba and CUPS to these ends. Having prior experience with these, thatll work just fine. Once installed, the system boots fine and after a little scouting with Nmap to get the DHCP-assigned IP of the server, I was able to sign in from my day-to-day notebook and start customization.
Configure Networking (Static IP) and Firewall
First thing to do in order for the server to be easily locatable on the home network, is to configure the network connection for a static IP. The two critical files involved are /etc/network/interfaces and /etc/resolv.conf. Before making any changes, as usual, be sure to make backup copies of the oriignal configuration files.
user@host:~$ sudo cp /etc/resolv.conf /etc/resolv.conf.original user@host:~$ sudo cp /etc/network/interfaces /etc/network/interfaces.original
For resolv.conf, the auto-generated one will work fine, or if youre a fan of openness, you may want to use OpenDNS servers. You should customize for your own circumstances, but heres an example resolve.conf:
nameserver 188.8.131.52 nameserver 184.108.40.206 domain hsd1.or.comcast.net. search hsd1.or.comcast.net.
Next is the interfaces config, for this one well need to know some details about the network environment, specifically the IP you want to set your server on, the netmask and the gateway (router) ip. On Linux, you can get this from a computer with an internet connection by entering ifconfig at the command line, or ipconfig on Windows. Example /etc/network/interfaces file below:
# The loopback network interface auto lo iface lo inet loopback # The primary network interface auto eth0 iface eth0 inet static address 192.168.1.105 netmask 255.255.255.0 gateway 192.168.1.1
Once you’ve set up the network files, make sure to restart networking:
sudo /etc/init.d/networking restart
To configure the firewall, we want to first think of the services we need to have network access to, and for whom those services are intended . For my setup, the services in action are SSH, Samba Server (Files), and CUPS server (Print). To set up these services, I chose to use the default firewall utility in Ubuntu, ufw (uncomplicated firewall). Since this is for a home network, Ill be restricting access to clients inside the LAN. SSH is run on port 22 by default, so well punch a hole there and in port 631 for CUPS. For Samba, ufw has a built in configuration file for Samba that it can use to determine what ports Samba needs access to. Heres how I set up the firewall.
user@host:~$ sudo ufw allow proto tcp from 192.168.1.0/24 to any port 22 user@host:~$ sudo ufw allow proto tcp from 192.168.1.0/24 to any port 631 user@host:~$ sudo ufw allow from 192.168.1.0/24 to any app Samba user@host:~$ sudo ufw enable; sudo ufw default deny
Alright, so thats network and firewall. Now lets look at the configuration of Samba and CUPS.
For Samba, the relevant configuration file is /etc/samba/smb.conf. While the default configuration file is fairly big and contains a lot of extra configuration options, I chose to copy smb.conf to smb.conf.origi nal, and set up a new smb.conf file from scratch, as I have pretty simpl e needs; I only need to share files and disk space on the local network.
Since I’m only allowing access to internal clients, I am choosing not to require user-names and passwords, and to allow guest access so that I dont need to add any extra users.
[global] workgroup = VALHALLA netbios name = YGGDRASIL #optional print sharing through Samba #[printers] #browsable = yes #guest ok = yes [landrive] path = /home/nathan/share guest ok = yes comment = Home Network Storage available = yes public = yes writable = yes browsable = yes create mask = 0666
After setting up smb.conf, be sure to restart Samba;
/etc/init.d/smbd restart. And of course you’d want to customize path for your own share. At this point you can test from any other comp uter on the network and you should be able to read and write files to the shared content. Also be sure to customize the create mask to your desired circumstances. I chose to give everyone read/write permissions, but 0644 might be a better idea depending on your circumstances. I recom mend NOT making scripts executable by default, though I hope you can trust the people in your home…
CUPS stands for the Common Unix Printing System, and is one area where Linux really stands out over Windows. Providing top-notch driver support and a slick and intuitive web-based administration, CUPS is really a joy to work with. Here’s an example configuration file:
ServerAdmin nathan@localhost # Allow remote access Port 631 Listen /var/run/cups/cups.sock DefaultEncryption Never # Allow shared printing and remote administration... Order allow,deny Allow from @LOCAL # Allow remote administration Order allow,deny Allow from @LOCAL # Allow remote access to the configuration files Order allow,deny Allow from @LOCAL # Share local printers on the local network Browsing On BrowseOrder allow,deny BrowseAddress @LOCAL BrowseAllow from @LOCAL DefaultAuthType Basic
This configuration file will give share, browsing and administrative priviliges to local network clients. Remember to restart CUPS; sudo /etc/init.d/cups restart. Now that youve configured cups to allow remote administration, you can add the printer through the web-based interface , by visiting the web-administration console. The address will be similar to: http://ip.of.your.server:631/. For more information on CUPS, visit their website at http://www.cups.org/.
Expanding Storage Capacity with USB-HDD
Great, so now the server set-up is done, tested and confirmed file- sharing access and remote printing. spiff! But… this crappy old laptop only has a 30GB harddrive, whereas both of the new ones have 250GB hard -drives, so unless we improve the storage somehow, this file-servers not going to be worth very much. Fortunately I also managed to dig out my 1 TB drive and external enclosure. While this isnt the slickest solution, its cheap, and readily available, so wtf, Im goin for it.
First the bad news. If your external storage device isnt already formatted, do it from a Windows machine or from command line, because both GParted and Palimpsest lay it out as GPT, which for some god- forsaken reason isnt supported without a kernel change in Ubuntu Server.
If you havent formatted a harddrive from the command line before, there are TONS of great tutorials online for basic linux sys-admin tasks, and a good one for this particular topic on ehow.com.
Don’t worry about choosing Windows compatibile file-system either, since were going through a Samba share, Windows wont have to support it.
After hooking up the hard drive, one of the first things I noticed was that Ubuntu Server Edition doesnt automatically mount hotplugged drives. Makes sense for servers I suppose, the less they do automatically, the fewer surprises one may encounter. So… mkdir a folder inside your already-configured Samba share (or if you want, somewhere new), then set up the entry for the drive in /etc/fstab. Since the drive IS hotpluggable, I recommend setting it up to identify the drive by UUID.
To get the UUID, you can find the drive by:
ls /dev/sdX, then run
tune2fs /dev/sdX where X is the USB-HDD drive. Once you have the UUID, you can set up an entry for the drive in /etc/fstab. In my case I choose to mount the drive inside the existing share for simplicitys sake.
My fstab looks like this:
UUID=63f5c4e1-3077-481c-bfb2-321a787fdc6f /home/nathan/share/backup ext4 defaults 0 0
To have the server automount the drive when detected, you can install usbmount:
sudo apt-get install usbmount. Now it is set up to automount your extended storage capacity to a predetermined location every time it detects the drive.
An issue is raised in using an external HDD for storage capacity though, and the issue is that external harddrives really arent meant to be left on all the time. Theres a really great script available over at shadypixel that will shut the hard drive entirely down, save it to the server and make it executable.
To have it run every time the server powers off, just move the script to /etc/init.d/ and link to it from /etc/rc0.d/.