Tuesday, October 21, 2008

More power!

Although T&TEC provides relatively cheap electricity (so cheap we can afford smelter plants apparently) compared to the rest of the world, it's always a good idea to conserve as much power as you can.

This lead me to do some investigations and install powertop. This was a painless process on Ubuntu (with the universe repo enabled)
sudo apt-get install powertop
Once installed you can see lots of processes that are sucking up power. When running they have commands that they suggest you run. I accumulated some and put it in a small shell script called lesspower.sh. I had to make the script executable via
chmod +x lesspower.sh
The script contents is below.
#!/bin/sh
hal-disable-polling --device /dev/cdrom
echo 1500 > /proc/sys/vm/dirty_writeback_centisecs
hciconfig hci0 down ; rmmod hci_usb
beagle-shutdown
killall hald-addon-storage
This helped a bit, disabling beagle, bluetooth and the polling for if there's a CD in the drive. Lowering the display brightness helps as well. I still found there was too much hard disk activity though and wanted to reduce that as well. Most of the time I'm researching or reading something on the 'net, so for low power it would be great if I could keep doing that as long as possible.

Then I had the idea of running Firefox entirely in RAM (I have 4 gigs). No hard disk activity (besides copying straight to RAM) meant lower power (and since this is a laptop, longer battery life). As an added bonus, the disk cache is in RAM so stuff loads really quickly. Also, it's also sorta privacy friendly as all the changes made (it is in RAM after all) are lost on reboot. No cookies to speak of.

Ok, next thing to do is figure out how to run Firefox in RAM.

Sunday, October 19, 2008

An obsessive compulsive guide to faster Internet access - Part 1 - DNS

When we hop on the Internet to visit that super cool website or chat with someone a million miles away, DNS is probably the last thing we're thinking about.

DNS is a service which translates a server name (like ttfloss.blogspot.com) into an IP address (like 72.14.221.191). No-one's going to remember the IP address (ok, I might, I meant no-one normal) so DNS is necessary for just about everything on the Internet to connect transparently.

As with many vital services, when it works, it works well and you don't even know it's there (or care really). When it dies, you're frustrated to your wits end.

