|
|
发表于 2004-2-20 11:28:09
|
显示全部楼层
I wrote it almost two years ago, but it should still be useful, especially the part to create sendmail.cf from the .mc file.
Terminator
May 18, 2001
I guess a lot of people might be interested in building their own internet
domain free of charge. Well, it's possible if we do not mention something, such
as power supplier... 
First of all, you need these things:
. A PC, at least 486, with at least 32M memory and 1G harddisk.
. Linux, FreeBSD or other free UNIX-like operating system installed on
your PC.
. A cable to connect to the Internet all day and night.
. Stable power supplier which enables your PC run 24x7 hours.
Well, now you are almost ready to create and administrate of your own
internet domain. Feel excited? But wait, it's not so simple to be an
administrator. You might meet all kinds of problems you have not expected. So
please remember, passion, initiative and curiosity are always your friends to
reach the finally success.
Now you can apply for an free domain somewhere, such as www.dhs.org. You
should at least get two static host name with a static domain. Let's assume
they are:
. host1.dhs.org, ip 192.9.200.1, MX mail.domain.dhs.org
. host2.dhs.org, ip 192.9.200.2, MX mail.domain.dhs.org
. domain.dhs.org, dns server 1, ns.domain.dhs.org, ip 192.9.200.1
dns server 2, ns1.domain.dhs.org, ip 192.9.200.2
Set the MX record of host1 and host2 so that they point to the mail server
in your domain, say mail.domain.dhs.org. But wait, you might think where's the
host mail.domain.dhs.org? Actually, they are host1 or host2. I will show you
how to do it.
Now, go to get Internet domain server package Bind. Build and install
it on your system. In your Bind database, add the following records:
domain.dhs.org. IN NS ns.domain.dhs.org.
ns.domain.dhs.org. IN A 192.9.200.1
mail.domain.dhs.org. IN A 192.9.200.1
www.domain.dhs.org. IN A 192.9.200.1
ns1.domain.dhs.org. IN A 192.9.200.2
mail1.domain.dhs.org. IN A 192.9.200.2
www1.domain.dhs.org. IN A 192.9.200.2
domain.dhs.org. IN MX 10 mail.domain.dhs.org.
IN MX 20 mail1.domain.dhs.org.
*.domain.dhs.org. IN MX 10 mail.domain.dhs.org.
IN MX 20 mail1.domain.dhs.org.
OK, at the next 6am, you domain will be ready since all the changes made
at www.dhs.org will be refreshed at 6am each day. You can ping your hosts via
its new DNS name.
You don't have to have two computers with two IPs, actually just have
192.9.200.1 online is fine. However, you can let your PC have two IPs if your
system support IP aliases. After you enable IP aliases, remember to add these
lines in your /etc/hosts:
192.9.200.1 host1.dhs.org host1
192.9.200.2 host2.dhs.org host2 # not necessary if without IP aliases
*******************************************************************************
Next is to make your web server ready. It's quite easy. Just get Apache,
build and install it. Apache support virtual domain, which means you can provide
different web contents from different directories by just running one Apache
server. For example:
http://www.domain.dhs.org/ -> apache_root_dir/www1/
http://www1.domain.dhs.org/ -> apache_root_dir/www2/
*******************************************************************************
Finally, you want to receive e-mail via your@domain.dhs.org, don't you? It's
also strightforward if you knows how to configure sendmail. But since it's said
that sendmail is the last nightmare to system administrators, I will give you
some hints here to make it a little bit easier. 
Ok, let's first download the latest version of sendmail from www.sendmail.
org, compile and install it on your PC.
According to the configuration of your domain, the Sendmail should be able
to receive mail to these address:
. myaccount@mail.domain.dhs.org
. myaccount@host1.dhs.org
. myaccount@host2.dhs.org
. myaccount@www.domain.dhs.org
Luckily, Sendmail already has this feature. You can set the hostdomain name
in file /etc/mail/local-host-name, one name per line, just as:
domain.dhs.org
host1.dhs.org
host2.dhs.org
mail.domain.dhs.org
And don't forget to add these host/domain name into file /etc/mail/relay-domains
so that Sendmail can relay incoming mail to these host/domain.
After these steps, we can create our own m4 file which is used to create
our sendmail.cf later. In my experience, it's quite easier to create sendmail.cf
with all features we want than modify the sendmail.cf manually.
Your m4 file perhaps looks like this:
############ m4 file starts here #########################
# put this file in sendmail_src_dir/cf/cf/
include(`../m4/cf.m4')
# you can change this description to anything else
VERSIONID(`linux for smtp-only setup')dnl
# change linux to the os type you are running
OSTYPE(linux)
# redefine statistics file location, not necessary
define(`STATUS_FILE', `/etc/mail/statistics')dnl
# redefine local mailer location
define(`LOCAL_MAILER_PATH', `/usr/bin/mail')dnl
# redefine procmail mailer location, some os needs this, ie. IRIX
define(`PROCMAIL_MAILER_PATH', `/usr/local/bin/procmail')dnl
# wanna reject spam mail? try this!
FEATURE(`access_db', `hash /etc/mail/access')dnl
# enable relay from certain mail sender
FEATURE(relay_mail_from)dnl
# enable procmail
FEATURE(local_procmail)dnl
# wanna map incoming mail whose destination address is jimmyzhou@domain.dhs.
# org to jimmy@domain.dhs.org? try this!
FEATURE(`virtusertable', `hash /etc/mail/virtusertable')dnl
# wanna map outgoing mail whose source address is root@domain.dhs.org to
# other@yahoo.com? try this!
FEATURE(`genericstable', `hash /etc/mail/genericstable')dnl
GENERICS_DOMAIN_FILE(`/etc/mail/generics-domains')dnl
# misc option
FEATURE(always_add_domain)dnl
# for /etc/relay-domains
FEATURE(use_cw_file)dnl
# disable msa services
FEATURE(no_default_msa)dnl
# masquade as domain.dhs.org
MASQUERADE_AS(`domain.dhs.org')
MASQUERADE_DOMAIN(`host1.dhs.org')
MASQUERADE_DOMAIN(`host2.dhs.org')
LOCAL_DOMAIN(`domain.dhs.org')
# redefine daemon type and port, just in case
DAEMON_OPTIONS(`Port=smtp, Name=MTA, M=E')dnl
# following lines are security reason
# to confuse attackers. ;-)
define(`confSMTP_LOGIN_MSG', `$j Postfix ready at $b')
# disable some SMTP command
define(`confPRIVACY_FLAGS', `authwarnings,noexpn,novrfy,restrictmailq')
# restrict CC numbers in mail
define(`confMAX_RCPTS_PER_MESSAGE', `50')
# redefine pid file location
define(`confPID_FILE', `/etc/mail/sendmail.pid')
# mailers, don't modify unless you know what you are doing!
MAILER(local)dnl
MAILER(smtp)dnl
MAILER(procmail)dnl
############ m4 file ends here ##########################
After create the m4 file, say my.mc, generate sendmail.cf via m4 program:
host1 # m4 my.mc > /etc/mail/sendmail.cf
Ok, let's create some other file for all the features in my.mc.
. /etc/mail/access is to reject spam mail and allow relay mail from certain
sender. For example:
spam1.com ERROR:"550 spam mail is rejected"
spam2.com ERROR:"550 spam mail is rejected"
some.com RELAY
. /etc/mail/aliases is used to map incoming mail user to some actual user
in your system. For example:
# jimmyzhou@domain.dhs.org -> user jimmy
jimmyzhou: jimmy
# terminator@domain.dhs.org -> user jimmy
terminator: jimmy
# webmaster@domain.dhs.org -> user root
webmaster: root
. /etc/mail/generics-domains and /etc/mail/genericstable are used to map
actual user to some other mail address. For example:
# in generics-domain
bigfoot.com
# in genericstable
# user jimmy@domain.dhs.org -> jimmyzhou@bigfoot.com
jimmy jimmyzhou@bigfoot.com
. /etc/virtusertable is to map user from different domain into your master
domain. For example:
# map someone@host1.dhs.org to someone@domain.dhs.org
@host1.dhs.org %1@domain.dhs.org
Ok, the final step is to create database file from file access, aliases,
genericstable and virtusertable:
host1 # makemap hash access < access
host1 # makemap hash aliases < aliases
host1 # makemap hash genericstable < genericstable
host1 # makemap hash virtusertable < virtusertable
host1 # ls *.db
access.db aliases.db genericstable.db virtusertable.db
Now your Sendmail is ready to receive and send e-mail from your own domain!
Congratulations! And remember, administration is really fun! |
|