Configure Static Routes In Debian or Red Hat Enterprise Linux

Posted on in Categories CentOS, Debian Linux, Linux, Networking, RedHat/Fedora Linux, Suse Linux, Ubuntu Linux last updated January 22, 2010

Static routes improves overall performance of your network (especially bandwidth saving). They are also useful in stub networks (i.e. there is only one link to the network). For example, each LAN (located at different offices) is connected to HQ IDC (Internet data center) using single T1/LL/Wan links.

For example under Red Hat/Fedora Linux you can add static router for eth0 network interface by editing /etc/sysconfig/network-scripts/route-eth0 file. Under Debian Linux add static route by editing /etc/network/interface file.

Executing Linux / UNIX commands from web page

Posted on in Categories Apache, CentOS, Debian Linux, Howto, Linux, RedHat/Fedora Linux, Shell scripting, Suse Linux, Tips, UNIX last updated November 15, 2007

A Web interfaces is almost used by routers and many other sophisticated programs such as webmin. However, why go for a web interface or execute commands from web page? For automation purpose, you need to use a web interfaces. Another advantage is you can access your web-based interface from any computer, running any operating system, anytime in the world :D

In this first part, you will see how to use simple bash (shell) script from web page. In order to execute commands or shell script from a webpage you need:

  1. CGI support with Apache / lighttpd web server.
  2. I’m assuming that you have a properly configured web server.

You need to store program in cgi-bin directory. If you are using Debian Linux default location for cgi-bin directory is /usr/lib/cgi-bin. Under Red Hat / Fedora it is /var/www/cgi-bin. Use text editor such as vi to create a first.cgi program:

$ cd /usr/lib/cgi-bin
$ vi first.cgi

first.cgi code listing:

echo "Content-type: text/html"
echo ""
echo "<html><head><title>Bash as CGI"
echo "</title></head><body>"

echo "<h1>Hello world</h1>"
echo "Today is $(date)"

echo "</body></html>"

Save and close the file. Setup execute permission on the script:

$ chmod +x first.cgi

Fire up your web browser and test the script, for example type url http://localhost/cgi-bin/first.cgi or http://your-ip/cgi-bin/first.cgi

You need to send headers, first three lines are almost same for all your script:

  • #!/bin/bash : First line tell Linux/UNIX how file first.cgi should be run. So it will use /bin/bash interpreter to execute your rest of program.
  • echo “Content-type: text/html” : Send html headers, you must include this line.
  • echo “” : Send a blank line, you must include this line.

Rest is html code. Take a close look at following echo command:

echo "Today is $(date)"

It use shell feature called command substitution. It allows the output of a command to replace the command name:


Your bash shell performs the expansion by executing command and replacing the command substitution. So date command get executed by replacing the its output.

Real life example

Here is simple script that collects system information. Create script in cgi-bin directory:

echo "Content-type: text/html"
echo ""
echo "<html><head><title>Bash as CGI"
echo "</title></head><body>"

echo "<h1>General system information for host $(hostname -s)</h1>"
echo ""

echo "<h1>Memory Info</h1>"
echo "<pre> $(free -m) </pre>"

echo "<h1>Disk Info:</h1>"
echo "<pre> $(df -h) </pre>"

echo "<h1>Logged in user</h1>"
echo "<pre> $(w) </pre>"

echo "<center>Information generated on $(date)</center>"
echo "</body></html>"

Save and close the file. Setup execute permission on script:

$ chmod +x script.cgi

