Showing posts with label Networking. Show all posts
Showing posts with label Networking. Show all posts

Tuesday, February 23, 2010

Wireless just works better with WICD than Gnome Network Manager

As I mentioned in my post about getting Ubuntu to start your wireless connection before login, Gnome Network Manager has to be uninstalled so that Ubuntu will rely on your /etc/network/interfaces file to start up your wireless connection. This worked great for me and my Ubuntu laptop until I started having to take my laptop away from home and use other wireless networks. In order to connect to other wireless networks, I would have to set my /etc/network/interfaces file so that my wlan0 interface relied on dhcp instead of static settings. I would then have to re-initialize my networking settings and then use the command-line to scan for dhcp requests on my wireless interface. This was no good!

To remedy the situation, I discovered another graphical network manager called WICD. The version in the Ubuntu repositories was actually a bit buggy, so I went directly to the WICD launchpad website and downloaded the latest release (version 1.7.0). I've tested it out at home and away and I can now say that it works quite nicely. WICD allows Ubuntu to start up my wireless connection before the Login screen. It also allows me to connect to other wireless networks despite the settings in my /etc/network/interfaces file.



As you can see above, WICD puts an icon in your system tray with a green indicator bar that tells you how good your signal is. If you hover your mouse over the icon it tells you what network you're connected to, what percentage signal strength you have, and what your IP address is.



Above is the window that pops up when you left click on the WICD icon in the system tray. As you can see, the window contains information about all available wireless network SSIDs in your vicinity, how strong the signal is to those networks, and what type of encryption (if any) protects each network. You can click on the properties button for any network that you want to connect to if you have to put in a wireless encryption key. The screen that pops up follows



Once you're ready, you can click on the Connect button and you're on your way!

Setting Up WICD

As I mentioned above, I first installed WICD from the Ubuntu Repositories. I think this forced my computer to install all the appropriate dependencies so that the newer version could work. When you download the newer version, extract it to whatever directory you want. Then, open up your terminal, navigate to the directory with the WICD setup files that you just extracted, and type in sudo python setup.py install. Now, when you restart your computer, you should see WICD in your system tray ready to do your bidding.

Tuesday, February 9, 2010

Start your wireless connection before Ubuntu login

Recently I started asking myself how I could get Ubuntu to forge its wireless connection (with WEP encryption) to my router without having to log-in through the GUI. I noticed that the default way of logging in through the GUI and then having a wireless connection available was limiting for two reasons: (1) If I wanted to be able to connect to my openSSH server then I needed to be logged in, and (2) If there was something wrong with the GUI and I had to log-in through the command line then I wouldn't have internet access.

So I started looking around on the net. Most pages that I found showed messageboard threads suggesting modifications to the /etc/network/interfaces file. This is the file that is supposed to tell your Linux system what to do with your network interfaces at boot-up. I tried to modify it so that my wireless card would start-up with a static IP at boot-up, but no matter how I changed this file, nothing worked.

Finally, I decided to ask a question on ubuntuforums. I found out that Gnome Network Manager, the program in Ubuntu which manages all your wired and wireless network connections, works terribly with the settings in the /etc/network/interfaces file. In other words, if you want Ubuntu to start your wireless connection at bootup instead of after login, you have to get rid of Gnome Network Manager!

So, on the advice of chili555 from ubuntuforums, I got rid of Gnome Network Manager by typing in sudo apt-get remove --purge network-manager and modified my /etc/network/interfaces file to look like the following (SSID and WEP key changed for privacy):

auto lo
iface lo inet loopback

auto wlan0
iface wlan0 inet static
address 192.168.2.11
netmask 255.255.255.0
gateway 192.168.2.1
wireless-essid MYSSID
wireless-key 12345678912345678912345678

iface eth0 inet dhcp


Now, every time I start my computer, my wireless connection is available before login so that I can login to my openSSH server or go to the command-line without logging in to the GUI!

Monday, December 28, 2009

Your download activity in one file!

