Archive for June, 2008

Simple firewall in linux

June 26, 2008

Just try this.

To use it:

  1. Create a file named /etc/init.d/firewall
  2. Copy and paste the script into it and save
  3. Edit the ALLOWED variable with port numbers you want to allow, default is ports 22 (SSH) and 80 (HTTP)
  4. Execute:
    touch /usr/local/etc/whitelist.txt && touch /usr/local/etc/blacklist.txt
  5. Edit the whitelist/blacklist files if you want
  6. Execute:
    chmod 755 /etc/init.d/firewall
  7. Execute:
    chkconfig --add firewall && chkconfig firewall on

The script:

#!/bin/bash
# chkconfig: 345 30 99
# description: Starts and stops iptables based firewall

## List Locations
#

WHITELIST=/usr/local/etc/whitelist.txt
BLACKLIST=/usr/local/etc/blacklist.txt

#
## Specify ports you wish to use.
#

ALLOWED="22 80 25"

#
## Specify where IP Tables is located
#

IPTABLES=/sbin/iptables

##
#DO NOT EDIT BELOW THIS LINE
###
RETVAL=0

# To start the firewall
start() {
  echo "Setting up firewall rules..."

	echo 'Allowing Localhost'
	#Allow localhost.
	$IPTABLES -A INPUT -t filter -s 127.0.0.1 -j ACCEPT

	#
	## Whitelist
	#

	for x in `grep -v ^# $WHITELIST | awk '{print $1}'`; do
	        echo "Permitting $x..."
	        $IPTABLES -A INPUT -t filter -s $x -j ACCEPT
	done

	#
	## Blacklist
	#

	for x in `grep -v ^# $BLACKLIST | awk '{print $1}'`; do
	        echo "Denying $x..."
	        $IPTABLES -A INPUT -t filter -s $x -j DROP
	done

	#
	## Permitted Ports
	#

	for port in $ALLOWED; do
	        echo "Accepting port TCP $port..."
	        $IPTABLES -A INPUT -t filter -p tcp --dport $port -j ACCEPT
	done

	for port in $ALLOWED; do
	        echo "Accepting port UDP $port..."
	        $IPTABLES -A INPUT -t filter -p udp --dport $port -j ACCEPT
	done

	$IPTABLES -A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
	$IPTABLES -A INPUT -p udp -j DROP
	$IPTABLES -A INPUT -p tcp --syn -j DROP

  RETVAL=0
}

# To stop the firewall
stop() {
  echo "Removing all iptables rules..."
  /sbin/iptables -F
  /sbin/iptables -X
  /sbin/iptables -Z
  RETVAL=0
}

case $1 in
  start)
		stop
    start
    ;;
  stop)
    stop
    ;;
  restart)
    stop
    start
    ;;
  status)
    /sbin/iptables -L
    /sbin/iptables -t nat -L
    RETVAL=0
    ;;
  *)
    echo "Usage: firewall {start|stop|restart|status}"
    RETVAL=1
esac

exit $RETVAL

how to delete last command from bash history

June 19, 2008

If you have ever typed something into a command prompt that you wished you hadn’t – you may find it useful to know that you can delete it from ~/.bash_history very easily.

The command:

history -d offset

will delete the history entry at position offset.

# history
1 cd
2 history
3 ls -alhF
4 history
5 wget username:password@private.ftp.com/secret/file.tar.gz
6 history

so to delete the wget command (which contains a password) – just use:
history -d 5

# history -d 5
# history
1 cd
2 history
3 ls -alhF
4 history
5 history
6 history -d 5
7 history

But suppose you KNOW you’re about to enter a command you don’t want to go into history. It’d be nice if you could just tack a little “hideme” modifer onto the front or tail of your command and be done with it. Unfortunately from what I’ve been able to google there is no such feature built into history or bash.

Naturally I made one.

