matt-helps

insight on all things techie

Faster internet connection with a local DNS cache

One of the things you can do to speed up browsing and general internet activity is to create a local DNS cache. A DNS is a Domain Name Server and its purpose is to convert domain names to IP addresses. Every time you type in a domain name your computer has to ask a DNS to convert it to an IP address. Occasionally a website’s IP address will change so you can’t store an IP address forever, but it is worth cacheing it locally, even just for 24 hours or so considering the number of times we hit some sites during the day.

In Ubuntu (and debian, and other flavours of linux, though this tutorial is written for ubuntu) we can install a little helper application to cache the DNS results for a time and thus speed up our internet experience in general! It is called dnsmasq and the first step is to install it:

sudo apt-get install dnsmasq

Then at the terminal we need to edit the config file:

gksudo gedit /etc/dnsmasq.conf

Then find the line that says “#listen-address” and remove the leading # (if there is one) and make it say:

listen-address=127.0.0.1

Save and exit. Now edit /etc/dhcp3/dhclient.conf:

gksudo gedit /etc/dhcp3/dhclient.conf

Edit the line that says “prepend domain-name-servers” to say:

prepend domain-name-servers 127.0.0.1;

or if you want to use OpenDNS.org’s DNS servers (which I recommend) then change that line to:

prepend domain-name-servers 127.0.0.1, 208.67.222.222, 208.67.220.220;

Now at this point if you were to get a new IP lease it would all work, but that’s a bit of hassle so lets make it work now without rebooting the hardware. Edit /etc/resolv.conf:

gksudo gedit /etc/resolv.conf

Insert the following line at the top of the nameserver list:

nameserver 127.0.0.1

Finally we need to restart our little utility to take into account the new settings:

sudo /etc/init.d/dnsmasq restart

Now it is time to test it! At the terminal type:

dig news.bbc.co.uk

…and take note of the query time. Then run the same command again and note the improvement. You should be looking at around 2ms for the 2nd time whereas the first one will be dependant upon your internet connection - for me it was about 50ms - so for me this makes the DNS query portion of browsing about 25 times quicker. Enjoy.

Using Alien to convert .rpm packages to lpia .deb

Alien is a nice little linux utility that converts .rpm software packages to .deb packages so that you can install software packaged for Red Hat on Debian and Ubuntu, etc.  Clever.  But for those of us on the lpia architecture (like the dell mini 9) we require those .deb files that Alien spits out to have their “architecture” setting to be lpia, not the i386. There is no way to change it from the command line so you’re left with a .deb package that either won’t install or can be forced to install but then won’t uninstall.  You could of course unpack, edit the control file and then repack the .deb file, but there is an easier way.

Install alien if you haven’t already:

sudo apt-get install alien

Then ask alien to generate the build tree without actually building the package itself:

alien -g filename.rpm

This creates a build tree that is turned into an lpia .deb package once we’ve made a change to the control file as before.   Edit debian/control using your favourite text editor and modify the line that specifies the architecture so that it now says:

Architecture: lpia

And then in the directory that contains the folder “debian” run:

debian/rules binary

That will create a .deb file which you can then install either through the usual GUI methods or by calling:

dpkg -i filename.deb

And of course because you’ve installed it using the right architecture you’re also able to uninstall it should you need to.  Hooray.

Three million hit by Windows worm

A worm that spreads through low security networks, memory sticks, and PCs without the latest security updates is posing a growing threat to users.

The malicious program, known as Conficker, Downadup, or Kido was first discovered in October 2008.

Although Microsoft released a patch, it has gone on to infect 3.5m machines.

via BBC NEWS | Technology | Three million hit by Windows worm.

Yet again we see windows requires updates to patch up their software with a million holes in it.  These are the ones we know about too.  According to the article this seems to be a clever bit of code.  First it hijacks services.exe then creates & allows a randomly named .dll to become a service and then sets up a webserver & downloads files to execute from any one of hundreds of sites whose name changes continually according to a preset algorithm.

