Showing posts with label Sendmail. Show all posts
Showing posts with label Sendmail. Show all posts

Saturday, July 10, 2010

Using Sendmail to Relay Mails from Your MSP/ISP in Centos, RHEL, Ubuntu and Other Linux Distros

Do you want to relay mails from your local sendmail server to your ISP. Just follow the below steps

Open sendmail.mc using default editor vi, edit, emacs
# vi /etc/mail/sendmail.mc

define(`SMART_HOST',`[smtp.yourisphost.com]')
FEATUREdnl

Save the File and exit
Open the File authinfo (If not Present Create a New File).


vi /etc/mail/authinfo
Add the following Line
"AuthInfo:smtp.yourisphost.com "U:UsernamefromISP" "P:passwordfromISP" "M:LOGIN PLAIN"

Save the File and Exit

Just run the below commands to recreate the sendmail.cf file

# cd /etc/mail/
# m4 sendmail.mc > sendmail.cf

Make Map will recreate the database for authinfo to be used in sendmail

# makemap hash /etc/mail/authinfo < /etc/mail/authinfo

Restart the Sendmail Service and check if All's Good !!!

# /etc/init.d/sendmail restart


echo '/map authinfo AuthInfo:smtp.yourisphost.com' | /usr/sbin/sendmail -bt



Sent Mail Check in Logs

Enjoy.....

Comment if issues or modification required.

Friday, July 9, 2010

Blocking Specific Sender to Specific Recipient or IPs Spamming Using Sendmail in Linux

Maintaining a MailServer is really a all time headache for Mail Server Admins, specifically to prevent SPAM relayed from you Server or delivered to your server.

In this article we would use some inbuilt feature of Sendmail to block users from sending mail to specific users or domains, this can be attained in many ways but i have done it in the below manner. For any issues please comment at the bottom of the post.

Sendmail is Oldest Mail transfer agent used by major of the MSP's (Mail Service Providers) all over the world, with its huge forum, mailing list and IRC Support and help it has gained high name within its competitors.

When Do i need to block a user or IP?
Reasons Are Many
1. Spamming done from your domain.
2. Spamming happening from outside to your server.
3. Spamming from a particular IP.
4. Wants to reject relaying mail for a user (Used incase allowed to just fetch mails, no sending allowed)
5. Any Many More...........

To block the user or IP we will be using access file / database included in the sendmail, Access Database provides a single, central database with rules to accept, reject, and discard messages based on the sender name, address, or IP number. It is enabled with the access_db configuration feature.

1. Enable the Access Database in Sendmail
You have to make add or declare the following lines in your sendmail.mc file

FEATURE(`access_db')

The above line added in the sendmail.mc enables use of the access database, and enables the default database type and path as:

hash /etc/mail/access

2. Create the access Database
Edit the File /etc/mail/access, the entries should be inorder

key value

The lefthand column is the key which is composed of a prefix and an address expression, this can contain hostname, email address, IP address, networks etc

The righthand column contains the value, which can be keywords or values that determine what should be done with the item described on the left or in a layman langauge the action to be executed, the preferable values are OK, RELAY, REJECT, DISCARD, SKIP, ERROR:XYZ text.

Eg :

spam@goo.gle.com REJECT
10.0.0.35 REJECT
192.168.1.100/255.0.0.0 REJECT
From:spammer@somedomain.com REJECT
To:trusteddomain.org RELAY
Connect:2trusteddomain.com OK
Connect:ashwin.com RELAY
From:good@domain.com OK
From:anotherbaddomain.com REJECT

To be able to block specific sender to specific recipient you need to add the following line in sendmail.mc to enable compat.
FEATURE(`check_compat')


Then make the following entries in access file (Location : /etc/mail/access)

Compat:extsender@mydomain.com<@>recipient@outdomain.com DISCARD


After confirming all the entries as per your requirement in access file, we have to recreate the access in hash database for which execute the below command

cd /etc/mail

makemap hash access < access

m4 /etc/mail/sendmail.mc > /etc/mail/sendmail.cf


Restart the sendmail service
/etc/init.d/sendmail restart


Testing

telnet to_your_mailserver_ip 25
mail from:internaluser@example.com
Ok
rcpt to:spam@goo.gle.com
REJECTED


Enjoy..

Tuesday, June 29, 2010

Solved : Lock table is out of available locker entries - Yum install, yum upgrade

Recently faced a issue while installing a package using yum
[root@back ~]# yum install mod-security
rpmdb: Lock table is out of available locker entries
rpmdb: Unknown locker ID: 3077
error: db4 error(22) from db->close: Invalid argument
error: cannot open Packages index using db3 - Cannot allocate memory (12)
error: cannot open Packages database in /var/lib/rpm
Traceback (most recent call last):
File "/usr/bin/yum", line 29, in ?
yummain.main(sys.argv[1:])
File "/usr/share/yum-cli/yummain.py", line 85, in main
base.getOptionsConfig(args)
File "/usr/share/yum-cli/cli.py", line 163, in getOptionsConfig
disabled_plugins=self.optparser._splitArg(opts.disableplugins))
File "/usr/lib/python2.4/site-packages/yum/__init__.py", line 164, in _getConfig
self._conf = config.readMainConfig(startupconf)
File "/usr/lib/python2.4/site-packages/yum/config.py", line 685, in readMainConfig
yumvars['releasever'] = _getsysver(startupconf.installroot, startupconf.distroverpkg)
File "/usr/lib/python2.4/site-packages/yum/config.py", line 752, in _getsysver
idx = ts.dbMatch('provides', distroverpkg)
TypeError: rpmdb open failed

Googling and Searching on this topic got it resolved
[root@back ~]# ll /var/lib/rpm/
Basenames __db.000 __db.002 Dirnames Group Name Providename Pubkeys Requireversion Sigmd5
Conflictname __db.001 __db.003 Filemd5s Installtid Packages Provideversion Requirename Sha1header Triggername
[root@back ~]# ll /var/lib/rpm/
Basenames __db.000 __db.002 Dirnames Group Name Providename Pubkeys Requireversion Sigmd5
Conflictname __db.001 __db.003 Filemd5s Installtid Packages Provideversion Requirename Sha1header Triggername

[root@back ~]# rm /var/lib/rpm/_db.00*
rm: cannot lstat `/var/lib/rpm/_db.00*': No such file or directory
[root@back ~]# rm /var/lib/rpm/__db.00*
rm: remove regular empty file `/var/lib/rpm/__db.000'? y
rm: remove regular file `/var/lib/rpm/__db.001'? y
rm: remove regular file `/var/lib/rpm/__db.002'? y
rm: remove regular file `/var/lib/rpm/__db.003'? y

[root@back ~]# rpm --rebuilddb

[root@back ~]# yum install mod-security

utterramblings 100% |=========================| 951 B 00:00

primary.xml.gz 100% |=========================| 22 kB 00:00

utterrambl: ################################################## 64/64

extras 100% |=========================| 2.1 kB 00:00

primary.sqlite.bz2 100% |=========================| 184 kB 00:38

updates 100% |=========================| 1.9 kB 00:00

primary.sqlite.bz2 100% |=========================| 254 kB 00:28

base 100% |=========================| 2.1 kB 00:00

primary.sqlite.bz2 100% |=========================| 1.6 MB 00:17

c5-testing 100% |=========================| 1.9 kB 00:00

addons 100% |=========================| 951 B 00:00

Setting up Install Process

Parsing package install arguments

No package mod-security available.

Nothing to do

[root@back ~]# yum install mod_security

Setting up Install Process

Parsing package install arguments

Resolving Dependencies

--> Running transaction check

---> Package mod_security.i386 0:2.5.9-1.jason.1 set to be updated

--> Finished Dependency Resolution
Dependencies Resolved
=============================================================================

Package Arch Version Repository Size

=============================================================================

Installing:

mod_security i386 2.5.9-1.jason.1 utterramblings 1.2 M
Transaction Summary

=============================================================================

Install 1 Package(s)

Update 0 Package(s)

Remove 0 Package(s)
Total download size: 1.2 M

Is this ok [y/N]: y

Downloading Packages:

(1/1): mod_security-2.5.9 100% |=========================| 1.2 MB 00:03

warning: rpmts_HdrFromFdno: Header V3 DSA signature: NOKEY, key ID 0d4306ef

Importing GPG key 0x0D4306EF "Jason Litka (http://www.jasonlitka.com) " from http://www.jasonlitka.com/media/RPM-GPG-KEY-jlitka

Is this ok [y/N]: y

Running rpm_check_debug

Running Transaction Test

Finished Transaction Test

Transaction Test Succeeded

Running Transaction

Installing: mod_security ######################### [1/1]
Installed: mod_security.i386 0:2.5.9-1.jason.1

Complete!

This problem occurs when rpm accesses the Berkeley database files, it makes temporary locker entries within the tables while it searches for data. If you control-c your rpm processes often, this issue will occur much sooner because the locks are never cleared.

Friday, March 5, 2010

Top Linux Admin Interview Questions asked in TOP IT industries : Question Bank 2

Top Linux Admin Interview Questions and Answers

Questions consists of Linux Admin Interview Questions and Answers, Linux Administration questions, Linux Networking questions, MYSQL questions, bash, postfix questions, sendmail questions, ftp server questions

Questions BANK 02


# What command is used to remove the password assigned to a group?

# You changed the GID of the sales group by editing the /etc/group file. All of the members can change to the group without any problem except for Joe. He cannot even login to the system. What is the problem? Choose one:
a. Joe forgot the password for the group.
b. You need to add Joe to the group again.
c. Joe had the original GID specified as his default group in the /etc/passwd file.
d. You need to delete Joe’s account and recreate it.

# You need to delete the group dataproject. Which two of the following tasks should you do first before deleting the group?
A. Check the /etc/passwd file to make sure no one has this group as his default group.
B. Change the members of the dataproject group to another group besides users.
C. Make sure that the members listed in the /etc/group file are given new login names.
D. Verify that no file or directory has this group listed as its owner.
Choose one: a. A and C b. A and D c. B and C d. B and D

# When you look at the /etc/group file you see the group kmem listed. Since it does not own any files and no one is using it as a default group, can you delete this group?

# When looking at the /etc/passwd file, you notice that all the password fields contain ‘x’. What does this mean? Choose one:
a. That the password is encrypted.
b. That you are using shadow passwords.
c. That all passwords are blank.
d. That all passwords have expired.

# In order to improve your system’s security you decide to implement shadow passwords. What command should you use?

# What file contains the default environment variables when using the bash shell? Choose one:
a. ~/.profile
b. /bash
c. /etc/profile
d. ~/bash

# You have created a subdirectory of your home directory containing your scripts. Since you use the bash shell, what file would you edit to put this directory on your path? Choose one:
a. ~/.profile
b. /etc/profile
c. /etc/bash
d. ~/.bash

# Which of the following interprets your actions when typing at the command line for the operating system? Choose One
a. Utility
b. Application
c. Shell
d. Command

# What can you type at a command line to determine which shell you are using?

# You want to enter a series of commands from the command-line. What would be the quickest way to do this? Choose One
a. Press enter after entering each command and its arguments
b. Put them in a script and execute the script
c. Separate each command with a semi-colon (;) and press enter after the last command
d. Separate each command with a / and press enter after the last command

# You are entering a long, complex command line and you reach the right side of your screen before you have finished typing. You want to finish typing the necessary commands but have the display wrap around to the left. Which of the following key combinations would achieve this? Choose One
a. Esc, /, Enter
b. /, Enter
c. ctrl-d, enter
d. esc, /, ctrl-d

# After typing in a new command and pressing enter, you receive an error message indicating incorrect syntax. This error message originated from.. Choose one
a. The shell
b. The operating system
c. The command
d. The kernel

Wednesday, February 17, 2010

Understanding and Reading Mail Logs, Postfix Logs, Sendmail Logs, Qmail Logs

How do I read Mail Log?

Logs play a crucial role in identifying the issue may it be Basic Problem or a Big Problem heap, logs generated can make a System Admins life quite easy if you know what exactly they say. Understanding Mail Logs, Postfix Logs, Sendmail Logs or any other MTA are all the same. All the Mail Server Programs are Logging aware.

Lets get to work and understand the Logs generated by RSyslog Daemon. I am Using Fedora 11 with Sendmail 8.14 installed on it. Sendmail Listens on Two ports
25 : MTA (Mail Transfer Agent)
587 : MSP (*Mail Submission Program/Port)

Example Log:

Feb 4 06:10:09 techy sendmail[5392]: o140e90B005392: from=, size=2434, class=0, nrcpts=1, msgid=<201002040040.o140e9Mi005380@techy.bounceme.net>, proto=ESMTP, daemon=MTA, relay=localhost [127.0.0.1]
Feb 4 06:10:09 techy sendmail[5380]: o140e9Mi005380: to=root, ctladdr=root (0/0), delay=00:00:00, xdelay=00:00:00, mailer=relay, pri=32168, relay=[127.0.0.1] [127.0.0.1], dsn=2.0.0, stat=Sent (o140e90B005392 Message accepted for delivery)



Feb 4 06:10:09 = Date of Mail received to the Mail Transfer Agent
techy = Hostname
sendmail[5392] = MTA or Application Name with PID for the Mail
o140e90B005392 = Queue ID
from= = Sender Address
to= Reciepient Address
Size=2434 = Size in Bytes
nrcpts=1 = Number of Recepients
msgid=<201002040040.o140e9Mi005380@www.linuxmaza.com> = Message ID (Unique of every Mail)
proto=ESMTP = Protocol Used
daemon=MTA = Application Handler In Sendmail it could be MSP or MTA
relay=localhost [127.0.0.1] = Mail relayed to the next Destination Server / Recipient Server
"delays=a/b/c/d"
where a=time before queue manager, including message transmission;
b=time in queue manager; c=connection setup time including DNS,
HELO and TLS; d=message transmission time. Numbers smaller than 0.01 seconds
are rounded to 0, to reduce the noise level in the logfile.

orig_to = This is omitted when the address did not change.
conn_use = This is omitted when a connection is used once.
ctladdr=root = Controlling user
dsn=2.0.0 = Delivery Status Notification, It can be 2.x.x, 4.x.x, 5.x.x Where 2.x.x is Successfully Sent, 4.x.x Is Mail Temporarily Deferred, 5.x.x stands for Permanent Failure
stat=Sent = Status of the Message. Values Sent,Deferred,Bounced

All the above parameters are almost same generated in Postfix Logs, Sendmail Logs, Qmail Logs also there could be some extra information about the mail added into the logs.

Tuesday, January 12, 2010

Simple Steps to Send Mail Using Sendmail in Linux, Fedora, Centos, Ubuntu

Have you got your Linux distribution like Fedora, Centos, Redhat, Gentoo up and running?

Have you found issues sending mail from linux or send mail from command line?

Having Problem in Manageing Linux Sendmail Mail Server to send your First Mail?

Your Answer to all your Questions ends Here..

Follow the below step by step guide how to send mails from the default installation of Sendmail. No Sendmail Configuration required to be changed.

Sendmail is generally used as a Mail server for relaying all your mails for your Local Area Network and also used as Direct delivery. Sendmail is very powerful and can be build as a standalone Centralized High Avaliability Mail Server for a organization. It has the capability to stop SPAM Stop Virus mail with 1000's of Trick which can be best suited for your needs. As Sendmail is Open Source Free to Use, Develop and Distribute its the best choice for todays Linux System Administrator. The Sendmail Configuration is as easy as adding or removing a line from a word file "here You must have a bit of knowledge what is to be deleted or added", Today it comes default installed with majority of Linux distribution avaliable worldwide. And if you dont find it installed just google it THE BIG G "Referring Google" will give you precisely the exact rpm (linux executable program) for your distribution of linux.

Its popularty increased with the Integration of Sendmail Milters (Mail Filter which are Highly Customizab;e) which have really changed the Fucntionality of Mail Server Today

Step 1.
Check if Sendmail is Running for which execute the following command :
ps ax | grep sendmail
If you get the output something like this
1846 ? Ss 0:13 sendmail: accepting connections
1850 ? Ss 0:00 sendmail: Queue runner@00:15:00 for /var/spool/clientmqueue
1855 ? Ss 0:00 sendmail: Queue runner@00:15:00 for /var/spool/mqueue

Great Your Copy of Sendmail is Running
OR Type the command in the terminal
/etc/init.d/sendmail start
You can see Sendmail Starting
Starting sendmail: [ OK ]


Step 2.
Next Step is to check Sendmail Listening IP:port. Listening IP:Port is nothing but the IP address and port number on which sendmail has started and will accept mails other than which connection would be refused. To Check enter the following:
[root@techy ~]# netstat -tnlp | grep sendmail
If You Get the resultant as this
tcp 0 0 0.0.0.0:587 0.0.0.0:* LISTEN 1846/sendmail: acce
tcp 0 0 0.0.0.0:25 0.0.0.0:* LISTEN 1846/sendmail: acce


Hurray !!! Your sendmail is ready to accept connection on all the interfaces of your machine. Here “0.0.0.0:587” is Sendmail Mail Submission Port and “0.0.0.0:25” is used to Send mail to External SMTP Source. IF You Need to make sendmail listen on specific port you need to change the sendmail.mc and Build a new Sendmail.cf which we would cover in the Sendmail Configuration Part.

Sendmail.mc : It is the macrotized Version for sendmail configuration
Sendmail.cf : IT is read by Sendmail Deamon to perform task.

BY Default Sendmail Does not allow mails to be relayed to external sources. We need to make sendmail configuration to perform such tasks. In this example we’ll send mail to local user which is “root”

Step 3.
Now the Final Steps is to check if Mail are sent properly
We’ll use Telnet if you are not familiar with telnet don’t worry just copy the code and it will do the magic for you.
[root@techy ~]# telnet 127.0.0.1 25
Trying 127.0.0.1...
Connected to 127.0.0.1.
Escape character is '^]'.
220 techy.bounceme.net ESMTP Sendmail 8.14.3/8.14.3; Tue, 12 Jan 2010 23:29:14 +0530
mail from:support@linuxmaza.com
250 2.1.0 support@linuxmaza.com... Sender ok
rcpt to:root@localhost
250 2.1.5 root@localhost... Recipient ok
data
354 Enter mail, end with "." on a line by itself
subject: My First Test Mail Using Sendmail.

This is First Paragraph.
.
250 2.0.0 o0CHxEYV022243 Message accepted for delivery
quit
221 2.0.0 techy.bounceme.net closing connection


Once You receive the final Message accepted for delivery. Great Just remember the first part of the line “o0CHxEYV022243” which would be helpful during crisis or troubleshooting sendmail. Now it’s the time to check the mail We’ll use mutt to check the mail.
[root@techy ~]# mutt
And check the mail. IF you Did not receive the mail You need to troubleshoot the issue checking the logs. The default location to check the logs for sendmail is /var/log/maillog or /var/log/mail.
Command to check: Do you remember the “o0CHxEYV022243” which we asked you earlier just parse the logs using the same you would get the reason for non-delivery or success messages.

[root@techy ~]# cat /var/log/maillog | grep "o0CHxEYV022243"
Jan 12 23:29:29 techy sendmail[22243]: o0CHxEYV022243: Authentication-Warning: techy.bounceme.net: localhost [127.0.0.1] didn't use HELO protocol
Jan 12 23:30:22 techy sendmail[22243]: o0CHxEYV022243: from=support@linuxmaza.com, size=70, class=0, nrcpts=1, msgid=<201001121759.o0CHxEYV022243@techy.bounceme.net>, proto=SMTP, daemon=MTA, relay=localhost [127.0.0.1]




We would be adding some Sendmail Videos. Please let us Know how did you like the information provided above and any suggestions. Drop a Mail to admin@linuxmaza.com