TMP=$(history | tail -1 | awk ‘{print $1}’) && history -d $TMP && \
paste_in_shell_and_replace_this_with_whatever_you_want_to_hide

Rather than holding down backspace, you may find it useful to know that in bash Ctrl-W will delete from the cursor to the beginning of the previous word. Or if you think you’re going to use it A LOT you may try to put a little function/alias into your .bashrc:

func_hide ()
{
TMP=$(history | tail -1 | awk ‘{print $1}’) && history -d $TMP
}

alias hideme=’func_hide’

Dig the sneaky:

# history
1 cd
2 history
3 ls -alhF
4 history
5 history
6 history -d 5
7 history
8 vi .bashrc
9 history
# hideme && mysecretcommand
# history
1 cd
2 history
3 ls -alhF
4 history
5 history
6 history -d 5
7 history
8 vi .bashrc
9 history
10 history

How to reset MySQL root password?

June 18, 2008

If you forgot root password for your MySQL server, you can follow the steps below to reset it.

1. Login to the server as root and stop MySQL service.

# /etc/init.d/mysqld stop

2. Start mysqld_safe service.

# mysqld_safe –skip-grant-tables &

3. Login to MySQL server now. It won’t ask you for a password.

# mysql -u root

4. Set up a new MySQL root user password:

mysql> use mysql;

mysql> update user set password=PASSWORD(”NEW-ROOT-PASSWORD”) where User=’root‘;

mysql> flush privileges;

mysql> quit

5. Restart your MySQL service.

# /etc/init.d/mysqld restart

6. Try to login using new password. It should work fine.

# mysql -u root -p

That’s it !!!

Domain redirection using PHP script

June 18, 2008

If you want to redirect a domain to some other url, you can use the PHP script below.

index.php
—————————————-
<?php
header(”Location: http://destination-domain.com/where-you-want-to-redirect/index.html”);
exit();
?>
—————————————-

So, when you take http://your-domain.com or http://your-domain.com/index.php it will be redirected to “http://destination-domain.com/where-you-want-to-redirect/index.html”.

How to configure OutLook email client?

June 18, 2008

Steps to configure OutLook Email client

+++++++++++++++++++++++++++++

1. Click “Tools” -> “Email Accounts” on the menu bar.

2. Select “Add a new e-mail account” and click “Next”.

3. Select “POP3″ and click “Next”.

4. Enter your name and email address under “User Information”.

5. Under “Logon Information”, enter the username and password you use to login to the mail server. MAKE SURE to put the domain at the end of the username — e.g. “user@domain.com” and not just “user”.

6. Check “Remember password” if desired.

7. Under “Server Information”, enter the mailserver in both the POP3 and SMTP fields.

8. Click “More Settings…”.

9. Open the tab “Outgoing Server”. Check the box that says “My outgoing server (SMTP) requires authentication”, and make sure that “Use same settings as my incoming mail server” is selected beneath that.

10. Click “OK”, then “Next”, and then “Finish”.

How to configure OutLook Express

June 18, 2008

Steps to configure configure Outlook Express.
+++++++++++++++++++++++++++++++++
1) Launch Outlook Express

2) Click Tools>>Accounts.

3) In the “Internet Accounts Windows” click Add >> Mail.

4) Fill in your username and Click Next.

5) Fill in your email address and Click Next.

6) On the “Email Servers Name” page, fill in the server information.
“My incoming mail server is a POP3 server.”

“Incoming Mail server”: –> Fill in with your mail server name.
“Outgoing mail server”: –> Fill in with your mail server name.
Now, Click Next.

7) In the account name field enter your e-mail address (name@domain.com) and the password below. Click Next.

8)Click Finish.

Now,
9) Take Tools >> Accounts >> Properties >> Servers
Enable the “My server requires authentication” option and click Apply

10) Click the Advanced tab,
Enable the “Leave a copy of messages on the server” option and click Apply.

Now Outlook Express must be configured for you to send and receive mails.

