Showing posts with label howto. Show all posts
Showing posts with label howto. Show all posts

Monday, June 9, 2014

Limiting recursive lookups in Bind

Limiting recursive lookups in Bind is a good idea for several reasons:
  1. Why give free DNS service to the entire internet.
  2. A source of denial of service flood attack.
  3. Increases traffic, which may increase costs.
  4. Increases CPU usage.
In /etc/bind/named.conf.options:
 acl "trusted" {
     111.222.333.444/55;
        127.0.0.1;
     localhost;
     localnets;
 };


options {
        directory "/var/cache/bind";

        auth-nxdomain no;    # conform to RFC1035
        additional-from-auth no;
        additional-from-cache no;
        allow-query { any; };
        allow-recursion { trusted; };
        allow-query-cache { trusted; };

};

Binding postfix to use a specific ip address.

Now-a-days with SPF records and such, it's always a good idea to limit postfix to use the ip address specified in the spf record to prevent your mail from being marked as spam. This is only necessary if your server has more that one ip bound to it. 

In /etc/postfix/main.cf add:
smtp_bind_address = 111.222.333.444

This will limit your postfix server to using the ip specified.

Friday, May 16, 2014

Postfix management / Mail administrator primer

I thought I'd write a little primer with some of the most important commands you will use as a mail administrator.

Most servers will use postfix. So I will concentrate on postfix centric commands.

How to check your mail queue:
# postqueue -p


This will all mail that is in the queue waiting to be delivered. This is usually the first place I go to check if someone is sending spam from my server.

Once you find a domain that is sending out spam, you should probably stop your mail server.

Shutdown postfix:
# /etc/init.d/postfix stop

At this point you should probably "plug the hole". What I mean by that is that you should locate the compromised email account and change the password, and notify the user.

If is being generated by the site itself, it will usually say the mail is from "PHPMAILFUNCTION@xzy.com". In that case, you will need to contact the site administrator for that site, and disable the MAIL function in the .htaccess file (if your server supports it).

One you plug the hole, you'll want to delete all the mail in the queue that is coming from that site. Use the following command (replacing example.com with the offending domain):

# find /var/spool/postfix/* -type f -exec grep -irl "example.com" {} \; -exec rm -vf {} \;

Re-run # postqueue -p to double-check you've got it all.

Once you are satisfied your eliminated all the spam in the queues, you can restart the mail server with:
# /etc/init.d/postfix start

That's it, you are good to go. Next I will write an article about accessing the damage done to your IP reputation.

Saturday, July 20, 2013

How limit postfix from sending email certain domains in Debian Squeeze

Well all know those certain users that you know they got that job because they are related to someone. And, most of them tend to send mail to made up domains.

This is how to limit them from sending to domains that don't exist.

Open up:
nano /etc/postfix/maps/header_checks

Add the following line per your requirements:
/^To:.*@hotmail\.com\.mx/ REJECT This domain does not exist.
/^To:.*@gmail\.com\.mx/ REJECT This domain does not exist.

You can easily change To: to From: and block receiving emails from those domains as well.

Here is a guide that might help you with other things you might want to block: http://www.akadia.com/services/postfix_uce.html

Friday, July 19, 2013

Installing monitoring, cli and configuration software for a PERC5 raid controller on Debian Squeeze

Please add deb http://hwraid.le-vert.net/distrib branch main to /etc/apt/sources.list to access all packages.
distrib can be either debian or ubuntu.
branch can be lenny, squeeze, wheezy and sid for debian, or hardy, intrepid, jaunty and lucid for ubuntu.

In example, for current Debian stable release (Squeeze):
deb http://hwraid.le-vert.net/debian squeeze main

Theses packages are available for amd64 and i386 architectures. Sources packages are available as well (replace deb with deb-src).

Once you add the repo above do:

apt-get install megacli megaclisas-status megactl

To view the original doc: http://hwraid.le-vert.net/wiki/DebianPackages
To get the list of commands: http://hwraid.le-vert.net/wiki/LSIMegaRAIDSAS

Installing E-accelerator on Debain Squeeze

Download it

cd /tmp
wget http://www.debiantutorials.com/static/eaccelerator-0.9.6.1.tar.bz2

Unpack it

tar -xvjf eaccelerator-0.9.6.1.tar.bz2

Prepare for compiling it

apt-get install php5-dev make
cd eaccelerator-0.9.6.1
phpize

Compile it

Note: The extra option –without-eaccelerator-use-inode is a fix for problems of basedir-open/basedir-restrictions found with this version of eAccelerator.
See http://tipstricks.itmatrix.eu/?p=1297 for more details.

./configure --enable-eaccelerator=shared --without-eaccelerator-use-inode
make
make install

Add a configuration to it

Add the following configuration in: /etc/php5/conf.d/eaccelerator.ini

extension="eaccelerator.so"
eaccelerator.shm_size="16"
eaccelerator.cache_dir="/var/cache/eaccelerator"
eaccelerator.enable="1"
eaccelerator.optimizer="1"
eaccelerator.check_mtime="1"
eaccelerator.debug="0"
eaccelerator.filter=""
eaccelerator.shm_max="0"
eaccelerator.shm_ttl="0"
eaccelerator.shm_prune_period="0"
eaccelerator.shm_only="0"
eaccelerator.compress="1"
eaccelerator.compress_level="9"

