17. Filtering Spam
I use spamassassin to tag spam for mail send to my personal mail account. My spamassassin configuration file /etc/mail/spamassassin/local.cf contains the following lines:
report_header 1
rewrite_subject 0
defang_mime 0
Besides the lines above, I have added some personal rules to the file /etc/mail/spamassassin/local.cf . These rules are outside the scope of this document.
I have created a file /etc/mail/spamassassin/whitelist.cf containing the e-mail addresses of my contacts in lines like:
whitelist_from user@domain
I have created a file /etc/mail/spamassassin/blacklist.cf containing the e-mail addresses of people from who I do not want to receive e-mail in lines like:
blacklist_from user@domain
I have written a procmail script which moves spam to a seperate mailbox ~/mail/Spam. The suspected spammer will receive a mail that his e-mail has been deleted. In this mail he is informed that he can bypass the spam filter by starting the subject field with the keyword NOSPAM. Real spammers do not read bounced messages. But legitimate senders whose mail is accidentally tagged as spam will do.
The procmail script is self documenting. It is available at You are not allowed to view links.
Register or
Login. Beware DOS to Unix text file conversion (CR-LF to LF) when downloading it. Copy it to /usr/local/bin/spamfilter. The file must be executable for everybody. This can be done with the command:
chmod 755 /usr/local/bin/spamfilter
To have all my e-mail filtered, I have created a /home/fwiarda/.forward containing the following line:
"|/usr/local/bin/spamfilter email=fwiarda@fwiarda.com"
Note that sendmail requires the /home/fwiarda/.forward file to be owned by fwiarda and not being world readable. When the file has been created by root, the following commands fix this:
chmod 644 /home/fwiarda/.forward
chown fwiarda /home/fwiarda/.forward
chgrp fwiarda /home/fwiarda/.forward
18. Auto-Replying to E-Mail
Red Hat Linux 8.0 does not come with a vacation program, to auto-reply to your mail. I have written a perl script myself, which mimics the Unix vacation program.
In most aspects this script is stripped down in functionality compared to the Unix vacation program. However, with the handling of .forward files it is more advanced. If a .forward file already exists and contains forwards to something else then vacation, it adds a line to the original .forward file instead of overwriting it. Later, when vacation is disabled, this line is deleted again. This behaviour leaves other forwards intact.
The script is self documenting. It is available at You are not allowed to view links.
Register or
Login. Beware DOS to Unix text file conversion (CR-LF to LF) when downloading it. Copy it to /usr/local/bin/vacation. The file must be executable for everybody. This can be done with the command:
chmod 755 /usr/local/bin/vacation
19. Web Server
By default the Apache web server is disabled at Red Hat Linux 8.0. To enable it the following commands must be executed:
mv /etc/rc.d/rc1.d/K15httpd /etc/rc.d/rc1.d/K86httpd
mv /etc/rc.d/rc2.d/K15httpd /etc/rc.d/rc2.d/S86httpd
mv /etc/rc.d/rc3.d/K15httpd /etc/rc.d/rc3.d/S86httpd
mv /etc/rc.d/rc4.d/K15httpd /etc/rc.d/rc4.d/S86httpd
mv /etc/rc.d/rc5.d/K15httpd /etc/rc.d/rc5.d/S86httpd
mv /etc/rc.d/rc6.d/K15httpd /etc/rc.d/rc6.d/K86httpd
The renaming of these files makes that the Apache web server is started during system boot. Note that we also rename the files from *15* into *86* This ensures the Apache web server is started after the name server has been started. In that case it is not able to resolve the host names used in it's configuration file.
The following lines must be added to or changed in the main server configuration section of /etc/httpd/conf/httpd.conf:
# Set my e-mail address as the server administrators e-mail.
ServerAdmin "
fwiarda@fwiarda.com"
# Set the name of the server.
ServerName "server.fwiarda.com"
# Each directory to which Apache has access can be configured with respect
# to which services and features are allowed and/or disabled in that
# directory (and its subdirectories).
#
# We configure the default to be a very relaxed set of features,
# so we do not have to switch them on seperately for each virtual
# server.
<Directory "/">
Options All
AllowOverride All
Order allow,deny
Allow from all
</Directory>
# We set the documents defining a directory index.
DirectoryIndex "index.htm" "index.html" "index.txt" "index.cgi" "index.php"
# The default is to present a test page if there is no index file in
# the document root directory. We like Apache to display the directory
# contents instead, by commenting the corresponding directives out.
#<LocationMatch "^/$>
# Options -Indexes
# ErrorDocument 403 /error/noindex.html
#</LocationMatch>
# We define the format of directory listings.
IndexOptions FancyIndexing NameWidth=* FoldersFirst SuppressDescription
# We disable headers and readme files in directory listings by commenting
# the corresponding directives out.
#ReadmeName README.html
#HeaderName HEADER.html
# All files ending with .cgi are scripts, even if they are not placed
# in a special directory for cgi-scripts.
AddHandler cgi-script .cgi
# We set .htaccess to be the file from which access permission can be
# overriden.
AccessFileName ".htaccess"
# We do not want .htaccess, .htpasswd and .htgroup files to be displayed.
<Files ~ "^\.ht">
Order allow,deny
Deny from all
</Files>
# We lookup the hostnames for the IP addresses to which
# we provide pages. This makes our log files more readable.
HostnameLookups On
# We set the error log file.
ErrorLog "/var/log/httpd/error_log"
# We set the access log file.
CustomLog "/var/log/httpd/access_log" combined
# We don't want to have the server name below directory indexes generated
# by Apache.
ServerSignature Off
# Disable You are not allowed to view links.
Register or
Login to be the Apache
# manual, by commenting the corresponding directives out.
#Alias /manual "/var/www/manual"
#
#<Directory "/var/www/manual">
# Options Indexes FollowSymLinks MultiViews
# AllowOverride None
# Order allow,deny
# Allow from all
#</Directory>
# Disable You are not allowed to view links.
Register or
Login to be a server # wide script directory. #ScriptAlias /cgi-bin/ "/var/www/cgi-bin/"
These settings are valid for all virtual hosts. The following lines have been added to or changed in the virtual host section of /etc/httpd/conf/httpd.conf:
# We define we are going to use name based virtual hosting.
NameVirtualHost "10.0.0.254"
# This entry is the default entry. It is used when the hostname in the
# URL is not known to us. Hackers just trying our IP address end-up here.
# We will always return an empty page with mime-type text/plain. All
# settings for this entry are taken form the main server configuration
# section above.
<VirtualHost "10.0.0.254">
<Directory "/dev">
ForceType text/plain
</Directory>
AliasMatch .* "/dev/null"
</VirtualHost>
# The entry for calls to You are not allowed to view links.
Register or
Login . It accesses
# SquirrelMail, a web based mail client which is part of the Red Hat
# Linux 8.0 distribution. Since it is a web site on it's own,
# it has it's own error log and access log files.
<VirtualHost "10.0.0.254">
ServerName "mail.fwiarda.com"
DocumentRoot "/usr/share/squirrelmail"
ErrorLog "/var/log/httpd/mail.fwiarda.com.error_log"
CustomLog "/var/log/httpd/mail.fwiarda.com.access_log" combined
</VirtualHost>
# The entry for calls to You are not allowed to view links.
Register or
Login .
# It has it's own error log and access log files.
<VirtualHost "10.0.0.254">
ServerName "server.fwiarda.com"
DocumentRoot "/home/server/www"
ErrorLog "/var/log/httpd/server.fwiarda.com.error_log"
CustomLog "/var/log/httpd/server.fwiarda.com.access_log" combined
</VirtualHost>
# The entry for calls to my personal web site
# You are not allowed to view links.
Register or
Login . It has it's own document root, and it's
# own, error log and access log files.
<VirtualHost "10.0.0.254">
ServerName "You are not allowed to view links.
Register or
Loginwww.fwiarda.com
"
ServerAlias "You are not allowed to view links.
Register or
Loginwww.fwiarda.com
"
DocumentRoot "/home/fwiarda/www"
ErrorLog "/var/log/httpd/www.fwiarda.com.error_log"
CustomLog "/var/log/httpd/www.fwiarda.com.access_log" combined
</VirtualHost>
Since we have defined You are not allowed to view links.
Register or
Login to access SquirrelMail, I considered it not necessary that You are not allowed to view links.
Register or
Login accesses SquirrelMail as well. The /etc/httpd/conf.d/squirrelmail.conf has been edited to delete the line:
Alias /webmail /usr/share/squirrelmail
The document root directory, the directory containing the log files, and all the directories above them, must be searchable and readable for the user apache. To be able to test this, it practical to login as user apache. However, by default no login shell is assigned to the user apache. We fix this editing the file /etc/passwd and changing the line:
apache:x:48:48:Apache:/var/www:/sbin/nologin
into:
apache:x:48:48:Apache:/var/www:/bin/bash
When logged-in as root, we can now log-in as apache by issuing the following command:
su - apache
If there is any flaw in file access permission settings, they will become clearly noticeable.
The web site You are not allowed to view links.
Register or
Login is used for accessing the access and error logs, and the usage statistics of my server. The directory /home/server/www is the document root for this web site. It must be created, as well as sub-directories for usage statistics and a link to the directory containing the servers log files:
mkdir /home/server/www
mkdir /home/server/www/usage
mkdir /home/server/www/usage/mail.fwiarda.com
mkdir /home/server/www/usage/server.fwiarda.com
ln -s /var/log/httpd /home/server/www/log
chmod 755 /var/log/httpd
I do not want everybody to have access to my logs and usage statistics. Therefore a file /home/server/www/.htaccess is created, containing the following lines:
AuthUserFile /home/server/www/.htpasswd
AuthName "Server Administrator"
AuthType Basic
<Limit GET POST>
require valid-user
</Limit>
A file /home/server/www/.htpasswd is created by issuing the following commands:
htpasswd /home/server/www/.htpasswd root
htpasswd /home/server/www/.htpasswd fwiarda
The htpasswd program prompts for the appropriate passwords.
The ownership of the /home/server/www tree shall belong to the user server. If this directory tree has been created while being logged-in as root, the ownership must be transferred with the following command:
chown -R server:server /home/server/www
For more information about the Apache web server see "Apache; The Definitive Guide" ([4]).
20. Web Usage Statistics
Webalizer is a tool for generating usage statistics for web pages.
The file /etc/webalizer.conf is edited, to ensure the following parameters are defined or commented out:
# We will specify the log file at the command line.
# The entry LogFile is commented out.
#LogFile /var/log/httpd/access_log
# We will specify the output directory at the command line.
# The entry OutputDir is commented out.
#OutputDir .
# The file webalizer.hist in the output directory will
# contain the data for previous months.
HistoryName webalizer.hist
# We only process entries not yet processed before. We
# retrieve the old usage information form the files
# webalizer.hist and webalizer.current
Incremental yes
# The file webalizer.current in the output directory will
# contain the data for the current month.
IncrementalName webalizer.current
# For debugging purposes we enable log messages. When
# webalizer is called from a script, we suppres all messages
# by adding the -Q option at the command line.
Quiet no
A file /etc/cron.daily/webalizer is created. This file is executed daily since it resides in the /etc/cron.daily directory. It must contain the following lines:
#!/bin/bash
if [ -s /var/log/httpd/server.fwiarda.com.access_log ] ; then
/usr/bin/webalizer -Q \
-n server.fwiarda.com \
-r server.fwiarda.com \
-o /home/server/www/usage/server.fwiarda.com \
/var/log/httpd/server.fwiarda.com.access_log
fi
if [ -s /var/log/httpd/mail.fwiarda.com.access_log ] ; then
/usr/bin/webalizer -Q \
-n mail.fwiarda.com \
-r mail.fwiarda.com \
-o /home/server/www/usage/mail.fwiarda.com \
/var/log/httpd/mail.fwiarda.com.access_log
fi
if [ -s /var/log/httpd/www.fwiarda.com.access_log ] ; then
/usr/bin/webalizer -Q \
-n You are not allowed to view links.
Register or
Loginwww.fwiarda.com
\
-r You are not allowed to view links.
Register or
Loginwww.fwiarda.com
\
-r fwiarda.com \
-o /home/server/www/usage/www.fwiarda.com \
/var/log/httpd/www.fwiarda.com.access_log
fi
exit 0
After editing this file must be made executable with the command:
chmod 755 /etc/cron.daily/webalizer
21. Samba
By default samba is disabled at Red Hat Linux 8.0. To enable it the following commands must be executed:
mv /etc/rc.d/rc2.d/K35smb /etc/rc.d/rc2.d/S35smb
mv /etc/rc.d/rc3.d/K35smb /etc/rc.d/rc3.d/S35smb
mv /etc/rc.d/rc4.d/K35smb /etc/rc.d/rc4.d/S35smb
mv /etc/rc.d/rc5.d/K35smb /etc/rc.d/rc5.d/S35smb
The file /etc/samba/smb.conf is edited and shall contain the following lines:
[global]
workgroup = fwiarda-group
netbios name = fwiarda-server
server string = Frits Wiarda's Server
encrypt passwords = yes
security = user
time service = yes
[fwiarda]
path = /home/fwiarda
comment = /home/fwiarda
read only = no
guest ok = no
create mask = 644
force create mode = 644
directory mask = 755
force directory mode = 755
Samba uses the passwords from file /etc/smbpasswd instead of /etc/passwd or /etc/shadow. That means separate passwords for samba must be created. This is done with the following comand:
smbpasswd -a fwiarda
The smbpasswd program prompts for the appropriate password.
For more information on samba see "Using Samba" ([5]).
22. Disabling Start-Up of Unused Services
Linux knows different run levels:
Run level 0. Halt the system;
Run level 1. Single user mode;
Run level 2. Multi user mode without NFS;
Run level 3. Multi user mode with NFS;
Run level 4. Unused;
Run level 5. X11 graphical user interface;
Run level 6 . Reboot the system.
When the system boots, it reads from the file /etc/inittab to which run level it should switch. It will then run the startup scripts for this run level (see /etc/rc.d/rc?.d).
We will use the unused run level 4. To have the system boot in run level 4, we edit /etc/inittab changing the initdefault line into:
id:4:initdefault:
With the following rename we make that only the services we need are started:
mv /etc/rc.d/rc4.d/S05kudzu /etc/rc.d/rc4.d/K05kudzu
mv /etc/rc.d/rc4.d/S08ip6tables /etc/rc.d/rc4.d/K08ip6tables
mv /etc/rc.d/rc4.d/S08ipchains /etc/rc.d/rc4.d/K08ipchains
mv /etc/rc.d/rc4.d/S08iptables /etc/rc.d/rc4.d/K08iptables
mv /etc/rc.d/rc4.d/S09isdn /etc/rc.d/rc4.d/K09isdn
mv /etc/rc.d/rc4.d/S13portmap /etc/rc.d/rc4.d/K13portmap
mv /etc/rc.d/rc4.d/S14nfslock /etc/rc.d/rc4.d/K14nfslock
mv /etc/rc.d/rc4.d/S17keytable /etc/rc.d/rc4.d/K17keytable
mv /etc/rc.d/rc4.d/S24pcmcia /etc/rc.d/rc4.d/K24pcmcia
mv /etc/rc.d/rc4.d/S25netfs /etc/rc.d/rc4.d/K25netfs
mv /etc/rc.d/rc4.d/S26apmd /etc/rc.d/rc4.d/K26apmd
mv /etc/rc.d/rc4.d/S28autofs /etc/rc.d/rc4.d/K28autofs
mv /etc/rc.d/rc4.d/S56rawdevices /etc/rc.d/rc4.d/K56rawdevices
mv /etc/rc.d/rc4.d/S84privoxy /etc/rc.d/rc4.d/K84privxy
mv /etc/rc.d/rc4.d/S85gpm /etc/rc.d/rc4.d/K85gpm
mv /etc/rc.d/rc4.d/S90canna /etc/rc.d/rc4.d/K90canna
mv /etc/rc.d/rc4.d/S90xfs /etc/rc.d/rc4.d/K90xfs
mv /etc/rc.d/rc4.d/S95anacron /etc/rc.d/rc4.d/K95anacron
mv /etc/rc.d/rc4.d/S95atd /etc/rc.d/rc4.d/K95atd
mv /etc/rc.d/rc4.d/S97rhnsd /etc/rc.d/rc4.d/K97rhnsd
mv /etc/rc.d/rc4.d/S98wine /etc/rc.d/rc4.d/K98wine
mv /etc/rc.d/rc4.d/S99mdmonitor /etc/rc.d/rc4.d/K99mdmonitor
The command ls /etc/rc.d/rc4.d/S* will list all the services that will be started at run level 4:
S00microcode_ctl
S10network
S12syslog
S20random
S35smb
S45named
S55sshd
S56xinetd
S60lpd
S80sendmail
S86httpd
S90crond
S99local
23. NAT Settings ADSL Modem
To be able to reach my server from the internet, the some NAT settings must me made in the ADSL modem.
The easiest option is to set the default address to which IP packages from the internet must be routed to the servers internal IP address 10.0.0.254. Now all IP packages from the internet are send to the server.
The best option is to list explicitly for which TCP and UDP ports IP packages must be routed to the servers internal IP address 10.0.0.254. Other IP packages can be discarded, making life for hackers more difficult. The ports which must be opened are:
TCP port 21 for FTP;
TCP port 22 for secure telnet (SSH);
TCP port 23 for telnet;
TCP port 25 for SMTP;
Both UDP and TCP port 53 for DNS;
TCP port 80 for HTTP;
TCP port 110 for POP3;
TCP port 143 for IMAP.
Glossary and Abbreviations
BOOTP BOOTstrap Protocol.
DHCP Dynamic Host Configuration Protocol.
DNS Domain Name System.
FTP File Transfer Protocol.
HTML HyperText Mark-up Language.
HTTP HyperText Transfer Protocol.
IMAP Internet Mail Access Protocol.
IP Internet Protocol.
LPD Line Printer Daemon.
POP3 Post Office Protocol version 3.
NAT Network Address Translation.
RFC Request For Comment.
SMTP Simple Mail Transfer Protocol.