Postsuper commands

June 12, 2008

Requeue the messages with
“postsuper -r ALL”.

Delete All messages in the queue

“postsuper -d ALL”.

Delete a single message

“postsuper -d message-id”.

How to resolve primary virus scanner (auto) error in Mailscanner

June 12, 2008

You may find you get an error like:

Unable to select a regular expression for your primary virus scanner (auto) – please see the examples in functions.php to create one.

This happens when you are using newer versions of MailScanner and have the auto setting turned on in your MailScanner.conf file. Edit the configuration and set the string for your virus scanner instead of using the auto setting like:

##Virus Scanners = auto
Virus Scanners = clamav

SquirrelMail and Courier IMAP

June 3, 2008

Hi ,

I was getting error when dealing with courier imap and squirrelmail .

ERROR : Could not complete request. Query:CREATE "INBOX./Sent" Reason Given: Invalid mailbox name

To correct this for all your users and run ./conf.pl (must be run from config/ in Squirrelmail’s root dir) select option 3 then 1 and enter ‘none’ (without the quotes). Save your changes and exit.

That might fix it, but in the most current version (1.4.0) from the main screen in ./conf.pl choose “D” and then pick your imap server.

If you are still having problems maximize your PHP error reporting by editing php.ini and changing:

   display_errors = on
   error_reporting = E_ALL

Then restart your web server.

Hope this helps you all.

error installing amavisd-new clamav on centos 5

June 2, 2008

Hi friends ,

m back

when trying to install amavisd-new on centos 5 , i was getting following error.

yum install amavisd-new spamassassin clamav clamd unzip bzip2 unrar

there is the message no match argument found.

So i googled few mins as usual and found the solution

Thing to check:

1. Check your /etc/yum.repos.d/
CentOS-Base.repo CentOS-Media.repo

Let say you already have this two repos.
To get the dag repo manually try this:

Use your favorite editor (vi or nano or etc) create rpmforge.repo

1. nano /etc/yum.repos.d/rpmforge.repo
2. Copy the code below and paste it into rpmforge.repo

# Name: RPMforge RPM Repository for Red Hat Enterprise 4 – dag
# URL: http://rpmforge.net/
[rpmforge]
name = Red Hat Enterprise $releasever – RPMforge.net – dag
#baseurl = http://apt.sw.be/redhat/el4/en/$basearch/dag
mirrorlist = http://apt.sw.be/redhat/el4/en/mirrors-rpmforge
#mirrorlist = file:///etc/yum.repos.d/mirrors-rpmforge
enabled = 0
gpgkey = file:///etc/pki/rpm-gpg/RPM-GPG-KEY-rpmforge-dag
gpgcheck = 1

3. Type this command

rpm –import http://dag.wieers.com/rpm/packages/RPM-GPG-KEY.dag.txt

This key will store in this directory /etc/pki/rpm-gpg/RPM-GPG-KEY-rpmforge-dag.

You may also download the GPG key manual and store it. Then just type “rpm –import RPM-GPG-KEY.dag.txt”

4. Type this command

yum –enablerepo=rpmforge list amavisd-new spamassassin clamav clamd unzip bzip2 unrar

still it gave me following error on centos 5 :

—> Package compat-db.i386 0:4.2.52-5.1 set to be updated
–> Running transaction check
–> Processing Dependency: lha for package: amavisd-new
–> Finished Dependency Resolution
Error: Missing Dependency: lha is needed by package amavisd-new

wget http://dag.wieers.com/rpm/packages/lha/lha-1.14i-19.2.2.el5.rf.i386.rpm

rpm -ivh lha-1.14i-19.2.2.el5.rf.i386.rpm

###############################################################################

yum –enablerepo=rpmforge install amavisd-new spamassassin clamav clamd unzip bzip2 unrar

###############################################################################

So i had a happy ending to my story, hope u liked the story.

Bye and enjoy with linux

tc