A Linux Admin's WeBlog!

A place where I jot things which happens in my day-to-day life!

Burn an ISO image to a CD right from the command line! 10:05 PM

This is commonly used by system administrators who love simple, efficient and verbose method of writing an image into a Compact Disk. If you have an ISO file "image.iso", then you can use the "cdrecord" command:

cdrecord -v speed=8 dev=/dev/cdrom /path/to/image.iso
Attributes:

-v : Verbose mode, shows a lotta information while writing the disk.. geeky :-D
speed = : you can set the burning speed. 8 means 8x speed
-multi : multisession mode (ooooh, cool feature for a command line tool)

Listing files in Linux sorted according to size 9:29 PM

Have you ever felt the need to list the 10 files that takes the largest space in a specific directory? You might know that its pretty easy do that via GUI but believe me its the same thing when it comes to the Console also.

Here is how its done:

du -a (directory) | sort -n -r | head -n 10
This will list all the files in the directory specified, sorts them and lists the 10 files that takes up maximum size.

Easy, right?

Make files in your webserver download instead of being displayed 6:57 AM

Suppose, you have a text file in your web directory. When you access that file, it will be displayed in the web browser itself. If you want to make that file (or any other file type you want) to be asked to download instead of being displayed, here is what you can do:

Create a .htaccess file in that directory with the following content:

AddType unknown/nothing pdf
AddType unknown/nothing txt
AddType unknown/nothing jpg
Now when you access any file with an extension .jpg or .pdf, your browser will ask you to download the file instead of showing up.

Relaying email from Postfix via another SMTP Server 5:43 AM

Have you ever been in a situation where you want to relay your emails from your Postfix server via another SMTP server? This is certainly possible and its way too simple:

First thing to do is configure Postfix in your machine. Once done, edit the configuration file for Postfix (usually under /etc/main.cf) and editing the below value:

#relayhost =

to

relayhost = smtp.emailprovider.com

Once done, all emails sent via your Postfix server will be relayed through the desired Outgoing server.

Other options that may interest you are as follows:

  • myhostname = hostname.emailprovider.com
  • mydomain = emailprovider.com
  • masquerade_domains = emailprovider.com
The last option will correct the envelopes shows as "user@emailprovider.com".

Hope that helps someone :-)

Limiting Denial of Service (DoS) attacks 7:54 AM

Denial of Service (DoS) attack is an attempt by a malicious (or unwitting) user, process, or system to prevent legitimate users from accessing a resource (usually a network service) by exploiting a weakness or design limitation in an information system. Examples of DoS attacks include flooding network connections, filling disk storage, disabling ports, or removing power. This can be limited by setting timeouts.

  • # echo 30 > /proc/sys/net/ipv4/tcp_fin_timeout
  • # echo 1800 > /proc/sys/net/ipv4/tcp_keepalive_time
  • # echo 1 > /proc/sys/net/ipv4/tcp_window_scaling
  • # echo 0 > /proc/sys/net/ipv4/tcp_sack
  • # echo 1280 > /proc/sys/net/ipv4/tcp_max_syn_backlog

Source: http://sourcelinux.wikidot.com/firewall-using-iptables

Usages of "wget" command in Linux 8:03 PM

Wget, IMO, is the best download manager application I've ever seen for Linux operating system. Apart from the normal usages of wget, there are so many cool usages which can become real handy!

Resume Downloads:

# wget -c download_link

Download in background:

# wget -b download_link

Limit the bandwidth usage:

# wget --limit-rate=10k download_link

This will make wget download the file at a maximum speed of 10Kbps. This can be handy when downloading in background and there are other applications that needs Internet usage.

Download from websites having authentication:

# wget --username=username --password=password download_link

Download from an FTP server that requires authentication:

# wget --ftp-user=username --ftp-password=password download_link

Download a website completely (recursively):

# wget -r website_link

Download a website completely (recursively) up to a certain level:

# wget -r -l 5 website_link

Download up to 5 levels from the website directory.
Please make sure you have enough disk space before attempting to download like this.

Download a website and convert the links relative to the local system to make it available for offline use:

# wget --convert-links -r website_link

Torn ON mirroring:

# wget --mirror download_link

Download an HTML page along with its page requisites:

This helps to download a web page (HTML) along with the requirements of that page such as images, sounds, style sheets etc.

# wget --page-requisites download_link

Download Securely from HTTPS sites:

wget --secure-protocol=protocol_name download_link

Valid options for Protocol names are "auto", "SSLv2", "SSLv3", and "TLSv1". The option "auto" can be used if you dont want to specify the protocol to be used.

And.. yes.. that's not all.. there are so many other options for the wget command. Refer its manual pages for more details.. If I find anything more interesting, I will make sure I post it here :-)

Find all files matching a specific pattern and move them to a specified sub-folder 7:58 PM

To find all files matching a specific pattern and move them to a specified sub-folder, this command will be handy:

# find . -type f -exec grep -q 'search_string' {} \; -exec mv {} sub_folder_location/ \;