Posts Tagged ‘Linux’

Linux saves the day

Saturday, January 3rd, 2009

My gfs computer crashed on the 1st of January (probably a sign of what is to come in the new year). It died during shutdown, and something went horrible wrong. From this moment the computer would just hang as soon as Windows started loading. First thing we tried was booting up with the Windows XP cd to see if we could fix it that way. No luck, computer hung as soon as it started loading the cd. If we disabled the hdd with windows on it, the cd would boot just fine though. The drive with Windows XP on it, also had Ubuntu on it, which booted just fine, as did the Ubuntu live cd. So it wasn’t a hardware problem.

Mounting the drive in Ubuntu didn’t work at all. Only option I saw was clearing out the windows partition and reinstall. Though, here comes the real problem…Backups. As often happens, they are out of date when they are needed.

This is were TestDisk (windows/linux/osx) comes into the picture. It’s a tool to test and rebuild broken HDDs. It can even copy deleted files and repear broken partitions. The computer has a couple of big drives in it, which happen to have about 200GiB free space. This meant we could mount one of these, and copy all the needed files to them.

We downloaded Ubuntu rescue remix 8.10 and fired it up. It’s a command line distro, so make sure you know your way around the command line and especially how to mount and unmount drives.

After mounting the drive where we could copy the files, we fired up TestDisk and let it analyze the drive in question. It found all the partitions, so we selected the windows partition and pressed ‘P’ to view files. Everything is there! Awesome. Hit ‘C’ to copy the selected file/folder and navigate to the mounted hard drive.

All files copied over and Windows is back and working.

I had to use linux some time earlier to clean out a pretty nasty virus that went around on Windows (couple of reformats ago). Funny how you need linux to save a windows crash :)

Handy Linux network stat commands

Wednesday, December 24th, 2008

Netstat can be used to do a lot of things, I usually use it to keep track of how many connections there are to my server. These are my two most used commands

Show the number of connections on your http port

netstat -nta | grep :80 | wc -l

List the top10 ips using the highest number of connections to your server

netstat -atnp -A inet | awk -F " " '{print $5} ' | awk -F ":" '{print $1}' | sort | uniq -c | sort -nr | head -10

If there are some bad offenders in the list, you can ban their ip by using IP tables.

Ban:

sudo iptables -A INPUT -s <IPHERE> -j DROP

Unban:

sudo iptables -D INPUT -s <IPHERE> -j DROP

These are temporary bans, if you want to save them you will need to save the IP tables and restart the IP table service. This is for rhel, fedora and centOS.

sudo service iptables save
sudo service iptables restart