I currently have blink broadband with TSTT (see, there was something Trini in this) and while the speed is ok, I have no clue what they're doing with their DNS servers. It's rather frustrating having a 2Mb line and waiting 5+ seconds to resolve a server name to an IP address. Before you call me impatient (which I am with machines, but that's besides the point), sites nowadays have re-directions, embedded iframes to sub-sites and whole sub-domains used for caching and load balancing. Basically about 4 to 5 lookups on popular sites just to figure out what servers to ask data for. Even worse if you're on dial up. I shudder to think about it.

At work, I'm not the network administrator. It's a more difficult kettle of fish as local server lookup is fine, but try to surf. Yowza.

How do I satisfy my need to speed by these DNS servers driving in the slow lane? pdnsd and OpenDns.

Caveat: This configuration may not allow you to resolve local network server names.

pdnsd is a neat caching DNS server easily installable from the Ubuntu repos (I think you need universe enabled to install it).

OpenDns is not, as the name implies, an Open Source DNS server or service (which is too bad), but a free DNS service (good) which uses lots and lots of caching to get you really fast replies to DNS requests. They work on ad revenue and by default you see them (the ads) when you mis-type a server name and it can't find the IP. It's worth it to me and I don't have any issue sending my DNS requests halfway around the world if they come back faster than the one on the same island.

Step 1 - Install pdnsd (Say that 5 times fast!)

pdnsd is in the repos so if you enter the following in a terminal
sudo apt-get install pdnsd
That should do the trick.

Step 2 - Configure pdnsd to use OpenDNS (kinda important)

There are a couple configuration things that need to be done. Open the config file by typing the following in a command line.
gksudo gedit /etc/pdnsd.conf
Comment out the section that says server with label resolvconf so it looks like below.

/*
server {
label="resolvconf";
}
*/

Now we need to add a server entry for OpenDNS. Put the following in the config file.

server {
label=OpenDNS;
ip=208.67.222.222;
ip=208.67.220.220;
timeout=30;
interval=30;
uptest=ping;
ping_timeout=50;
purge_cache=off;
}

That basically says to use the OpenDNS DNS servers to do lookups that are not in the cache to populate the cache.

Save the file and then start / restart pdnsd. From a terminal type
sudo /etc/init.d/pdnsd restart
It's now all nice and configured.

Step 3 - Start using the pdnsd server (about time!)

Many of us get dynamic IPs from a dhcp server. To use the pdnsd DNS instead of the one suggested by the DNS server, execute the following commands. (This is for Ubuntu based Linuxes).
gksudo gedit /etc/dhcp3/dhclient.conf
While editing the dhclient.conf add the following line and save the file.
prepend domain-name-servers 127.0.0.1;
You can restart the network (or reboot) for the changes to take effect.

Step 4 - I can't see anything on the local network! Fix it!

I haven't really figured this out. You can follow some OpenDNS steps. They didn't really work for me. I'm sure pdnsd can let me fix this, but I haven't figured it out as yet.

Right now I have a couple of entries in my /etc/hosts file for local servers I use at work and it's good enough for now.

Worst case scenario, remove the prepend line from the dhclient.conf and restart the network.

If I figure out how to fix this I'll post an update. In the meantime, enjoy (slightly) faster surfing. :).

Saturday, October 18, 2008

Blackberry 8310 Modem on Ubuntu with Bmobile / TSTT

I don't like cell phones. I won't go into why, but someone up there had a quirky sense of humor when I went from having no cell phone to a company-sponsored Blackberry 8310 (ah, the joys of IT support and administration).

Being rather disheartened at constant crashes of XP on my company's Dell M90, I decided to upgrade to Ubuntu (shhh, don't tell them). One of the things which my Internet addicted brain missed (and was a requirement in case a server blew up outside office hours) was the EDGE network Internet access provided by TSTT (re-branded into a greener looking bmobile).

