Mailserver Postfix, Dovecot, MySQL etc.
20.06.2011
21:29:58 Uhr5330 Aufrufe
1 Antwort
21:29:58 Uhr
1 Antwort
Hilfreich +4
Linux Mailserver mit
-Postfix
-Dovecot
-Postfixadmin
-MySQL
-Spamassassin
-Diverse Scripte
-Postfix
-Dovecot
-Postfixadmin
-MySQL
-Spamassassin
-Diverse Scripte
Inhaltsverzeichnis
Übersicht
Man kann E-Mails wahlweise über POP3 oder IMAP mit seinem Login abrufen. Vorzugsweise per SSL.
• Zum versenden von E-Mail muss man sich einloggen. Standardisiert per SMTP-AUTH, nicht POP-before-SMTP.
• Man kann nur seine eigenen E-Mail-Adressen zum Versenden nutzen
• Es sind viele Nutzer möglich, die ebenfalls nicht als Nutzer auf dem System (/etc/passwd, usw.) angelegt werden
• Die Daten werden in einer zentralen Datenbank gespeichert. Hier in einer MySQL-DB.
• Die Verwaltung erfolgt über Postfixadmin
• Roudcube und Postfixadmin auf anderen Server
• IPTabels Firewall
Durch die Verwendung der MySQL-Datenbank kann man einfach und schnell neue Nutzer und Domains anlegen, ohne jedes Mal viel Konfigurationsaufwand betreiben zu müssen.
Installation
Grundinstallation Debian 600 (Squezze)
Auskommentieren des CD Laufwerkes aus /etc/apt/sources.list dmait der Server nicht immer nach dem CD Laufwerk fragt
Installation aller benötigten Pakete
01.
apt-get install openssl ssh rsync fail2ban mysql-server dovecot-common dovecot-imapd dovecot-pop3d postfix postfix-mysql logwatch mc-ssh für den Remote Zugriff
-Rsync für evtl. Synchronisationen
-Fail2ban um Ip Adressen zu Sperren
-MySQL als Datenbank Server für Postfix
-Dovecot als IMAP/POP/Sieve Server
-Postfix als SMTP Server
-Logwatch damit eine Log Auswertung per email Versand wird
-MC als Editor
Falls ihr einen Server mit mehr als 4 GB Ram benützt müsst ihr noch einen anderen Kernel installieren
01.
apt-get install linux-image-2.6.32-5-bigmemKonfiguration
Konfiguration von Logwatch
Der Logwatch Detail Grad ist auf Hoch gesetzt und die Mails gehen jeden Tag um 20 Uhr an example@example.com/usr/share/logwatch/dist.conf/logwatch.conf
01.
mailer = "/usr/sbin/sendmail -t" 02.
TmpDir = /tmp 03.
MailFrom = root 04.
Detail = High 05.
Service = AllIn der Crontab ist noch folgende Eingabe zu tätigen
Öffnet die Crontab
01.
crontab -e01.
00 20 * * * /usr/sbin/logwatch –mail-to pachler@delta.co.atKonfiguration von Dovecot
Ich habe hier die Konfigurations Datein so kommentiert das hier jede Erklärung fehl am Platz wäre./etc/dovecot/dovecot.conf
01.
################################# 02.
# 03.
# Unterstütze Protokolle 04.
# 05.
################################# 06.
protocols = imaps pop3s managesieve 07.
08.
################################# 09.
# 10.
# Sicherheit 11.
# 12.
################################# 13.
disable_plaintext_auth = no 14.
auth_mechanisms = plain 15.
log_timestamp = "%Y-%m-%d %H:%M:%S " 16.
ssl_cert_file = /etc/postfix/sslcert/olympia.crt 17.
ssl_key_file = /etc/postfix/sslcert/olympia.key 18.
19.
############################################ 20.
# 21.
# Konfiguration der Protokolle 22.
# 23.
############################################ 24.
protocol pop3 { 25.
pop3_uidl_format = %08Xu%08Xv 26.
} 27.
28.
protocol imap { 29.
mail_plugins = quota imap_quota 30.
} 31.
32.
protocol lda { 33.
postmaster_address = example@example.com 34.
auth_socket_path = /var/run/dovecot/auth-master 35.
mail_plugins = sieve 36.
} 37.
38.
############################################# 39.
# 40.
# Passwort abfragen 41.
# 42.
############################################ 43.
auth default { 44.
mechanisms = plain login 45.
46.
passdb sql { 47.
args = /etc/dovecot/dovecot-mysql.conf 48.
} 49.
userdb sql { 50.
# Path for SQL configuration file, see /etc/dovecot/dovecot-sql.conf for example 51.
args = /etc/dovecot/dovecot-mysql.conf 52.
} 53.
user = root 54.
############################################### 55.
# 56.
# Passwort Datenbanken/BACKEND 57.
# 58.
############################################### 59.
socket listen { 60.
master { 61.
path = /var/run/dovecot/auth-master 62.
mode = 0600 63.
user = vmail 64.
} 65.
client { 66.
path = /var/spool/postfix/private/auth_dovecot 67.
mode = 0660 68.
user = postfix 69.
group = postfix 70.
} 71.
} 72.
} 73.
74.
################################################## 75.
# 76.
# PLGUINS 77.
# 78.
################################################## 79.
plugin { 80.
sieve_dir = /home/mail/%d/%n/sieve 81.
sieve = /home/mail/%d/%n/dovecot.sieve 82.
quota = maildir:User quota 83.
quota_rule = *:storage=10M 84.
quota_warning = storage=95%% /usr/local/sbin/quota-warning.sh 95 85.
quota_warning2 = storage=80%% /usr/local/sbin/quota-warning.sh 80 86.
} 87.
88.
#EOFNun kommt die Datenbankanbindung für Dovecot
/etc/dovecot/ dovecot-mysql.conf
01.
driver = mysql 02.
connect = host=localhost dbname=postfix user=postfix password=mysqlpw 03.
default_pass_scheme = PLAIN-MD5 04.
password_query = SELECT password FROM mailbox WHERE username = '%u' 05.
user_query = SELECT CONCAT('maildir:/home/mail/',maildir) AS mail, 5000 AS uid, 5000 AS gid, concat('*:bytes=', mailbox.quota) AS quota_rule FROM mailbox WHERE username = '%u' Konfiguration von Postfix
Auch hier sind die Konfig Datein wider kommentiert für eventuelle Fragen einfach ein KOmmentar schreiben
/etc/postfix/main.cf
01.
########################################## 02.
# 03.
# Allgmein 04.
# 05.
########################################## 06.
myhostname = example.example.com 07.
myorigin = /etc/mailname 08.
mydestination = example.example.com 09.
localhost.delta.co.at, 10.
localhost 11.
mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128 12.
mailbox_size_limit = 0 13.
recipient_delimiter = + 14.
inet_interfaces = all 15.
smtpd_banner = $myhostname 16.
delay_warning_time = 4h 17.
biff = no 18.
append_dot_mydomain = no 19.
readme_directory = no 20.
21.
########################################## 22.
# 23.
#SSL/TLS parameters 24.
# 25.
########################################## 26.
smtpd_tls_cert_file = /etc/postfix/sslcert/olympia.crt 27.
smtpd_tls_key_file = /etc/postfix/sslcert/olympia.key 28.
smtpd_use_tls=yes 29.
smtpd_tls_session_cache_database = btree:${data_directory}/smtpd_scache 30.
smtp_tls_session_cache_database = btree:${data_directory}/smtp_scache 31.
32.
######################################### 33.
# 34.
# Anmeldung 35.
# 36.
######################################### 37.
smtpd_sasl_type=dovecot 38.
smtpd_sasl_path=private/auth_dovecot 39.
smtpd_sasl_auth_enable = yes 40.
smtpd_sasl_authenticated_header = yes 41.
broken_sasl_auth_clients = yes 42.
43.
######################################### 44.
# 45.
# Sicherheit 46.
# 47.
######################################## 48.
disable_vrfy_command = yes 49.
smtpd_helo_required = yes 50.
strict_rfc821_envelopes = yes 51.
52.
################################################# 53.
# 54.
# ANTI SPAM 55.
# REIHENFOLGE BEACHTEN 56.
# 57.
################################################# 58.
smtpd_client_restrictions = permit_sasl_authenticated 59.
permit_mynetworks 60.
reject_unknown_client 61.
62.
smtpd_helo_restricitons = permit_sasl_authenticated 63.
permit_mynetworks 64.
reject_invalid_hostname 65.
reject_non_fqdn_hostname 66.
67.
smtpd_sender_restrictions = permit_sasl_authenticated 68.
permit_mynetworks 69.
reject_unknown_sender_domain 70.
reject_non_fqdn_sender 71.
72.
smtpd_recipient_restrictions = permit_sasl_authenticated 73.
reject_unknown_recipient_domain 74.
reject_non_fqdn_recipient 75.
reject_unauth_pipelining 76.
reject_unauth_destination, 77.
reject_unlisted_recipient, 78.
reject_invalid_hostname, 79.
reject_non_fqdn_sender, 80.
reject_unknown_sender_domain, 81.
reject_unverified_recipient, 82.
reject_rbl_client sbl.spamhaus.org, 83.
reject_rbl_client dialup.blacklist.jippg.org, 84.
reject_rbl_client cbl.abuseat.org, 85.
reject_rbl_client zen.spamhaus.org, 86.
reject_rbl_client dnsbl.sorbs.net 87.
permit_auth_destination 88.
check_policy_service inet:127.0.0.1:12525 89.
reject 90.
91.
################################################ 92.
# 93.
# MySQL und MAIL Dir 94.
# 95.
################################################# 96.
smtpd_sender_login_maps = proxy:mysql:/etc/postfix/mysql_sender_login_maps.cf 97.
virtual_alias_maps = proxy:mysql:/etc/postfix/mysql_virtual_alias_maps.cf 98.
virtual_mailbox_base = /home/mail/ 99.
virtual_mailbox_domains = proxy:mysql:/etc/postfix/mysql_virtual_domains_maps.cf 100.
virtual_mailbox_limit = 112400000 101.
virtual_mailbox_maps = proxy:mysql:/etc/postfix/mysql_virtual_mailbox_maps.cf 102.
virtual_minimum_uid = 104 103.
virtual_transport = virtual 104.
virtual_uid_maps = static:5000 105.
virtual_gid_maps = static:5000 106.
virtual_transport = dovecot 107.
dovecot_destination_recipient_limit = 1 108.
proxy_read_maps = $local_recipient_maps $mydestination $virtual_alias_maps $virtual_alias_domains $virtual_mailbox_maps $virtual_mailbox_domains $relay_recipient_maps $relay_domains $canonical_maps $sender_canonical_maps $recipient_canonical_maps $relocated_maps $transport_maps $mynetworks $smtpd_sender_login_maps 109.
110.
111.
#EOFAm Anfang der Datei /etc/postfix/master.conf müssen wir noch folgendes einfügen damit die Mails über Spamassasin geleitet werden
01.
smtp inet n - n - - smtpd -o content_filter=spamassassinNun folgen noch die gesamten Datenbanabfragen die Postfix benötigt:
/etc/postfix/mysql_sender_login_maps.cf
01.
hosts = localhost 02.
user = postfix 03.
password = mysqlpw 04.
dbname = postfix 05.
query = SELECT username AS allowedUser FROM mailbox WHERE username="%s" AND active = 1 UNION SELECT goto FROM alias WHERE address="%s" AND active = 1/etc/postfix/mysql_virtual_alias_maps.cf
01.
hosts = localhost 02.
user = postfix 03.
password = mysqlpw 04.
dbname = postfix 05.
query = SELECT goto FROM alias WHERE address='%s' AND active = '1'/etc/postfix/mysql_virtual_domains_maps.cf
01.
hosts = localhost 02.
user = postfix 03.
password = mysqlpw 04.
dbname = postfix 05.
query = SELECT domain FROM domain WHERE domain='%s' AND active = '1'/etc/postfix/mysql_virtual_mailbox_maps.cf
01.
hosts = localhost 02.
user = postfix 03.
password = mysqlpw 04.
dbname = postfix 05.
query = SELECT maildir FROM mailbox WHERE username='%s' AND active = '1'Konfiguration von Spamassassin
Damit Spam gekennzeichnet wird und anhand dieser Markierung leichter erkannt bzw. aussortiert werden kann.Bitte an dieser Konfiguration nichts ändern wenn ihr nicht 100% wisst was ihr macht!!
/etc/spamassin/local.cf
01.
# 02.
#Allgemeine Konfiguration 03.
# 04.
rewrite_header Subject *****SPAM***** 05.
required_hits 4.8 06.
rewrite_subject 1 07.
subject_tag [SPAM?] 08.
auto_whitelist_factor 0.03 09.
report_safe 1 10.
use_terse_report 1 11.
12.
# 13.
#bayes konfiguration 14.
# 15.
use_bayes 1 16.
bayes_path /etc/spamassassin/bayes 17.
bayes_use_chi2_combining 1 18.
bayes_auto_expire 0 19.
bayes_journal_max_size 15000000 20.
bayes_expiry_max_db_size 20000000 21.
bayes_auto_learn 0 22.
bayes_ignore_header Return-Path 23.
bayes_ignore_header Received 24.
bayes_ignore_header X-Spam-Flag 25.
bayes_ignore_header X-Spam-Status 26.
bayes_ignore_header X-Spam-Flag 27.
bayes_ignore_header X-Spam-Level 28.
bayes_ignore_header X-purgate 29.
bayes_ignore_header X-purgate-ID 30.
bayes_ignore_header X-purgate-Ad 31.
bayes_ignore_header X-GMX-Antispam 32.
bayes_ignore_header X-Resent-For 33.
bayes_ignore_header X-Resent-By 34.
bayes_ignore_header X-Resent-To 35.
bayes_ignore_header Resent-To 36.
bayes_ignore_header Sender 37.
bayes_ignore_header Precedence 38.
bayes_ignore_header X-Antispam 39.
bayes_ignore_header X-Sieve 40.
bayes_ignore_header X-Spamcount 41.
bayes_ignore_header X-Spamsensitivity 42.
bayes_ignore_header To 43.
bayes_ignore_header X-Sieve 44.
bayes_ignore_header X-WEBDE-FORWARD 45.
46.
#dcc konfiguration 47.
dcc_path /usr/local/bin/dccproc 48.
dcc_add_header 1 49.
50.
#pyzor konfiguration 51.
pyzor_path /usr/local/bin/pyzor 52.
pyzor_add_header 1 53.
pyzor_max 3 54.
55.
# Andere Module benutzen 56.
skip_rbl_checks 0 57.
use_razor2 1 58.
use_dcc 1 59.
use_pyzor 1 60.
rbl_timeout 4 61.
ok_languages all 62.
ok_locales all 63.
dns_available yes 64.
check_mx_attempts 0 65.
check_mx_delay 1 66.
auto_learn 1 67.
auto_learn_threshold_spam 5.9 68.
auto_learn_threshold_nonspam 2.0 69.
trusted_networks #mein netzwerk 70.
71.
# Reports 72.
clear_report_template 73.
report Diese Mail wurde von der Installation des SpamAssassin Spam-Filters als 74.
report Spam erkannt. Sollte diese Nachricht zu Unrecht als Spam markiert worden sein, 75.
report dann bitte diese Mail an example@example.com weiterleiten (wenn moeglich 76.
report als Anlage!). Vielen Dank! 77.
report Die Originalnachricht ist dieser E-Mail als Anhang beigefuegt. 78.
report 79.
report Content analysis details: (_HITS_ points, _REQD_ required) 80.
report 81.
report 82.
report " Pkt Regel Name Beschreibung" 83.
report ---- ---------------------- -------------------------------------------------- 84.
report _SUMMARY_ 85.
86.
clear_unsafe_report_template 87.
unsafe_report Diese Nachricht ist nicht komplett in plain text gewesen, so dass es 88.
unsafe_report evtl. gefaehrlich ist, sie zu oeffnen, da die Mail moeglicherweise 89.
unsafe_report einen Virus enthalten koe¶nnte. Wer sie dennoch anschauen moechte, sollte 90.
unsafe_report dafuer besser einen Editor verwenden! 91.
92.
#spamcop punkte 93.
uri SPAMCOP_URI_RBL eval:check_spamcop_uri_rbl('sc.surbl.org','127.0.0.2') 94.
describe SPAMCOP_URI_RBL URI's domain appears in spamcop database at sc.surbl.org 95.
tflags SPAMCOP_URI_RBL net 96.
score SPAMCOP_URI_RBL 5.0 97.
98.
#bayes punkte 99.
score BAYES_00 -6.1 100.
score BAYES_01 -5.0 101.
score BAYES_10 -3.5 102.
score BAYES_20 -2.0 103.
score BAYES_30 -1.0 104.
score BAYES_40 -0.3 105.
score BAYES_44 -0.01 106.
score BAYES_50 0.01 107.
score BAYES_56 0.3 108.
score BAYES_60 1.0 109.
score BAYES_70 1.6 110.
score BAYES_80 3.1 111.
score BAYES_90 5.2 112.
score BAYES_99 7.2 113.
114.
#razor punkte 115.
score RAZOR2_CHECK 1.8 116.
score RAZOR2_CF_RANGE_11_50 0.32 117.
score RAZOR2_CF_RANGE_51_100 2.7 118.
119.
#dcc punkte 120.
score DCC_CHECK 4.9 121.
122.
#pyzor punkte 123.
score PYZOR_CHECK 4.8 124.
125.
score SUBJ_ILLEGAL_CHARS 2.6 126.
score PORN_4 3.7 127.
score RCVD_IN_RFCI 2.0 128.
score RCVD_IN_ORBS 1.0 129.
score RCVD_IN_DSBL 1.0 130.
score RCVD_IN_SBL 0.5 131.
score RCVD_IN_VISI 1.0 132.
score RCVD_IN_RFCI 0.5 133.
score RCVD_IN_SORBS 0.5 134.
score X_NJABL_OPEN_PROXY 0.5 135.
score RCVD_IN_UNCONFIRMED_DSBL 0.2 136.
score RCVD_IN_BL_SPAMCOP_NET 1.1 137.
score RCVD_IN_VISI 0.3 138.
score RCVD_IN_RELAYS_ORDB_ORG 0.3 139.
score USER_AGENT_MACOE 1.0 140.
score NIGERIAN_TRANSACTION_1 1.5 141.
score MICROSOFT_EXECUTABLE 3.100 142.
score MIME_SUSPECT_NAME 3.100 143.
score RCVD_IN_BONDEDSENDER -6.0 144.
score HABEAS_HIL_RBL -6.0 145.
score X_LIST_UNSUBSCRIBE 0.5 146.
score EMAIL_ATTRIBUTION -0.5 147.
score IN_REP_TO -0.5 148.
score QUOTED_EMAIL_TEXT -0.5 149.
score REPLY_WITH_QUOTES -0.5 150.
score HTML_IMAGE_ONLY_02 1.978 151.
score HTML_IMAGE_ONLY_04 2.087 152.
score HTML_IMAGE_ONLY_06 1.228 153.
score HTML_IMAGE_ONLY_08 0.984 154.
score HTML_IMAGE_ONLY_10 0.843 155.
score HTML_IMAGE_ONLY_12 0.487 156.
score EMAIL_ATTRIBUTION -1 157.
score MSGID_GOOD_EXCHANGE -1 158.
159.
ifplugin Mail::SpamAssassin::Plugin::Shortcircuit 160.
endif # Mail::SpamAssassin::Plugin::Shortcircuit 161.
162.
#EOFKonfiguration der SSL Zertifikate
Zur Erstellunge des Benötigten SSL Zertifikates wechseln wir in den Ordner /etc/postfix/sslcert/
Und geben dort folgenden Befehl ein:
01.
openssl req -new -nodes -keyout olympia.key -out olympia.csr -newkey rsa:4096Konfiguration von Fetchmail
Um E-Mails von anderen anbietern abholen zu können müssen wir noch Fetchmail konfigurierenDas Fetchmail Script wirt minütlich mit dem user Vmail über die /etc/crontab ausgeführt.
/etc/home/mail/fetchmail.pl
01.
#!/usr/bin/perl 02.
###### 03.
# 04.
# MySQL to Fetchmail, Frontend: Roundcube Plugin (RC0.4 and above) 05.
# Developped by Arthur Mayer, a.mayer@citex.net 06.
# Released under GPL license (http://www.gnu.org/licenses/gpl.txt) 07.
# 08.
###### 09.
10.
use DBI; 11.
12.
$db_database="webmail"; 13.
$db_username="webmail"; 14.
$db_password="webmail"; 15.
16.
$text='#temp fetchmailrc 17.
set no syslog 18.
set postmaster "postmaster" 19.
set no bouncemail 20.
set properties "" 21.
'; 22.
23.
$dbh = DBI->connect("DBI:mysql:$db_database;host=IP_ADRESSE0", $db_username, $db_password) or die "Database connection error: $DBI::errstr\n"; 24.
25.
$sth = $dbh->prepare("SELECT mailget_id,userhere,remoteserver,remoteuser,remotepass,type,options,active FROM virtual_fetchmail WHERE active='1' ORDER BY remoteserver ASC"); 26.
$sth->execute; 27.
while(my ($mailget_id,$userhere,$remoteserver,$remoteuser,$remotepass,$type,$options,$active) = $sth->fetchrow_array()) { 28.
$text.="\npoll $remoteserver with proto $type\n"; 29.
if ( $options eq '0' ) { $keep='keep'; } else { $keep=''; } 30.
$text.="\tuser \"$remoteuser\" there with password \"$remotepass\" is \"$userhere\" here $keep\n"; 31.
} 32.
33.
$dbh->disconnect(); 34.
35.
#print $text; 36.
37.
open(DA, ">/home/mail/fetchmail/fetchmailrc") or die "Can't Open File. Try chmod 777"; 38.
print DA $text; 39.
close(DA); 40.
41.
$chown=`chown -R vmail:vmail /home/mail/fetchmail/fetchmailrc`; 42.
$chmod=`chmod -R 600 /home/mail/fetchmail/fetchmailrc`; 43.
$ret=`/usr/bin/fetchmail -f /home/mail/fetchmail/fetchmailrc -i /home/mail/fetchmail/fetchmailid --pidfile /home/mail/fetchmail/fetchmail.pid -L /var/log/fetchmail`; 44.
45.
unlink "/var/mail/fetchmail/fetchmailrc";Konfiguration von Iptables
Als Firewall System benützen wir IPTables da es in Linux ab Kernel 2.6 sowieso integriert istZum starten benutzen wir das Script
/etc/init.d/iptables.sh
01.
#!/bin/bash 02.
### BEGIN INIT INFO 03.
# Provides: Iptables 04.
# Required-Start: 05.
# Required-Stop: 06.
# Default-Start: 2 07.
# Default-Stop: 0 1 6 08.
# Short-Description: Startet Iptables 09.
# Description: Startet das Iptables Firewalling System 10.
### END INIT INFO 11.
#Beginn der Definitionen 12.
13.
#Beginn der Definitionen 14.
15.
IPTABLES="/sbin/iptables" #Pfad zu den Iptables 16.
DEV="eth0" #Netzwerkkarte 17.
18.
#################################### 19.
## 20.
## Server 21.
## 22.
#################################### 23.
24.
ADMINIP=IP Adresse der Firewall von DD Administration 25.
NS1=Erster NS 26.
NS2=Zweiter NS 27.
NAGIOS=Netzwerküberwachung 28.
GALACTICA=WEB Server 29.
CONTROL=Postfixadmin Server 30.
31.
################################### 32.
## 33.
## Ports 34.
## 35.
################################### 36.
37.
SSH="22" #SSH Port 38.
DNS="53" #DNS Port 39.
NRPE="5666" #Netzwerküberwachung 40.
SMTP="25" #SMTP 41.
POP="995" #POP3 42.
IMAP="993" #IMAP 43.
SIEVE="2000" #Sieve 44.
MYSQL="3306" #MySQL 45.
46.
################################### 47.
## 48.
## Module 49.
## 50.
################################### 51.
52.
modprobe ip_conntrack_ftp #Modul für den Status einer FTP verbindung 53.
54.
#################################### 55.
## 56.
## Leere die Ketten 57.
## 58.
#################################### 59.
60.
$IPTABLES -F 61.
62.
#################################### 63.
## 64.
## Sperre Jeden Input 65.
## 66.
#################################### 67.
68.
$IPTABLES -P INPUT DROP 69.
$IPTABLES -P OUTPUT DROP 70.
$IPTABLES -P FORWARD DROP 71.
72.
#################################### 73.
## 74.
## Beginn der Regeln Für die Verwaltung 75.
## 76.
#################################### 77.
78.
#Erlaube nur DD und Backup-Nas Zugriff via SSH 79.
$IPTABLES -A INPUT -i $DEV -p tcp --dport $SSH -s $ADMINIP -j ACCEPT 80.
81.
#Erlaube Nagios Zugriff auf den NRPE Client 82.
$IPTABLES -A INPUT -i $DEV -p tcp --dport $NRPE -s $NAGIOS -j ACCEPT 83.
84.
#Erlaube PING von Nagios zur Überwachung und von DD zur Diagnose 85.
$IPTABLES -A INPUT -p icmp --icmp-type ping -s $NAGIOS -j ACCEPT 86.
$IPTABLES -A INPUT -p icmp --icmp-type ping -s $ADMINIP -j ACCEPT 87.
88.
##################################### 89.
## 90.
## Beginn der Allgemeinen Regeln 91.
## 92.
##################################### 93.
## 94.
## INPUT 95.
## 96.
97.
#Erlaube Bereits aufgebaute Verbindungen 98.
iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT 99.
100.
#Erlaube HTTP von überall 101.
$IPTABLES -A INPUT -i $DEV -p tcp --dport $SMTP -m state --state NEW -j ACCEPT 102.
$IPTABLES -A INPUT -i $DEV -p tcp --dport $IMAP -m state --state NEW -j ACCEPT 103.
$IPTABLES -A INPUT -i $DEV -p tcp --dport $POP -m state --state NEW -j ACCEPT 104.
105.
#Öffne DNS Abfragen 106.
$IPTABLES -A INPUT -i $DEV -p tcp -s $NS1 --sport $DNS -m state --state NEW -j ACCEPT 107.
$IPTABLES -A INPUT -i $DEV -p udp -s $NS1 --sport $DNS -m state --state NEW -j ACCEPT 108.
$IPTABLES -A INPUT -i $DEV -p tcp -s $NS2 --sport $DNS -m state --state NEW -j ACCEPT 109.
$IPTABLES -A INPUT -i $DEV -p udp -s $NS2 --sport $DNS -m state --state NEW -j ACCEPT 110.
111.
## 112.
## OUTPUT 113.
## 114.
#Erlaube Antworten auf angenommene Verbindungen 115.
$IPTABLES -A OUTPUT -m state --state ESTABLISHED,RELATED -j ACCEPT 116.
117.
$IPTABLES -A OUTPUT -p tcp --dport $SMTP -m state --state NEW -j ACCEPT 118.
$IPTABLES -A OUTPUT -p tcp --dport $IMAP -m state --state NEW -j ACCEPT 119.
$IPTABLES -A OUTPUT -p tcp --dport $POP -m state --state NEW -j ACCEPT 120.
121.
#Öffne Web Server Control und Localhost 122.
$IPTABLES -A OUTPUT -d 127.0.0.1 -j ACCEPT 123.
$IPTABLES -A INPUT -s 127.0.0.1 -j ACCEPT 124.
$IPTABLES -A INPUT -s 195.130.198.90 -j ACCEPT 125.
$IPTABLES -A INPUT -s 195.130.198.180 -j ACCEPT 126.
127.
#Öffne DNS Abfragen 128.
$IPTABLES -A OUTPUT -p tcp -d $NS1 --dport $DNS -m state --state NEW -j ACCEPT 129.
$IPTABLES -A OUTPUT -p udp -d $NS1 --dport $DNS -m state --state NEW -j ACCEPT 130.
$IPTABLES -A OUTPUT -p tcp -d $NS2 --dport $DNS -m state --state NEW -j ACCEPT 131.
$IPTABLES -A OUTPUT -p udp -d $NS2 --dport $DNS -m state --state NEW -j ACCEPT 132.
133.
#EOFDies verlinken wir bei Debian noch in das zweite Runlevel mit dem Befehl
01.
ln -s /etc/init.d/iptables.sh /etc/rc2.dS05iptables.shNatürlich müssen wir es auch wider stoppen können hierzu verwenden wir folgendes Script
01.
#!/bin/bash 02.
### BEGIN INIT INFO 03.
# Provides: IPTABLES 04.
# Required-Start: $local_fs $syslog mdadm-raid 05.
# Required-Stop: $local_fs $syslog mdadm-raid 06.
# Default-Start: 2 3 4 5 07.
# Default-Stop: 0 1 6 08.
# Short-Description: IPTABLES STOP 09.
# Description: Stoppt das Firewalling System 10.
### END INIT INFO 11.
#Beginn der Definitionen 12.
13.
IPTABLES="/sbin/iptables" 14.
15.
#################################### 16.
## 17.
## Leere die Ketten 18.
## 19.
#################################### 20.
21.
$IPTABLES -F 22.
23.
24.
#################################### 25.
## 26.
## Erlaube Alles 27.
## 28.
#################################### 29.
$IPTABLES -P INPUT ACCEPT 30.
$IPTABLES -P OUTPUT ACCEPT 31.
$IPTABLES -P FORWARD ACCEPT 32.
#EOFDiverse Scripte
Quota Warning
Natürlich wollen wir unsere Kunde/User darüber informieren wenn der Mailspace kurz vor dem Ende ist.Ich benutze dazu folgendes Script
/usr/local/sbin/quota-warning.sh
01.
#!/bin/sh 02.
03.
PERCENT=$1 04.
FROM="example@example.com" 05.
06.
msg="From: $FROM 07.
To: $USER 08.
To: support@delta.co.at 09.
Subject: Your email quota is $PERCENT% full 10.
Content-Type: text/plain; charset=UTF-8 11.
12.
Your mailbox is now $PERCENT% full." 13.
14.
echo -e "$msg" | /usr/sbin/sendmail -f $FROM "$USER" 15.
16.
exit 0Benachrichtigung über abgelehnte E-Mails
Nachdem sich einige User über abgelehnte Mails beschwert haben habe ich folgendes Script entworfen damit sie selbst einen Überblich haben welche Mails abgelehnt werden01.
#!/bin/sh 02.
03.
MAILLOG='/var/log/mail.log' 04.
MAILSOURCEPATH='/home/mail/' 05.
TMPFILEDESTPATH='/usr/local/sbin/checkSPAMtmp' 06.
CHECKSPAMLIST='/usr/local/sbin/checkSPAM.list' 07.
WORKDATE=`date +%d.%m.%Y` 08.
09.
### Alte Auswertungen löschen 10.
11.
rm $TMPFILEDESTPATH/* 12.
13.
### aktuelles Datum für Suche definieren 14.
15.
TODAY_DAY=`date +%d` 16.
TODAY_MONTH=`date +%b` 17.
18.
if [ $TODAY_MONTH = "Mrz" ]; then 19.
TODAY_MONTH='Mar' 20.
elif [ $TODAY_MONTH = "Mai" ]; then 21.
TODAY_MONTH='May' 22.
elif [ $TODAY_MONTH = "Okt" ]; then 23.
TODAY_MONTH='Oct' 24.
elif [ $TODAY_MONTH = "Dez" ]; then 25.
TODAY_MONTH='Dec' 26.
fi 27.
28.
if [ $TODAY_DAY -le 10 ]; then 29.
30.
TODAY_DAY=`echo $TODAY_DAY | sed -e 's/^0/.*/'` 31.
TODAY="$TODAY_MONTH$TODAY_DAY" 32.
else 33.
TODAY="$TODAY_MONTH $TODAY_DAY" 34.
fi 35.
36.
TODAY='^'$TODAY 37.
38.
### Vordefinierte Liste abarbeiten und nach Abgelehnten Emails suchen 39.
40.
for EMAIL in $(cat $CHECKSPAMLIST) 41.
do 42.
grep -i "$TODAY.*reject:.*to=<$EMAIL>" $MAILLOG >> $TMPFILEDESTPATH/$EMAIL 43.
echo "### $EMAIL " 44.
45.
if [ -f $TMPFILEDESTPATH/$EMAIL ]; then 46.
47.
FILESIZE=`wc -c $TMPFILEDESTPATH/$EMAIL` 48.
FILESIZE=`echo $FILESIZE | sed -n -e 's/ .*$/''/gp'` 49.
echo $FILESIZE 50.
51.
if [ $FILESIZE -ge 1 ]; then 52.
53.
for SPAMINFO in $(cat $TMPFILEDESTPATH/$EMAIL) 54.
do 55.
SENDFROM=`echo $SPAMINFO | sed -n -e 's/^.*from=</''/gp'` 56.
SENDFROM=`echo $SENDFROM | sed -n -e 's/>.*$/''/gp'` 57.
58.
if ! [ -z $SENDFROM ]; then 59.
echo "$SENDFROM" >> $TMPFILEDESTPATH/$EMAIL.txt 60.
fi 61.
done 62.
63.
ATTACHEMENT="$TMPFILEDESTPATH/$EMAIL.txt" 64.
65.
### Email an Kunden versenden 66.
67.
mail -s "SPAM Info $WORKDATE" -a $ATTACHEMENT $EMAIL < /usr/local/sbin/checkSPAM.txt 68.
fi 69.
fi 70.
done 71.
Postfixadmin/Roundcube
Die Anleitungen für Postfixadmin und Roundcube folgen in den nächsten Tagen. Es ist aber auch kein großer Aufwand die zu konfigurieren
Für eventuelle Anregungen und Ideen um diese Konfig zu ergänzen bin ich offen oder auch für jede Kritik
LG
HItman





