Monday, June 11, 2007

Qmail in Linux

Qmail is an SMTP (Simple Mail Transfer Protocol) Server for UNIX. This is the program that receives all incoming/outgoing mail for your domains.

Configuring QMail for @Mail

Find out the folder qmail lives in. On most linuxsystems this can be done by typing:
shell# locate qmail

The default folder for Qmail is /usr/local/qmail/.
Edit the control/virtualdomains file, and enter the domains you want qmail to accept email for and which folder to assign for it's incoming email.


myfirstdomain.com myfirstfolder-com
myseconddomain.com mysecondfolder-com
mythirddomain.com mythirdfolder-comFoldernames must be created in the Qmail mailnames folder

shell# mkdir /path-to-qmail/mailnames/myfirstfolder-com/ shell# mkdir /path-to-qmail/mailnames/mysecondfolder-com/ shell# mkdir /path-to-qmail/mailnames/mythirdfolder-com/

Finally, in order to make the email for the folders forward the email to @Mail, create a file called .qmail-default in the folders containing the following line:
/path-to-atmail/saveemail.pl $RECIPIENT

The $RECIPIENT must be included to tell the @Mail saveemail.pl script which user the email is intended for.
Once the .qmail-default file is created you can restart qmail and test your installation.

Restarting Qmail
If you are running linux, find out which rc file starts and stops qmail. These scripts are usually located in the /etc/rc.d/ folder or in the /etc/rc.d/init.d/, /etc/init.d/ folders. Find the script that starts up qmail and do a restart.

shell# /etc/rc.d/init.d/qmail stop
shell# /etc/rc.d/init.d/qmail start

Next, use the ps command to check if qmail is running.
shell# ps aux grep qmail
qmails 20750 0.0 0.1 1460 400 pts/1 S Aug06 0:00 qmail-send
qmaill 20762 0.0 0.1 1408 452 pts/1 S Aug06 0:00 splogger qmail
root 20763 0.0 0.1 1432 364 pts/1 S Aug06 0:00 qmail-lspawn ./Ma
qmailr 20764 0.0 0.1 1428 368 pts/1 S Aug06 0:00 qmail-rspawn
qmailq 20765 0.0 0.1 1392 328 pts/1 S Aug06 0:00 qmail-clean

Testing Email Delivery
Telnet to your machine on port 25 to send an email message manually. During this test phase, use your own email address as the sender. Debugging information will be sent to you if the message fails
First create a new account in @Mail, and test the email delivery to the account.

shell# telnet localhost 25
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
220 hostname ESMTP
mail from:
you@email.com
250 ok
rcpt to:
user@domain.com
250 ok
data
354 go ahead
test
.
250 ok 1028743136 qp 24920
quit
221 hostname
Connection closed by foreign host.

In this example you will have to give the mail from, rcpt to and data commands manually. Correct spelling of those is required. After the data command give a dot (.) on a single line to return. Use the quit command to get back to your shell.
If successful the user
user@myfirstdomain.com will receive a message with the text 'test' in the email body. If the email doesn't get received by this user, check out your maillog (usually /var/log/maillog , or /var/log/mail), or any email qMail might send back to your email address.

Testing the @Mail delivery script
If the above example fails, run the @Mail delivery script manually. shell# /path-to-atmail/saveemail.pl "user@domain.com"
Type a message then hit ^D (Control D) to quit.
Now check the users email account in @Mail, and check the message has been received. If you receive the message, but sending via the SMTP server does not work, check your qmail configuration.

FireWall

FireWall is use for two things.

1. To keep the people (worms and cracker) out

2. To keep the people (user) in


There are two types of firewalls.
a) Filtering Firewalls - that block selected network packets.
b)Proxy Servers (sometimes called firewalls) - that make network connections for you.

Packet Filtering:
Packet Filtering is the type of firewall built into the Linux kernel.
A filtering firewall works at the network level. Data is only allowed to leave the system if the firewall rules allow it. As packets arrive they are filtered by their type, source address, destination address, and port information contained in each packet.
Many network routers have the ability to perform some firewall services. Filtering firewalls can be thought of as a type of router. Because of this you need a deep understanding of IP packet structure to work with one.
Because very little data is analyzed and logged, filtering firewalls take less CPU and create less latency in your network.
Filtering firewalls do not provide for password controls. User can not identify themselves. The only identity a user has is the IP number assigned to their workstation. This can be a problem if you are going to use DHCP (Dynamic IP assignments). This is because rules are based on IP numbers you will have to adjust the rules as new IP numbers are assigned. I don't know how to automate this process.
Filtering firewalls are more transparent to the user. The user does not have to setup rules in their applications to use the Internet. With most proxy servers this is not true.
Proxy Servers:
Proxies are mostly used to control, or monitor, outbound traffic. Some application proxies cache the requested data. This lowers bandwidth requirements and decreases the access the same data for the next user. It also gives unquestionable evidence of what was transferred.
There are two types of proxy servers.
1) Application Proxies - that do the work for you.
2) SOCKS Proxies - that cross wire ports.

Application Proxy:
The best example is a person telneting to another computer and then telneting from there to the outside world. With a application proxy server the process is automated. As you telnet to the outside world the client send you to the proxy first. The proxy then connects to the server you requested (the outside world) and returns the data to you.
Because proxy servers are handling all the communications, they can log everything they (you) do. For HTTP (web) proxies this includes very URL they you see. For FTP proxies this includes every file you download. They can even filter out "inappropriate" words from the sites you visit or scan for viruses.
Application proxy servers can authenticate users. Before a connection to the outside is made, the server can ask the user to login first. To a web user this would make every site look like it required a login.

SOCKS Proxy:
A SOCKS server is a lot like an old switch board. It simply cross wires your connection through the system to another outside connection.
Most SOCKS server only work with TCP type connections. And like filtering firewalls they don't provide for user authentication. They can however record where each user connected to.
web counter