Wednesday, October 7, 2009

Apache: Port-Based Virtual Hosts

Problem

You want to present different content for HTTP connections on different ports.

Solution

Explicitly list the port number in the declaration:
Listen 8080


DocumentRoot


Listen 9090


DocumentRoot /www/vhosts/port9090

Apache:Splitting Up a LogFile

Problem

Because of a large number of virtual hosts, you want to have a single logfile for all of them and split it up afterward.

Solution

LogFormat "%v %h %l %u %t \"%r\" %>s %b" vhost
CustomLog logs/vhost_log vhost

Then, after rotating your logfile:
split-logfile < logs/vhost_log

Saturday, October 3, 2009

Episode 21: Sendmail /etc/mail/virtusertable Setup?

File: /etc/mail/virtusertable


finance@intinfra.com finance

#cd /etc/mail

#makemap hash virtusertable.db < virtusertable #service sendmail restart File: /etc/mail/access



finance: azit,abhi,receiver

#newaliases
#service sendmail restart

Try out sending mail to finance@groupinfra.com
And Found mail to all the three Users:

[receiver@Innova ~]$ mail
Mail version 8.1 6/6/93. Type ? for help.
"/var/spool/mail/receiver": 1 message 1 new
>N 1 sender@intinfra.co Sun Oct 4 03:34 16/650 "hi"
& t
Message 1:
From sender@intinfra.com Sun Oct 4 03:34:25 2009
Date: Sun, 4 Oct 2009 03:34:25 +0530
From: sender@intinfra.com
To: finance@intinfra.com
Subject: hi

hello

&

Episode 20: How can I redirect mail to a different port on my smarthost?

If a system administrator does not want to use the default port 25 for SMTP traffic to a smarthost, it can be redirected by inserting this line into the sendmail.mc file to change the port number:

define(`RELAY_MAILER_ARGS', `TPC $h XXXX')dnl


Replace XXXX with the desired port on the smarthost. The Sendmail service must be restarted after applying this change. Restart the service with:

service sendmail restart


Note: If for any reason, a restart of the mail server has to be avoided, the sendmail service can be reloaded instead by issuing the command:

service sendmail reload

Friday, October 2, 2009

Episode 19: How can I control whether incoming email is accepted, denied, or relayed when using Sendmail?

The file /etc/mail/access is used to accept, deny, or relay incoming email. This file controls access to users, entire domains, or an entire IP subnet. The first column specifies a user, domain, or subnet. The second column can be one of the following values:




REJECT
rejects the sender with a general purpose message

OK
accepts mail for receipt (not relay)

RELAY
accept mail for relaying

DISCARD
discard the message completely (harsher than reject)

ERROR:550 your message
like REJECT but returns with your specific message


Here is an example /etc/mail/access file:


user@spammer.org REJECT
spammers.net REJECT
204.168.23 REJECT
192.168 OK
virtualdomain.com RELAY
user@domain.com ERROR:550 mail discarded
nobody@ ERROR:550 bad name


After making changes to this file, execute the following for the changes to take effect:


# make -C /etc/mail
# service sendmail restart


For Example:

I add the following entry in /etc/mail/access :

receiver@intinfra.com REJECT
abhi ERROR:550 mail discarded
ajeet RELAY

Then I ran:
make -C /etc/mail
service sendmail restart

When I tried sending mail from user sender@groupinfra.com as:

[sender@Innova ~]$ echo "hello" | mail -v -s "hi" receiver@intinfra.com
receiver@intinfra.com... Connecting to [127.0.0.1] via relay...
220 Innova.intinfra.com ESMTP Sendmail 8.14.2/8.14.2; Sat, 3 Oct 2009 17:39:59 +0530
>>> EHLO Innova.intinfra.com
250-Innova.intinfra.com Hello localhost.localdomain [127.0.0.1], pleased to meet you
250-ENHANCEDSTATUSCODES
250-PIPELINING
250-8BITMIME
250-SIZE
250-DSN
250-ETRN
250-AUTH DIGEST-MD5 CRAM-MD5
250-DELIVERBY
250 HELP
>>> MAIL From: SIZE=47 AUTH=sender@Innova.intinfra.com
250 2.1.0 ... Sender ok
>>> RCPT To:
>>> DATA
550 5.2.1 ... Mailbox disabled for this recipient
503 5.0.0 Need RCPT (recipient)
>>> RSET
250 2.0.0 Reset state
/home/sender/dead.letter... Saved message in /home/sender/dead.letter
Closing connection to [127.0.0.1]
>>> QUIT
221 2.0.0 Innovation1.groupinfra.com closing connection

And When I tried :

[sender@Innova ~]$ echo "hello" | mail -v -s "hi" abhi@intinfra.com
abhinesh@intinfra.com... Connecting to [127.0.0.1] via relay...
220 Innova.intinfra.com ESMTP Sendmail 8.14.2/8.14.2; Sat, 3 Oct 2009 18:46:32 +0530
>>> EHLO Innova.intinfra.com
250-Innova.intinfra.com Hello localhost.localdomain [127.0.0.1], pleased to meet you
250-ENHANCEDSTATUSCODES
250-PIPELINING
250-8BITMIME
250-SIZE
250-DSN
250-ETRN
250-AUTH DIGEST-MD5 CRAM-MD5
250-DELIVERBY
250 HELP
>>> MAIL From: SIZE=47 AUTH=sender@Innova.intinfra.com
250 2.1.0 ... Sender ok
>>> RCPT To:
>>> DATA
550 5.0.0 ... mail discarded
503 5.0.0 Need RCPT (recipient)
>>> RSET
250 2.0.0 Reset state
/home/sender/dead.letter... Saved message in /home/sender/dead.letter
Closing connection to [127.0.0.1]
>>> QUIT
221 2.0.0 Innova.intinfra.com closing connection
[sender@Innova ~]$

So Both the receiver and abhi were discarded but when I tried mailing ajeet
it went successful.

[sender@Innova ~]$ echo "hello"|mail -v -s "I am here" ajeet@intinfra.com
ajeet@intinfra.com... Connecting to [127.0.0.1] via relay...
220 Innova.intinfra.com ESMTP Sendmail 8.14.2/8.14.2; Sat, 3 Oct 2009 18:54:29 +0530
>>> EHLO Innova.intinfra.com
250-Innova.intinfra.com Hello localhost.localdomain [127.0.0.1], pleased to meet you
250-ENHANCEDSTATUSCODES
250-PIPELINING
250-8BITMIME
250-SIZE
250-DSN
250-ETRN
250-AUTH DIGEST-MD5 CRAM-MD5
250-DELIVERBY
250 HELP
>>> MAIL From: SIZE=51 AUTH=sender@Innova.intinfra.com
250 2.1.0 ... Sender ok
>>> RCPT To:
>>> DATA
250 2.1.5 ... Recipient ok
354 Enter mail, end with "." on a line by itself
>>> .
250 2.0.0 n93DOTF2006201 Message accepted for delivery
ajeet@intinfra.com... Sent (n93DOTF2006201 Message accepted for delivery)
Closing connection to [127.0.0.1]
>>> QUIT
221 2.0.0 Innova.intinfra.com closing connection
[sender@Innova ~]$

So It is working for ajeet.

Episode 18: How can I make new aliases for my users if I am running sendmail?

Edit the /etc/aliases file. The syntax for the file is as follows:

username: newalias


Add the usernames and aliases then save the file. Then run (as the user root) the following command:


newaliases


Or restart sendmail with this command:


service sendmail restart

This is the same as running the following command:

sendmail -bi


The aliases database will now be rebuilt with the new changes.