I started downloading a very big set of files today on bittorrent (using the simple and elegant Transmission Bittorrent Client that comes with Ubuntu).  As I was watching the download speed indicator fluctuate up and down, the data analyst in me started stirring.  I thought it would be neat if I could find a program that would output my download speed over time to a dataset that I could then analyze for trends, averages, highs and lows.

I inputted the term 'bandwidth' in Synaptic Package Manager to see what kinds of programs were available for this purpose.  I found some simple command line programs such as nload, bmon, and iftop.  All of them provide text-mode screens that help you monitor your bandwidth, but none of them allow you to output download speed over time to a plain text file.

After examining the man (manual) pages for each of these programs, I noticed a commonality: each of these programs sample bandwidth information from a file named dev in the /proc/net/ directory on my computer.  Curious for more info, I navigated to that directory and opened up the file.  Here's an example of what it looks like:



If you've spent any time messing around with your network connection settings in Ubuntu (or most other operating systems) then you'll recognize most of the row titles in the above image.  Now, my computer is only connected to the net through a wireless connection to my Router/ADSL Modem.  Therefore, I don't expect any significant data in rows other than the one titled wlan0.

Next is the neat step: Linux repeatedly updates the dev file with the total number of bytes and packets received since boot-up.  All you need to do to find out the download speed in bytes/second is:

  • Open the file
  • Copy the numeric value just to the right of wlan0, under the bytes column
  • Wait a second
  • Do the same thing with the next value
  • Subtract the two!

Of course nobody in their right minds would want to do this manually, but the implementation of the above algorithm is very simple in Python:

def get_bytes():
    dev = open('/proc/net/dev','rb').read()
    import re
    pat = re.compile('wlan0:\s*([0-9]+)\s*')
    return int(pat.search(dev).group(1))

def get_kbps():
    import time
    bytes1 = get_bytes()
    time.sleep(1)
    result = round(((get_bytes() - bytes1)/1000.0),1)
    return '%3.1f' % result