Quite clever actually.  I guess I find the whole thing quite bemusing.  You buy a nice fast machine and then have to buy a slow operating system with holes in it to run it which you then have to go out and buy antivirus software to do something that the operating system should be doing anyway which makes your computer run like a 3-legged dog.  The only reason to have a windows partition is games & specialist software - most software has linux equivalents and even some games run under wine.

Still, if you’re going to pay a huge multi-national corporation lots of money to still produce trash after all these years and you still pay and install it then I guess you get what you deserve.

Trash rather than rm

One of the most powerful/dangerous commands in linux is the “rm” command.  It removes the file from the filesystem and whilst with some media formats it is possible to recover an rm’d file in ext3 it is almost impossible to get that file back (without a hexdumper and lots of time on your hands to manually re-link the file).

After doing a bit of work the other day but before my nightly backup had run I went into the directory I had been coding in and decided to get rid of the backup files that had been created.  The backup files were like the normal files except they had a tilda attached, ie, filename.txt~, so to delete all the backup files in one go I quickly typed in:

rm *~

Except that’s not what I typed.  I missed the tilde off the end and wiped all the files from that directory.  Oops.  Nightly backup not yet run.  Major Oops.  After chuckling that I do make backups a priority and I tell people to make backups a priority I hadn’t done it myself.  Too late.

I did get the files back because, thankfully,  my data store is an SDHC card formatted to vfat (windows) so only the FAT entry had been deleted - more on that in my next post.

But that left me wondering.  I rarely need all the power of rm - whenever I’m using it from the commandline I could think of virtually no circumstances where I would prefer to unlink the file altogether rather than just move it to the trash.  As I looked around the net I noticed lots of suggestions from people to replace rm altogether or to create an alias for rm that does something else, but the problem with that is that lots of programs rely on rm being the way it is and taking specific arguments, etc.  To change it just for me would probably break the system or applications that I have installed or could install at any time.

The solution I settled on was to stop using rm from the commandline altogether and learn to use an alias I created called “trash” whenever I wanted to delete a file from the commandline.  All you need to do to use it is to open your ~/.bashrc file and put the following line in it somewhere (at the end works just fine):

alias trash="mv -t ~/.local/share/Trash/files --backup=t --verbose"

Obviously if your trash is in a different location you need to change the location above - what I’ve written above is correct for Ubuntu.  Now when you “trash” a file it will go into your trash bin and is therefore retreivable rather than being deleted forever.

Such a simple script doesn’t work perfectly of course and if you delete a huge file on a removable local device you’ll notice that it will move the file to the trash bin on another device and that will take some time.  What I could do with now is to know the name of the trash folder on the device on which the file is located and send it there.

Hard drive destruction ‘crucial’

The only way to stop fraudsters stealing information from old computer hard drives is by destroying them completely, a study has found.

Computing magazine Which? recovered 22,000 “deleted” files from eight computers purchased on eBay.

Criminals source old computers from internet auction sites or in rubbish tips, to find users’ valuable details.

via BBC NEWS | Technology | Hard drive destruction ‘crucial’.

Actually you don’t quite need to go to that extreme, and I’m sure a  very determined tech thief could piece together the digital media from the smashed hard-drive.  No, more secure (and easier!) is to just run one of the many shredding utilities you can download out there - preferably one where you can specify to overwrite the original data with a given number of garbage writes (I remember 23 being the number of times you should go over the original data - though that was some time ago), and then you can go ahead and sell your computer/hard-drive on ebay.

Perhaps the best solution though is just to have your home folder encrypted (or profile directory in windows) .   Or even setup an entire volume to be encrypted.  You never know when you’re going to leave your laptop on the train or when someone is going to steal it from under your nose at Starbucks.  You also never know when someone is going to break into your house and walk away with your desktop tower.  Sure your home insurance will cover the equipment, but it won’t cover the cost of re-securing your identity.