Archive

Archive for July, 2009

Flush Buffers And cache On Linux

July 31st, 2009

Many users tend to worry when the free memory on a Linux system is very low. Especially when the system is barely active. What many don’t know is that this is normal behavior for Linux. It simply takes your free memory and caches it. This caching behavior makes subsequent memory allocations much faster. So it improves performance overall.

However, if you really really need to flush the cache and buffers, you can run the following two commands on the shell as root:

sync; echo 3 > /proc/sys/vm/drop_caches

Here’s the output of free before and after running the above command.

Before

# free -m
             total       used       free     shared    buffers     cached
Mem:           502        487         15          0         15        170
-/+ buffers/cache:        301        201
Swap:         3153        375       2777

After

# free -m
             total       used       free     shared    buffers     cached
Mem:           502        345        157          0          1         44
-/+ buffers/cache:        300        202

As you can see the highlighted numbers, the buffers and cached values have dropped significantly after I ran the command. Again, this is not necessary. In fact, it’s not recommended at all but there it is if you’re curious to know.

That’s all folks. I hope you enjoyed this one.

UNIXy Uncategorized , , , , , ,

Dig initial domain registration or migration cookbook

July 25th, 2009

Dig, not to confuse with the social network Digg, is a tool that allows one to trouble shoot or view domain name DNS data. Dig is in the category of essential tools. Just like a voltage tester is an essential tool for an electrician, dig the most important tool for domain administrator. Dig tells the truth like nothing else.

Let us start with the basics first. A domain, to be accessible via a web browser, has to be associated with a name server that is tasked with responding to requests on its behalf and deliver the IP address associated with the domain in question. So every time someone decides to browse your Website, the browser has to go through a chain of requests and events to obtain the IP and then make a connection to the IP. The chain of events and requests are defined in protocols, standards, and best practices.

The good news is Dig can emulate the same browser actions and events without us having to understand the details behind them. One, however, needs to know how to interpret the results. The rest of this blog entry will be a list of essential Dig commands that will help trouble shoot a domain name. The following commands are done against the root domain name’s A record, although it could be against any valid DNS record like MX, SOA, TXT, etc.

First of all, if you are on a Windows computer, you will need to download Dig for Windows. Download it from here http://members.shaw.ca/nicholas.fong/dig/. You can install Dig on Linux directly from the repositories. Let’s get started!

Obtain the IP of a domain from your ISP’s cache

When running this command via your computer, you are essentially tapping into your ISP’s DNS server, which most often than not caches results to speed up lookups, improve performance, and save on bandwidth fees.

dig +nocmd vpslux.com A +short +norecurse

If the above command doesn’t return an IP address, chances are the domain’s IP is not in the cache. This could be because no one using your ISP has ever visited the domain or that the cache was flushed after the record expired.

Find out how much longer your ISP is going to cache your domain’s IP

dig +nocmd vpslux.com A +norecurse

;; ANSWER SECTION:
vpslux.com. 12884 IN A 74.52.123.139

That would be 12884 seconds until the ISP’s cache refreshes the data or removes the domain name from the cache altogether.

Obtain the IP of a domain bypassing the ISP’s cache

dig vpslux.com A +trace +short

That’s all folks. We hope this was useful.

UNIXy Crash Course , , ,

Ban File Extensions Using Pure-ftpd

July 9th, 2009

Pure-ftpd has no direct support to prevent files with certain extensions from being uploaded. But it’s possible to accomplish this goal using a pure-ftp feature. pure-ftpd has a post-upload program that runs after each file is successfully uploaded and can run an external program. Here’s the excerpt from the pure-ftpd manual:

NAME
pure-uploadscript – Automatically run an external program after a successful upload

SYNTAX
pure-uploadscript [-p ] [-B] [-g ] [-h] -r [-u ]

So the program to run in our case can be a simple Bash script I’m going to call ban.sh

#!/bin/bash

uploaded_file=${1};
banned_extensions="zip tar rar";

for ext in ${banned_extensions};
do
count=$(echo ${uploaded_file}|grep -i ${ext}$|wc -l);
if [ "${count}" -gt "0" ];
then
rm -f ${uploaded_file}; # File with banned extension detected. Delete it.
break;
fi;
done

So you start the program in the background like this:

pure-uploadscript -p /var/run/pure-ftpd.pid -B -r /root/ban.sh

That’s all folks.

UNIXy Security , , , , , ,