The first function above simply opens the dev file and returns the numeric value beside wlan0.  The second function uses the first function to get the bytes value two times and calculates Kilobytes/second (it's a smaller number than bytes/second).

I'm now using these functions to calculate Kilobytes/second every 3 seconds for a total of 4 hours to get my dataset!  If you'd like to use these functions just remember that if you're using a wired ethernet connection, change wlan0 to eth0 and you will be able get your data.

Saturday, December 26, 2009

Permissions, Samba Sharing an External NTFS drive, and fstab

For my first post on this blog I wrote about setting up samba shares for my printer and external hard drive.  When I wrote that entry, I thought I finally succeeded in sharing both devices.  I was disappointed to learn that my solution was temporary, and my external USB hard drive was still unable to be shared with my wife's Windows XP machine.

After hours and hours of pursuing the solution to this problem like Captain Ahab come to life, I started to realize that my problem wasn't anything to do with Samba itself, but the permissions that were automatically assigned to my external hard drive upon its mounting.  Every time I looked at the extended information given by the ls -l command in my /media directory, I saw the following:

drwx------ 1 inkhorn inkhorn 4096 2009-12-06 18:24 backup

In other words, my external hard drive was mounted so that I personally would have read, write and execute access to the drive, that I could mount and unmount it, but nobody else could access my drive in any way at all.

From googling my problem, I learned that if you modify the fstab (file system table) file in the /etc directory, you can change the permissions linux assigns to your hard drive when mounting it.  I found numerous message board postings with examples of how to set up an entry for your hard drive in the fstab file, but none of them helped for very long.  Finally I found a web page that described a program available to Ubuntu users called pysdm (Python Storage Device Manager) that provides a GUI allowing the user to set permissions for any attached storage devices.





As you can see above, it displays all connected partitions and provides an Assistant button that allows you to choose your mounting options intelligently.  In my case, without having a USB stick connected first, my external hard drive shows up as partition sdb1, or /dev/sdb1. 





When you click on the Assistant button, you're brought to the above Select options window.  Most of these options were already set as enabled when this window popped up.  I think the only option here that I changed was to enable Allow a user to mount and unmount the file system.





I then found an option I thought might be important in the Miscellaneous tab.  I enabled the option above labelled This file system requires network.  So, I pressed OK, then at the main window I pressed the Apply button.  There was one catch however: the line that it automatically entered into my /etc/fstab file linked the partition to the mounting point, not the device itself.  See the fstab entry below:

/dev/sdb1    /media/backup    ntfs    nls=iso8859-1,_netdev,umask=000,user,owner  0  0

In other words, what this entry in my fstab file says is that any time partition /dev/sdb1 comes online, mount it to /media/backup; even if /dev/sdb1 is my USB stick, and not my external hard drive!  You see what I mean?

This is where what's called the UUID comes in handy.  The UUID is an alphanumeric sequence that uniquely identifies each connected storage device independently of the partition assigned to that device.  After all, if I connect my USB stick and then my external hard drive, it's my USB stick that would show up as partition sdb1, while my
external hard drive would show up as partition sdc1.  In order to make sure that it's my external hard drive that gets mounted as /media/backup and not my USB stick, I had to replace /dev/sdb1 with the UUID.  To find out the UUID of a connected device, go to the terminal and type in sudo blkid.  Here's the output on my terminal:

inkhorn@inkhorn-laptop:/media$ sudo blkid
/dev/sda1: UUID="2fb4ca03-eca7-41f8-9767-bbfaf88a1890" TYPE="swap"
/dev/sda2: UUID="34B836C6B8368700" LABEL="S3A6134D002" TYPE="ntfs"
/dev/sda5: UUID="ece79ff2-c123-4a72-80a9-c187b2cfd785" TYPE="ext4"
/dev/sdb1: UUID="010C7CC23301CA6C" LABEL="backup" TYPE="ntfs"

So, I opened up the fstab file again and replaced /dev/sdb1 with UUID=010C7CC23301CA6C.  I then saved the fstab file, restarted, and VOILA!!!  My Samba share for my external hard drive is finally accessible from my Wife's Windows XP machine!




If you want to install pysdm on your Ubuntu system, type the following in your terminal:

sudo apt-get install pysdm

Then you can access it through the following menu items: System > Administration > Storage Device Manager.

Sunday, December 6, 2009

Setting up file sharing in Ubuntu Linux

I made a BIG switch from Windows Vista to Ubuntu Linux a while ago.  I have been able to figure out how to do nearly all of my computing tasks in Ubuntu that I need on a regular basis.  The one thing I had a lot of difficulty with for some reason was file sharing.

My linux machine is wirelessly networked with my wife's Windows XP desktop and my own Windows XP netbook.  I wanted to share my external backup hard drive over the network so that she could just copy-paste stuff right into the drive over the network.

For some reason I found that the simplest method just didn't work:
  • Right-click on the icon for my backup drive in Nautilus
  • Click on 'Sharing Options'
  • Click on 'Share this folder'
  • Click on 'Allow others to create and delete files in this folder'
It kept giving me error messages!  Argh!  I kept finding a bunch of how-to's telling me how to modify my samba configuration file.  That was promising but I kept messing stuff up:
  • My printer share stopped working
  • All my shares stopped working
  • I could only view shares from her computer
Finally I found an answer.  Today I looked up "easy samba configuration" on google and found this page that gives a simple samba configuration file that only needs a few tweaks to work.  First I modified the [global] section:

  • I put my computer name, "inkhorn-laptop", next to "netbios name = "
  • I put my workgroup name, "MSHOME", next to "workgroup = "
Then I modified the [network-share] section:
  • I changed [network-share] to read [backup-drive]
  • Put the path to my backup drive, "/media/backup" next to "path = "
  • I deleted the "force group" line, as that didn't seem to help
  • I put the username I set up for my wife next to "force user = "
 Just make sure to follow the directions in the page I linked to above to create a samba username and password for the person you want to access your share.

Finally file sharing and printer sharing are working at the same time :)

--------------- EDIT: Dec. 27, 2009----------------------

The above seems to work just fine for sharing folders on my main hard drive.  To share my external drive it turns out I needed to jump through some hoops to change its permissions so that other people can read, write and execute files on it.  See my latest blog post on the topic here.