Debian on the Seagate Dockstar Post-Installation

From David Darts Wiki

Revision as of 21:01, 13 January 2012 by WikiSysop (Talk | contribs)
Jump to: navigation, search

Updated: 12-18-2011 Now that you've installed Debian on the Seagate Dockstar, there are lots of useful things you can do with your system including running a media server, a web server, a VPN server, a NAS, a torrent client, a print server, etc. Here are a few tips to get you started...

Contents

Setting up a Static IP

For administrative purposes, it makes a lot of sense to assign a static IP address to your Debian Dockstar on your local network.

First make a backup of your current network setup with the following command:

cp /etc/network/interfaces /etc/network/interfaces.bak

Next, open your networking interfaces file with:

nano /etc/network/interfaces

And replace the current content with this (modify your static IP address and gateway IP as required):

# The loopback interface
auto lo
iface lo inet loopback

# The first network card - this entry was created during the Debian installation
# (network, broadcast and gateway are optional)
auto eth0

iface eth0 inet static
       #set your static IP below
       address 192.168.1.169  

       #set your default gateway IP here
       gateway 192.168.1.1

       netmask 255.255.255.0
       network 192.168.1.0
       broadcast 192.168.1.255

Finally, restart networking with the following command. Note: once you have issued this command, you will need to ssh into your server using your new static IP address. Note: you may also receive a warning about this command being deprecated - you can safely ignore it.

invoke-rc.d networking restart

OpenVPN

Note: Thanks to petergunn on Jeff Doozan's forums for the original tutorial.

Once you've set up a static IP for your server on your local network, you may want to install OpenVPN. This will allow you to create an encrypted connection to your Debian Dockstar from a computer on another network. This means you can remotely mount shares on your home network and route your web traffic through your home network's ISP's DNS servers. This is especially useful if you are using a public wifi network and would like to ensure that your web traffic is not sniffed or tracked. OpenVPN will thus act as a proxy server which will also allow you to bypass Internet filters if you happen to find yourself behind an aggressive firewall or network filter.

First you'll need to determine your public IP address so that you can locate your local network from the Internet. You can find more info about running OpenVPN on a server with a dynamic IP address here.

Assuming your local network has a dynamic IP address (most residential ISP plans only include a dynamic IP), you'll need to create a free account with a Dynamic DNS service company so that you bind a domain name to IP address so that you can consistently access your local network remotely.

I recommend DynDNS though there are lots of other options. As you set up your account, be sure to record your hostname, username, and password.

Next you'll need to set up a client that updates your DNS record periodically whenever the IP address of your local network changes. Some routers have clients built in. I use DD-WRT Linux firmware on my router which has Dynamic DNS support (visit the router's admin IP and navigate to Setup > DDNS). This means my router will update a dynamic DNS name every time a new DHCP lease is obtained from my ISP. Some consumer-grade routers offer this functionality as well.

If your router doesn't have this capability, don't despair. You can use ddclient instead.

apt-get install ddclient

At the end of the installation process, you will be asked some configuration questions, including your hostname, username, and password. You can also edit the config file directly:

nano /etc/ddclient.conf

You config file should look something like this:

# Configuration file for ddclient generated by debconf
#
# /etc/ddclient.conf

protocol=dyndns2
use=web, web=checkip.dyndns.com, web-skip='IP Address'
server=members.dyndns.org
login=Your_User_Name
password='Your_Password'
Your_Hostname.dyndns.org

To restart ddclient, use:

/etc/init.d/ddclient restart

Next you'll need to open port 1194 on your router and point it to your your Debian Dockstar server's local IP address. On my DD-WRT router, I navigated to NAT/QoS > Port Forwarding and forwarded port 1194 to my Dockstar's IP. You can find more info about port forwarding with DD-WRT here.

Now you're ready to install OpenVPN. First, ssh into your Debian Dockstar and navigate to the /tmp directory:

cd /tmp

Then download petergunn's modded OpenVPN installation script to your /tmp directory. More info about the script here and here. I've provided a copy of the script that you can download with the following command though you should check the forum thread to see if there's a newer version.