Create the cache directory for it

mkdir -p /var/cache/eaccelerator
chmod 0777 /var/cache/eaccelerator


Restart Apache2
/etc/init.d/apache2 restart

How to fix SSH timeouts

This is such a nuisance. I don't know of anything more annoying than to walk away to the bathroom, kitchen or whatever; and come back to find your terminal session disconnected.

This can also be helpful when running jobs that take a little longer, but I would really advise using SCREEN for that.

We will tackle this problem from both ends, the server and the client.


On the server

Edit /etc/ssh/sshd_config and add the line:


ClientAliveInterval 60

On the client

Edit /etc/ssh/ssh_config and add the line:

ServerAliveInterval 60

Installing Logwatch on Debian Squeeze

Logwatch is a good package that can send you emails every morning that you can peruse over your coffee. Is will run through your log file looking for anomalies.

It doesn't get much easier than this.

apt-get install logwatch

Config file here:
/usr/share/logwatch/default.conf/logwatch.conf

How to turn off IPv6 in Bind9 in Squeeze

In order to stop those nasty messages in your log files about not being able to find the route for IPV6 lookups, just do this:

nano /etc/default/bind9

Change OPTIONS to:

OPTIONS="-4 -u bind"

"-4" will tell bind to use ipv4 only.

How to turn off IPv6 in Debian Squeeze

Disabling IPv6 is not crucial however I like to keep my logs clean and to a minimum. 

Disable ipv6 in kernel :
echo net.ipv6.conf.all.disable_ipv6=1 > /etc/sysctl.d/disableipv6.conf will disable ipv6 at next reboot.

Installing Denyhosts on Debian Squeeze(6.0.7)

While trying to install Denyhosts on Debian(with SYNCING working), I ran around this guide: Preventing_ssh_dictionary_attacks_with_denyhosts on Debian on Howtoforge. It had be written in 2006. Time for an update.

The DenyHosts in the Debian Repos worked fine, if you are not interested in SYNCing. If your not using syncing in Denyhosts, you might as well use Fail2ban, as it covers more services that just SSH.

The sync feature really sets Denyhosts apart from the rest of the pack. Because as soon as an IP is detected and banned on a server half-way around the world, it will will shortly be pre-emptively banned on your server as well. So you are protected by, as well as helping to protect others.

Here is what worked for me:

1 Installation

DenyHosts is written in Python, therefore we must install Python and also the Python development files first:

apt-get install python2.6-dev python2.6

or you can probably get away with doing:

apt-get install python python-dev

I just happened to know that 2.6 was the latest in the repos anyways.

Then we download and install DenyHosts like this:
cd /tmp
wget http://sourceforge.net/projects/denyhosts/files/denyhosts/2.6/DenyHosts-2.6.tar.gz/download
tar xvfz
DenyHosts-2.6.tar.gz 

cd DenyHosts-2.6
python setup.py install
This installs DenyHosts to /usr/share/denyhosts.

2 Configuration

Now we have to create the DenyHosts configuration file /usr/share/denyhosts/denyhosts.cfg. We can use the sample configuration file /usr/share/denyhosts/denyhosts.cfg-dist for this:

cd /usr/share/denyhosts
cp denyhosts.cfg-dist denyhosts.cfg


Make sure you set SECURE_LOG and LOCK_FILE to the correct values for your distribution! For Debian, these are:

SECURE_LOG = /var/log/auth.log
LOCK_FILE = /var/run/denyhosts.pid


As we want to run DenyHosts as a daemon, we need the daemon control script /usr/share/denyhosts/daemon-control. Again, we can use the sample script /usr/share/denyhosts/daemon-control-dist to create the needed file:

cp daemon-control-dist daemon-control
Edit /usr/share/denyhosts/daemon-control and make sure you set the correct values for DENYHOSTS_BIN, DENYHOSTS_LOCK, and DENYHOSTS_CFG. For Debian, these are:

DENYHOSTS_BIN   = "/usr/local/bin/denyhosts.py"
DENYHOSTS_LOCK  = "/var/run/denyhosts.pid"
DENYHOSTS_CFG   = "/usr/share/denyhosts/denyhosts.cfg"


Next we have to make that file executable:

chown root daemon-control
chmod 700 daemon-control

Afterwards, we create the system bootup links for DenyHosts do that it is started automatically when the system is booted:

cd /etc/init.d
ln -s /usr/share/denyhosts/daemon-control denyhosts
update-rc.d denyhosts defaults

Finally, we start DenyHosts:
/etc/init.d/denyhosts start
 
DenyHosts logs to /var/log/denyhosts, if you are interested in the logs. The SSH daemon logs to /var/log/auth.log on Debian. You can watch both logs and try to log in with an invalid user or with a valid user and incorrect password, etc. via SSH and see what happens. 

Credits to: Falko Timme <ft [at] falkotimme [dot] com> for writing the original guide I drew most of this text from.