While I had one of those wireless USB dongle modems (which I got to work with Ubuntu as well - I'll post about it sometime), now I don't. I recalled I should be able to use the blackberry as a modem to get Internet access (yay 'unlimited' data plan). Being stranded by myself waiting without any 'net was the impetus of my investigations. Enough rambling, time for the good stuff.

There are lots of tutorials out there, some focus on using the bluetooth as a connector and then the blackberry as a modem after that. I prefer the tethered approach, connect by USB cable thankyouverymuch. After lots of investigation, the easiest thing was to use barry.

Step 1 - Remove old barry (not necessary if it's never been installed)

Ubuntu has barry in its repos, but that's barry-0.12. I went for (at time of writing) latest release; barry-0.14. The two can't co-exist, so if you have barry installed from the repos, you need to remove it. You can do this using the synaptic package manager, searching for barry and removing:
  • libbarry
  • barry-util
  • barrybackup-gui

Step 2 - Install new barry (this you need to do)

The barry sourceforge site helpfully has debs for Ubuntu 8.04 (which is what I'm running) so we don't need to install from source (yay). Download all the barry files which have ubuntu 8.04 in their title (you don't need the dev deb) and it should be as easy as double clicking on the debs to install. You need to install in order:
  1. libbarry0_0.14-0_ubuntu804_i386.deb
  2. barry-util_0.14-0_ubuntu804_i386.deb
and optionally (recommended because it's an easy way to see if your blackberry's detected) barrybackup-gui_0.14-0_ubuntu804_i386.deb

Time for an obligatory pic. Once installed you should see something like the following picture if you search for barry in synaptic.


Notice it's all nice and 0.14 installed.

Step 3 - Install ppp

This thing is going to work like a modem with a dial up connection and everything, so you need to
sudo apt-get install ppp
That should install the ppp daemon and the pon and poff scripts.

Step 4 - Get barry to work for you

This step is Trinidad and Tobago specific. Actually it's bmobile specific because I don't have a Digicel blackberry to play with. :(.

Once barry is installed it creates chat scripts for well known carriers. You can find these in the /etc/chatscripts folder. The one most closely resembling what's needed for bmobile is the tmobileus script (ain't that co-incidental). Enter the following in a terminal.
sudo cp /etc/chatscripts/barry-tmobileus.chat /etc/chatscripts/barry-bmobile.chat
Once that's done, we edit the barry-bmobile.chat script. Enter the following in a terminal.
gksudo gedit /etc/chatscripts/barry-bmobile.chat
You're going to change the line
OK AT+CGDCONT=1,"IP","wap.voicestream.com"
to
OK AT+CGDCONT=1,"IP","internet"
And save the file. Everything else should be ok. My full chat file is quoted below:

ABORT BUSY ABORT 'NO CARRIER' ABORT VOICE ABORT 'NO DIALTONE' ABORT 'NO DIAL TONE' ABORT 'NO ANSWER' ABORT DELAYED ABORT ERROR
SAY "Initializing\n"
'' ATZ
OK AT+CGDCONT=1,"IP","internet"
OK-AT-OK ATDT*99#
CONNECT \d\c

The next step is to setup a peer file, so the pppd knows who to call and how to authenticate. These peer files are in the /etc/ppp/peers directory.

We create a file based off tmobileus again and call it bmobile. Enter the following in a terminal.
sudo cp /etc/ppp/peers/barry-tmobileus /etc/ppp/peers/barry-bmobile
Next we edit the barry-bmobile peer setting to use the bmobile chat script.
gksudo gedit /etc/ppp/peers/barry-bmobile
Change the line
connect "/usr/sbin/chat -f /etc/chatscripts/barry-tmobileus.chat"
to
connect "/usr/sbin/chat -f /etc/chatscripts/barry-bmobile.chat"
And save the file.

Once everything is all nice and detected you can enter the following in a terminal.
pon barry-bmobile
You should see fun looking output something like below
Initializing
Serial connection established.
using channel 3
Using interface ppp0
Connect: ppp0 <--> /dev/pts/3
sent [LCP ConfReq id=0x1 ]
rcvd [LCP ConfReq id=0x6 ]
sent [LCP ConfAck id=0x6 ]
rcvd [LCP ConfAck id=0x1 ]
sent [PAP AuthReq id=0x1 user="XXXXXXXX" password=]
rcvd [PAP AuthAck id=0x1]
PAP authentication succeeded
sent [IPCP ConfReq id=0x1 ]
rcvd [IPCP ConfReq id=0x7 ]
sent [IPCP ConfAck id=0x7 ]
rcvd [IPCP ConfRej id=0x1 ]
sent [IPCP ConfReq id=0x2 ]
rcvd [IPCP ConfNak id=0x2 ]
sent [IPCP ConfReq id=0x3 ]
rcvd [IPCP ConfAck id=0x3 ]
Cannot determine ethernet address for proxy ARP
local IP address 10.20.14.54
remote IP address 169.254.1.1
primary DNS address 196.3.132.1
Script /etc/ppp/ip-up started (pid 17392)
When you're done and want to hang up enter in another terminal:
poff barry-bmobile
Step 5 - Surf

Lastly, try it out! You should be surfing (maybe a bit slow, but surfing nonetheless).

Step 6 - Troubleshooting
  • If it doesn't work (arg!), see if the backup application detects your blackberry. You can run it by typing barrybackup at a terminal. If your blackberry is not detected, check your usb cable and / or settings.
  • Check on your blackberry that data services is on (You can check this in Options > Mobile Network)
  • Sometimes you might need to unplug the USB cable and plug it back in for the pon script to detect the blackberry
That's it. If anyone out there knows a better way to do all this, feel free to let me know. :). I hope this is of some use to someone.