wget http://wiki.daviddarts.com/images/b/b8/Openvpn.sh

Now make the script executable with:

chmod +x Openvpn.sh

Now launch the script with:

./Openvpn.sh

Note: Near the beginning of the installation process, you'll be asked to enter some basic info for the certification keys. The system will then generate keys which will take a few minutes. You'll also be asked to answer a few questions near the end of the installation process.

After the keys have been generated, you should copy the directory to your client machine. You can find them in your /tmp directory.

scp keys.tgz username@IP_Address_of_Your_Client_Computer:~/Desktop

Right click on the keys file and extract.

NOTE: I've found that occasionally (and inexplicably) the script produces a key file (client1.crt) that is 0 Bytes. If this happens, trash all the key files and run the script again on your Dockstar.

Next, assuming your client computer is running Ubuntu Linux, install network-manager-openvpn-gnome:

 sudo apt-get install network-manager-openvpn-gnome

Now, click on the Network Manager daemon at the top right of your screen and select: VPN Connections > Configure VPN > Add). Use the following settings and certificates.

Gateway: Your home IP Address/Domain (the URL you created with DynDNS)
Type: Certificate (TLS) 
User Certificate: client1.crt 
CA Certificate: ca.crt 
Private Key: client1.key 
Private Key Password: (leave blank) 
Advanced: (Click and check "Use LZO data compression")

Now, restart networking (or reboot):

sudo /etc/init.d/networking restart

To test your connection, you'll need to be on a different network than your server. Simply click on the Network Manager and select VPN Connections. Once you've established a connection, a small padlock icon will indicate you're connected to your VPN. All of your web traffic should now be securely passing through the OpenVPN connection on your Dockstar. You will now also be able to navigate around your local network via ssh, etc.

NOTE: If you are able to establish a VPN connection but your web traffic does not connect to the internet, you may need to delete everything and run the OpenVPN script again.

Rsync Offsite Backup

This howto obviously assumes that you have a second Linux box at an offsite (remote) location.

First install rysnc on both your local and offsite machines:

apt-get install rysnc

On your offsite (remote) machine, you'll need to set up an account with a Dynamic DNS service company, install ddclient, and open a port on your router that forwards to port 22 (I recommend opening port 2200 and forwarding it to port 22). See the OpenVPN instructions above for more info.

Now generate private and public keys on your local machine:

ssh-keygen -t rsa

Note: Do NOT enter a passphrase during the creation of these keys or otherwise you will be prompted to enter it each time you access your remote machine which will prohibit automated backup.

Copy the public key from the local machine to the remote machine using ssh-copy-id:

ssh-copy-id -i ~/.ssh/id_rsa.pub user@IP_of_Remote_Machine'

Note: ssh-copy-id copies the contents of the /root/.ssh/id_rsa.pub file to /root/.ssh/authorized_keys and sets the file permissions to 600 and the .ssh directory permissions to 700.

Next, try sshing from the local machine into the remote machine (if you did everything correctly you should NOT be prompted for a password):

ssh user@IP_of_Remote_Machine

Now create an rsync bash script and save it in /root/bin on your local machine:

nano /root/bin/backup.sh

Add the following (modify the directory paths to suit your needs):


#!/bin/bash
#
# Simple Backup Script
#
# This tells the script to grab the date from the system.
echo "Backup started... $(date)"
rsync -e "ssh -p 2200" -avz --progress --delete \
/path_to_directory/ user@IP_of_Remote_Machine:/path_to_backup_directory
echo "Backup finished at $(date)"
exit 0
# End of script

Now set the permissions of the backup script to 700:

chmod 700 backup.sh

Install cron:

apt-get install cron

In order to automate this process, create a cronjob:

crontab -e

Add the following (backup everyday at 4am and send the log with datestamp info to /bin/backup.log)

0 4 * * * /bin/backup.sh >> /bin/backup.log

Send Email from the Command Line

First install sendemail and the required libraries by opening a terminal and issuing the following command:

apt-get install sendEmail libnet-ssleay-perl libio-socket-ssl-perl

Now you're ready to send emails from the command line. Here's an example using Gmail's SMTP server:

sendEmail -f my.address@gmail.com -t someone@somedomain.com \
-u "Hello World -m “this is a test message” \
-s smtp.gmail.com \
-o tls=yes \
-xu usernameonly -xp mypasswd

Here's a second example using the SMTP server provided by an ISP (Time Warner):

sendEmail -f myaddress@isp.net \
-t myfriend@somedomain.com \
-s smtp-server.nyc.rr.com \
-u “Hello world again” \
-m “Hi , this is another test email.”

More info here.

MediaTomb UPnP MediaServer

MediaTomb is an open source (GPL) UPnP MediaServer with a nice web user interface. It allows you to stream your digital media through your home network and listen to/watch it on a variety of UPnP compatible devices.

First, install the required packages:

apt-get install mediatomb-common mediatomb-daemon

Then install the recommended and suggested packages:

apt-get install file speex javascript-common libsasl2-modules

Now open and edit the configuration file:

nano /etc/mediatomb/config.xml

Change the UI entry to:

<ui enabled="yes" show-tooltips="yes">

And change the Accounts entry to:

<accounts enabled="yes" session-timeout="30">

Change the default username (mediatomb) and password (mediatomb) if required:

<account user="mediatomb" password="mediatomb"/>

Save and close. Now restart MediaTomb with: /etc/init.d/mediatomb

You can now access the MediaTomb web interface and setup which directories you'd like to stream by directing your web browser to: "http://IP_of_Your_Dockstar:49152"

Transmission BitTorrent Client

Transmission is a lightweight and powerful BitTorrent client with a low memory footprint. It can be operated from the command line and also via a web browser or even your Android device (see Transdroid). To install Transmission on your Debian Dockstar, use the following command:

apt-get install transmission-daemon transmission transmission-cli transmission-common

Next, you'll need to configure Transmission by changing some of the variables in the settings.json file:

nano /etc/transmission-daemon/settings.json

First, disable the whitelist (set to false) so that you can access and control transmission from a browser on another computer:

“rpc-whitelist-enabled”: false,

Next, set the Blocklist to True:

“blocklist-enabled”: true,

Note: You can read more about blocklists on the Transmission wiki and see blocklist examples here.

Also, don't forget to set the download directories:

“download-dir”: “/mnt/some_drive/transmission/downloads”,
“incomplete-dir”: “/mnt/some_drive/transmission/incomplete”,

And the watch directory (to put new torrent files into):

“watch-dir”: “/mnt/some_drive/transmission/watch”,

After saving any changes, tell the daemon to reload its configuration file, which applies all the changes you have made. Note that according to Michael Descy, by default the daemon overwrites its configuration file on exit. Thus restarting the daemon, if it is already running, will result in it saving the configuration file, and overwriting any changes you have made to it. He suggests that:

Instead of restarting the service after editing the configuration file, you should reload the service. The following code sends a SIGHUP signal to transmission-daemon, which causes it to reload its configuration file. Importantly, it does not stop the the daemon, which would cause it to write over the configuration file.
service transmission-daemon reload

Now, re-open the settings.json file:

nano /etc/transmission-daemon/settings.json

And change your password and username (look for these lines):

“rpc-password”: “your_password”,
“rpc-username”: “your_username”,

Now reload the transmission-daemon to write the changes:

service transmission-daemon reload

Finally, restart the transmission-daemon in order to convert your password from plaintext to a SHA1 encrypted format.

service transmission-daemon restart

You can now access transmission via a web browser at: http://yourserverIP:9091

CUPS Print Server

CUPS is the standards-based, open source printing system developed by Apple Inc. for Mac OS X and other UNIX-like operating systems. Setting up your Debian Dockstar as a print server is pretty straightforward. You can learn more about CUPS on Debian here.

First plug your printer's USB cable into the Dockstar.

Then ssh into your Dockstar and install the CUPS packages with:

apt-get install cups cups-client

Once the packages are installed, you can add a printer to your print server by visiting http://localhost:631/ from your Dockstar. You will need a terminal-based browser like w3m or elinks in order to do this.

Install elinks:

apt-get install w3m

Now visit the CUPS configuration page and follow the on screen instructions:

elinks http://localhost:631/

Once you've saved your configuration, restart CUPS with:

/etc/init.d/cups restart

USB Audio

With the addition of an inexpensive USB sound card, the Dockstar will play audio. I'm using this $2 USB audio adapter from DealExtreme though I suspect most USB adapters will work.

MOC (Music On Console) Audio Player

There are a number of audio applications to choose from. I've been using MOC (music on console) which is a lightweight but full-featured console-based music player to play music on a pair of speakers in my studio.

To install:

apt-get install moc moc-ffmpeg-plugin

You'll also need a few Alsa packages:

apt-get install alsa-base alsaplayer alsaplayer-text alsa-utils

You'll also want to add the Alsa "softvol" feature and bump up the buffer sizes by creating the following /etc/asound.conf file:

nano /etc/asound.conf

And paste:

pcm.!default {
    type plug
    slave.pcm "softvol"
}
pcm.dmixer {
       type dmix
       ipc_key 1024
       slave {
           pcm "hw:0"
           period_time 0
           period_size 4096
           buffer_size 131072
           rate 48000
       }
       bindings {
           0 0
           1 1
       }
}
pcm.dsnooper {
       type dsnoop
       ipc_key 1024
       slave {
           pcm "hw:0"
           channels 2
           period_time 0
           period_size 4096
           buffer_size 131072
           rate 50000
       }
       bindings {
           0 0
           1 1
       }
}
pcm.softvol {
       type softvol
       slave { pcm "dmixer" }
       control {
           name "Master"
           card 0
       }
}
ctl.!default {
    type hw
    card 0
}
ctl.softvol {
    type hw
    card 0
}
ctl.dmixer {
    type hw
    card 0
}

To ensure that your USB audio adapter is loaded correctly after a reboot, you'll need to change the alsa-base config file.

nano /etc/modprobe.d/alsa-base.conf
Old: 
 
# Keep snd-usb-audio from beeing loaded as first soundcard
options snd-usb-audio index=-2

New: 

# Allow snd-usb-audio to be loaded as first soundcard
options snd-usb-audio index=0

Save and reboot.

To run moc, simply type:

mocp

MOC is fairly intuitive to use. You can quickly view the available commands and key mappings by pressing "h."

Note: to control the volume, press the "w" and then the "x" to toggle the mixer and master channels. You can then use the following keys to increase or decrease the volume:

<              Decrease volume by 1%
>              Increase volume by 1%
,              Decrease volume by 5%
.              Increase volume by 5%

MOC also provides an optional configuration file. If you'd like to make changes to your configuration, you'll need to copy the example configuration file to the ~/.moc directory.

First unzip the file:

gunzip /usr/share/doc/moc/examples/config.example.gz

Then copy it to your ~/.moc directory:

cp /usr/share/doc/moc/examples/config.example ~/.moc/config

If you'd like to alter the keymapping, you'll also need to copy the example keymap file to your ~.moc directory

cp /usr/share/doc/moc/examples/keymap.example ~/.moc/keymap

You'll also need to add your keymap file to the MOC config file:

nano ~/.moc/config

Mplayer

You can also install Mplayer to play and stream media files.

apt-get install madplay mplayer

Then use the following to test the audio...

mplayer -ao alsa -msgcolor -cache 64 http://www.tv-radio.com/station/fip_mp3/fip_mp3-128k.m3u

Streamripper

Streamripper is a stand-alone client or Winamp plugin that records Internet radio streams in the MP3 or Vorbis formats. Streamripper will allow you to stream (and record) internet radio across your LAN. See petergunn's post for more info.

apt-get install streamripper

Make a directory to save recording songs.

 mkdir -p /root/streamripper

Connect streamripper relay to radio station:

streamripper URL -r 8000 -d /root/streamripper/ -A

Run mplayer against the relay:

mplayer http://127.0.0.1:8000 # change 127.0.0.1 to dockstar IP if playing on another LAN computer

You can then connect other players on your LAN to the dockstar without wasting bandwidth.

Personal tools