Fire up web browser and test it (http://localhost/cgi-bin/script.cgi):

Next time you will see:

  • How to use and place form elements (from POSTs and GETs)
  • Cookies in your environment
  • Use of perl scripting
  • And finally use of special tools

How Do I Secure Grub Boot Loader?

Posted on in Categories Debian Linux, Howto, Linux, Linux desktop, RedHat/Fedora Linux, Security, Sys admin, Tips, Ubuntu Linux last updated October 27, 2009

You can set a password for the GRUB bootloader. This prevents users from entering single user mode or changing settings at boot time.

When your system is rebooted, grub presents the boot option menu. From this menu one can easily login into a single user mode without the password which might result into compromise system security.

For example, anyone can access the data or change the settings. However you can setup a password for grub with password option. This option forces grub to ask for a password before making any changes or entering into single user mode. You need to type p followed by password.

Linux > Command line BitTorrent client

Posted on in Categories Linux, RedHat/Fedora Linux, Shell scripting, Suse Linux, Tip of the day, Tips, Ubuntu Linux, UNIX last updated February 18, 2008

BitTorrent is the name of a peer-to-peer (P2P) file distribution protocol, and of a free software implementation of that protocol.

The BitTorrent client is a computer program developed by BitTorrent, Inc. used to download and upload files via the BitTorrent protocol. You can download python based command line BitTorrent client download for Linux/BSD/Mac OS X/UNIX link oses. This is quite useful, if you would like to download file remotely over SSH session. offers bittorrent client in .deb (Debian Linux) or rpm (RedHat/Fedora Core/CentOS Linux) file formats.

To use the bittorrent in command line one you need to use command bittorrent-console or bittorrent-curses (see below for examples).

Step # 1: Find Python version

Make sure you download file according to your python version. Type following command to find out python version:
$ python -V

Python 2.4.2

Step # 2: Download bittorrent client

Use wget to download bittorrent client

Download bittorrent client for Debian Linux:

$ wget

Download bittorrent clientFor Red Hat / Fedora Core / Cent OS Linux

$ wget

Step # 3: Linux Install BitTorrent client

First login as a root user (use su or sudo command). If you are using Debian Linux, use dpkg command install bittorrent client
# dpkg -i bittorrent_5.0.3_python2.4.deb
If you are using Red Hat / Fedora Core /Cent OS Linux, use rpm command install bittorrent client:
# rpm -ivh BitTorrent-5.0.3-1-Python2.4.noarch.rpm

Step # 4: Start using or downloading files

Use bittorrent client as follows:
$ /usr/bin/bittorrent-curses ''
$ bittorrent-curses ''
$ /usr/bin/bittorrent-curses '/path/to/file.torrent'
You can try out pure console based client bittorrent-console instead of curses based client:
$ bittorrent-console '/path/to/file.torrent'
$ /usr/bin/bittorrent-console ''

Tips about using and Troubleshooting BitTorrent client

(A) If you get [Errno 2] No such file or directory, you need to use wget or lynx command to download .torrent file to local hard drive first. For example
$ bittorrent-curses '[222].torrent'
First download download .torrent file using any one of the following method:
$ lynx '[222].torrent'
When prompted save .torrent file to a hard-disk. Another option is use wget to download .torrent file:
$ wget '[222].torrent'
Now start the downloading as follows:
$ bittorrent-curses 'some_file[222].torrent'

(B) If you get error ‘This seems to be an old Python version which does not support detecting the filesystem encoding. Assuming ‘ascii’, then upgrade your python version to 2.4.xx:

Debian user upgrade python version using apt-get command:
# apt-get update
# apt-get install python2.4

Red Hat Linux user try out:
# up2date python2.4
Fedora Linux user try out:
# yum install python2.4

Remember if you have both versions (python v2.3 and v2.4) installed, you need to run bittorent client as follows:
$ python2.4 /usr/bin/bittorrent-curses '/path/to/file.torrent'
Command line BitTorrent client should work with other UNIX like operating systems such as FreeBSD/OpenBSD/Solaris etc (as long as you have Python it should work).

The current client enables a range of features including multiple parallel downloads. It also intermediates peering between itself, source file servers (read as trackers) and other clients, thereby yielding great distribution efficiencies. The client also enables users to create and share torrent files. See help files for more information.

See also: