<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>温室小花.技术.博客 --纯粹的unix技术博客 &#187; mail</title>
	<atom:link href="http://www.evanjiang.net.cn/archives/category/apps/mail/feed" rel="self" type="application/rss+xml" />
	<link>http://www.evanjiang.net.cn</link>
	<description>红颜弹指老，刹那芳华，与其天涯思君，恋恋不舍，莫若相忘于江湖！</description>
	<lastBuildDate>Sun, 05 Sep 2010 14:51:18 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>mail 邮件服务器建设方案.</title>
		<link>http://www.evanjiang.net.cn/archives/1214.html</link>
		<comments>http://www.evanjiang.net.cn/archives/1214.html#comments</comments>
		<pubDate>Mon, 06 Jul 2009 14:39:15 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[mail]]></category>

		<guid isPermaLink="false">http://www.evanjiang.net.cn/archives/1214.html</guid>
		<description><![CDATA[<p>


 <p>mail 邮件服务器建设方案.</p>
<p>在中国为数众多的中小企业中，由于存在资金、人才、管理水平等瓶颈问题，全面实施信息化工程的企业比例较低。在信息系统的整体投入一般在百万元以下，当前建设主要集中在财务管理、电子邮件以及少量的ERP系统等方面。
而在信息系统的管理方面，中小企业由于缺少专业的技术人员，必然要求信息系统的核心&#8211;服务器系统，有很高的要求:便于管理和维护，能够远程操作等。那么如何选择一套满意的服务器系统，需要注意哪些方面的问题，成为中小企业用户目前迫切需要了解的瓶颈。</p>
<p>　　据统计，中小企业是双路服务器的主要市场。这类用户是当前中国经济中非常活跃的一部分，他们的数据应用是随着他们业务的增长而不断增长的，这就要求所选配的服务器具备弹性部署的能力，能够随应用的增长而有较大空间提升性能。由于中小企业受投资预算所限，一般采用2～3台服务器运行多个应用。虽然中小企业的应用多种多样，但是这多种应用的核心关注点归纳起来主要有以下方面。</p>
<p>　　首先是服务器的数据处理能力:在信息系统中，作为核心单元的服务器系统面临着各种数据采集、处理、传输等数据密集型操作。服务器系统强大的数据处理能力和数据吞吐能力是企业信息系统高效率运行的保障。这类应用一般常见于企业的网站、办公自动化系统和后台数据库的应用。</p>
<p>　　其次是服务器系统的可扩展性: 中小企业是一个不断成长、应用不断变化的经济个体。采购的服务器不光要满足当前的应用，还要能随着企业应用的变化而一同扩展、升级。这就要求服务器具备较大的扩展空间。

　　第三是服务器系统的可管理性:在中小企业应用中由于专业技术人员缺乏，承载着多种应用的服务器系统必须便于管理，运行稳定可靠。</p>
<p>　　第四是厂商的服务能力和信誉:中小企业需要将精力集中到主营业务上来，而信息系统的安全运行及售后保障需要厂家具备极强的售后服务能力和售前、售中的咨询服务能力。</p>
<p>　　解决方案</p>
<p>　　E-Mail服务器上运行着邮件服务软件，用户使用的电子邮箱就是建立在邮件服务器上。借助它提供的服务，建立企业内部邮件系统，辅助企业专业应用系统和OA系统，实现企业各级工作人员之间的沟通、交流、协作，以及与外界联络等。</p>
<p>　　目前，主流的电子邮件服务主要还是基于纯文本和HTML格式的邮件文件的存储和转发，但是随着邮件服务软件的功能扩展和某些工作对多媒体信息的渴求，邮件中开始携带越来越多的音视频数据信息，不但增大了邮件文件，还增加了邮件服务软件处理它们时的CPU资源开销</p>
]]></description>
			<content:encoded><![CDATA[<p style="float: left;margin: 4px;"><script type="text/javascript"><!--
google_ad_client = "pub-8438729971248494";
/* 160x600, 创建于 10-2-7 */
google_ad_slot = "8970910006";
google_ad_width = 160;
google_ad_height = 600;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></p> <p>mail 邮件服务器建设方案.</p>
<p>在中国为数众多的中小企业中，由于存在资金、人才、管理水平等瓶颈问题，全面实施信息化工程的企业比例较低。在信息系统的整体投入一般在百万元以下，当前建设主要集中在财务管理、电子邮件以及少量的ERP系统等方面。<br />
而在信息系统的管理方面，中小企业由于缺少专业的技术人员，必然要求信息系统的核心&#8211;服务器系统，有很高的要求:便于管理和维护，能够远程操作等。那么如何选择一套满意的服务器系统，需要注意哪些方面的问题，成为中小企业用户目前迫切需要了解的瓶颈。</p>
<p>　　据统计，中小企业是双路服务器的主要市场。这类用户是当前中国经济中非常活跃的一部分，他们的数据应用是随着他们业务的增长而不断增长的，这就要求所选配的服务器具备弹性部署的能力，能够随应用的增长而有较大空间提升性能。由于中小企业受投资预算所限，一般采用2～3台服务器运行多个应用。虽然中小企业的应用多种多样，但是这多种应用的核心关注点归纳起来主要有以下方面。</p>
<p>　　首先是服务器的数据处理能力:在信息系统中，作为核心单元的服务器系统面临着各种数据采集、处理、传输等数据密集型操作。服务器系统强大的数据处理能力和数据吞吐能力是企业信息系统高效率运行的保障。这类应用一般常见于企业的网站、办公自动化系统和后台数据库的应用。</p>
<p>　　其次是服务器系统的可扩展性: 中小企业是一个不断成长、应用不断变化的经济个体。采购的服务器不光要满足当前的应用，还要能随着企业应用的变化而一同扩展、升级。这就要求服务器具备较大的扩展空间。<br />
<span id="more-1214"></span><br />
　　第三是服务器系统的可管理性:在中小企业应用中由于专业技术人员缺乏，承载着多种应用的服务器系统必须便于管理，运行稳定可靠。</p>
<p>　　第四是厂商的服务能力和信誉:中小企业需要将精力集中到主营业务上来，而信息系统的安全运行及售后保障需要厂家具备极强的售后服务能力和售前、售中的咨询服务能力。</p>
<p>　　解决方案</p>
<p>　　E-Mail服务器上运行着邮件服务软件，用户使用的电子邮箱就是建立在邮件服务器上。借助它提供的服务，建立企业内部邮件系统，辅助企业专业应用系统和OA系统，实现企业各级工作人员之间的沟通、交流、协作，以及与外界联络等。</p>
<p>　　目前，主流的电子邮件服务主要还是基于纯文本和HTML格式的邮件文件的存储和转发，但是随着邮件服务软件的功能扩展和某些工作对多媒体信息的渴求，邮件中开始携带越来越多的音视频数据信息，不但增大了邮件文件，还增加了邮件服务软件处理它们时的CPU资源开销</p>
]]></content:encoded>
			<wfw:commentRss>http://www.evanjiang.net.cn/archives/1214.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Installing Cyrus IMAP and Postfix on OpenBSD</title>
		<link>http://www.evanjiang.net.cn/archives/847.html</link>
		<comments>http://www.evanjiang.net.cn/archives/847.html#comments</comments>
		<pubDate>Mon, 23 Mar 2009 14:26:48 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[mail]]></category>
		<category><![CDATA[openbsd unix]]></category>
		<category><![CDATA[www]]></category>
		<category><![CDATA[Installing Cyrus IMAP and Postfix on OpenBSD]]></category>

		<guid isPermaLink="false">http://www.evanjiang.net.cn/?p=847</guid>
		<description><![CDATA[<p style="float: right;margin: 4px;">


</p> <p>Table of contents
Introduction
Installation</p>
<p>Prerequisites
libsasl2
imapd
postfix
Configuration</p>
<p>imapd
sieve
postfix
Maintenance</p>
<p>Creating mailboxes
Deleting mailboxes
Installing sieve scripts
Restarting cyrus
Trouble shooting
SASL authentication failure
Undefined constant: _PATH_BSHELL
Introduction
This document is a step by step instruction for installing a Cyrus IMAP Server to an OpenBSD 3.4 machine. I was setting up a mail server for the faerion.oss domain and I wanted to achieve: </p>
<p>Security.</p>
<p>I wanted to secure [...]]]></description>
			<content:encoded><![CDATA[<p>Table of contents<br />
Introduction<br />
Installation</p>
<p>Prerequisites<br />
libsasl2<br />
imapd<br />
postfix<br />
Configuration</p>
<p>imapd<br />
sieve<br />
postfix<br />
Maintenance</p>
<p>Creating mailboxes<br />
Deleting mailboxes<br />
Installing sieve scripts<br />
Restarting cyrus<br />
Trouble shooting<br />
SASL authentication failure<br />
Undefined constant: _PATH_BSHELL<br />
Introduction<br />
This document is a step by step instruction for installing a Cyrus IMAP Server to an OpenBSD 3.4 machine. I was setting up a mail server for the faerion.oss domain and I wanted to achieve: </p>
<p>Security.</p>
<p>I wanted to secure as much data transfers as possible. All services use transport level security (TLS). (On a slightly different note, I was surprised to know how many major mail servers use TLS for delivery.) </p>
<p>Authenticity.</p>
<p>Anonymous SMTP sessions should only allow sending messages to local recipients.</p>
<p>Consistency.</p>
<p>One source of authentication for both IMAP and SMTP servers. I decided to use SASL2 as the simplest available solution. </p>
<p>Things I could not accomplish in the described setup:</p>
<p>Virtual domains (authentication always fails in imapd). [hint]<br />
Allow users to change passwords without my interaction.<br />
These issues will be covered in a later edition of this document.</p>
<p>Installation<br />
Prerequisites<br />
The IMAP server will be running as user cyrus; create the user and the group. </p>
<p>Postfix will be running as user _postfix. The port created everything automatically, so nothing needs to be done. </p>
<p>The password database will be shared between postfix and imapd, so a group mail must be created and both users must be added to it. </p>
<p>It is not a good idea to build ports as root (though you will have to install them as root). It is best to make the whole ports tree gourp writable:<br />
<span id="more-847"></span><br />
$ cd /usr<br />
$ sudo chmod -R g+w ports<br />
$ sudo chown -R root:wheel portsCyrus SASL Library<br />
The library is in ports, so it is supposed to be installed relatively easy. However, the port for OpenBSD 3.4 is broken (&#8220;make install&#8221; is failing to install shared versions of authentication plugins). Updated the port to version 3.5, it will work on 3.4. </p>
<p>$ cd /usr/ports/security/cyrus-sasl2<br />
$ cvs up -d:pserver:anoncvs@anoncvs.ca.openbsd.org:/cvs up -r OPENBSD_3_5<br />
$ make<br />
$ sudo make installCyrus IMAP Server<br />
I was installing the latest available version, 2.2.3. I had to disable GSSAPI support until they fix it to compile on OpenBSD.</p>
<p>The following commands worked for me:</p>
<p>$ ftp ftp://ftp.andrew.cmu.edu/pub/cyrus-mail/cyrus-imapd-2.2.3.tar.gz<br />
$ tar xfz cyrus-imapd-2.2.3.tar.gz<br />
$ cd cyrus-imapd-2.2.3<br />
$ ./configure \<br />
	&#8211;with-openssl=/usr \<br />
	&#8211;with-cyrus-user=cyrus \<br />
	&#8211;with-cyrus-group=cyrus \<br />
	&#8211;with-notify=no \<br />
	&#8211;with-idle=idled \<br />
	&#8211;disable-cmulocal \<br />
	&#8211;disable-gssapi \<br />
	&#8211;with-sasl=/usr/local \<br />
	&#8211;with-bdb=/usr/local/BerkeleyDB.4.2 \<br />
	&#8211;with-bdb-incdir=/usr/local/BerkeleyDB.4.2/include<br />
$ make<br />
$ sudo make installPostfix<br />
$ cd /usr/ports/mail/postfix/snapshot<br />
$ export FLAVOR=&#8221;sasl2 tls&#8221;<br />
$ make<br />
$ sudo make install<br />
$ export FLAVOR=<br />
$ sudo /usr/local/sbin/postfix-enable &#8212; replace sendmail with postfixConfiguration<br />
Configuring imapd<br />
Create the master configuration file:</p>
<p>$ sudo cp master/conf/normal.conf /etc/cyrus.confEdite the file to disable pop3 and pop3s and enable idled (the latter is an extension that notifies connected clients about new mail so that they won&#8217;t have to periodically query the server; you definitely want this).</p>
<p>Create /etc/imapd.conf with the following content:</p>
<p>admins: cyradm<br />
configdirectory: /var/imap<br />
partition-default: /var/spool/imap<br />
reject8bit: 1<br />
rfc2046_strict: 1<br />
virtdomains: no<br />
sasl_pwcheck_method: auxprop<br />
tls_cert_file: /var/imap/server.pem<br />
tls_key_file: /var/imap/server.pemCreate directories specified in imapd.conf:</p>
<p>$ mkdir -m 750 /var/imap /var/spool/imap<br />
$ sudo chown cyrus.cyrus /var/imap /var/spool/imap<br />
$ sudo -u cyrus tools/mkimapCreate the certificate:</p>
<p>$ cd &#8212; home<br />
$ openssl req -new -x509 -nodes -out server.pem \<br />
	-keyout server.pem -days 3650<br />
$ sudo mv server.pem /var/imap/Add the following lines to /etc/rc.local:</p>
<p>if [ -x /usr/cyrus/bin/master ]; then<br />
	echo -n &#8216; cyrus-imapd&#8217;<br />
	/usr/cyrus/bin/master -d >/dev/null 2>&#038;1<br />
fiStart the server:</p>
<p>$ sudo /usr/cyrus/bin/master -dMake sure it works:</p>
<p>$ telnet localhost. imap<br />
Trying ::1&#8230;<br />
Connected to localhost..<br />
Escape character is &#8216;^]&#8217;.<br />
* OK faerion.oss Cyrus IMAP4 v2.2.3 server ready<br />
. logout<br />
* BYE LOGOUT received<br />
. OK Completed<br />
Connection closed by foreign host.Good.</p>
<p>Create an email user account that will be used for administering the server:</p>
<p>$ sudo saslpasswd2 -c cyradm<br />
Password:<br />
Again (for verification):Make sure the server will be able to access the database:</p>
<p>$ sudo chown cyrus.mail /etc/sasldb2.dbTry to log in as user cyradm using the LOGIN method:</p>
<p>$ imtest -m login -a cyradm localhost.<br />
S: * OK faerion.oss Cyrus IMAP4 v2.2.3 server ready<br />
C: C01 CAPABILITY<br />
S: * CAPABILITY IMAP4 IMAP4rev1 ACL QUOTA LITERAL+<br />
	MAILBOX-REFERRALS NAMESPACE UIDPLUS ID NO_ATOMIC_RENAME<br />
	UNSELECT CHILDREN MULTIAPPEND BINARY SORT<br />
	THREAD=ORDEREDSUBJECT THREAD=REFERENCES ANNOTATEMORE<br />
	IDLE STARTTLS AUTH=OTP AUTH=GSSAPI AUTH=DIGEST-MD5<br />
	AUTH=CRAM-MD5 SASL-IR<br />
S: C01 OK Completed<br />
Please enter your password:<br />
C: L01 LOGIN cyradm {4}<br />
S: + go ahead<br />
C:<br />
S: L01 OK User logged in<br />
Authenticated.<br />
Security strength factor: 0<br />
. logout<br />
* BYE LOGOUT received<br />
. OK Completed<br />
Connection closed.Wonderful.</p>
<p>Configuring SIEVE<br />
Sieve is server-side message filtering extension. It requires two additional directories:</p>
<p>$ sudo mkdir -m 750 /usr/sieve /var/sieve<br />
$ sudo chown cyrus.cyrus /usr/sieve /var/sieveConfiguring Postfix<br />
/etc/postfix/main.cf<br />
Added my domains:</p>
<p>myhostname = faerion.oss<br />
mydestination = $myhostname, faerion.ossChanged mailbox transport to cyrus:</p>
<p>mailbox_transport = cyrusEnabled SASL by adding the following to the end of the file:</p>
<p>smtpd_recipient_restrictions =<br />
	reject_non_fqdn_recipient,<br />
	permit_auth_destination,<br />
	permit_sasl_authenticated,<br />
	reject<br />
smtpd_sasl_auth_enable = yes<br />
smtpd_sasl_local_domain = $myhostname<br />
smtpd_sasl_security_options = noanonymous<br />
broken_sasl_auth_clients = yes<br />
/etc/postfix/master.cf<br />
Corrected the path to the delivery agent (it was /cyrus/bin/deliver):</p>
<p>cyrus     unix  &#8211;       n       n       &#8211;       &#8211;       pipe<br />
  user=cyrus argv=/usr/cyrus/bin/deliver -e -r ${sender} -m ${extension} ${user}<br />
To use SASL, the following lines were added to /usr/local/lib/sasl2/smtpd.conf</p>
<p>Note: there were numerous &#8220;SASL authentication failure&#8221; warnings in /var/log/maillog which confused me at first; it came out to be normal because libsasl2 features several plugins, only one of which succeeds (sasldb), all other should fail.</p>
<p>pwcheck_method: auxprop<br />
mech_list: crammd5 digestmd5 login plainI wanted to use a single certificate for both IMAP and SMTP (some email clients, like The Bat!, complain if different certificates are used):</p>
<p>$ sudo mkdir /etc/postfix/ssl<br />
$ sudo cp /var/imap/server.pem /etc/postfix/ssl/Enabled TLS by adding the following lines to /etc/postfix/main.cf:</p>
<p>smtp_use_tls = yes<br />
smtpd_use_tls = yes<br />
smtp_tls_note_starttls_offer = yes<br />
smtpd_tls_key_file = /etc/postfix/ssl/server.pem<br />
smtpd_tls_cert_file = /etc/postfix/ssl/server.pem<br />
smtpd_tls_CAfile = /etc/postfix/ssl/server.pem<br />
smtpd_tls_loglevel = 1<br />
smtpd_tls_received_header = yes<br />
smtpd_tls_session_cache_timeout = 3600s<br />
tls_random_source = dev:/dev/urandomSince postfix runs chrooted by default, it needs a local copy of /etc/sasldb2.db. I made a hardlink, because /etc and /var are within one filesystem in my installation; you may need to copy the file (perhaps in a cron script) or unchroot the smtp service.</p>
<p>$ sudo mkdir /var/spool/postfix/etc<br />
$ sudo ln /etc/sasldb2.db /var/spool/postfix/etc/sasldb2.dbTo make sure postfix starts with the system, the following lines were added to /etc/rc.local:</p>
<p>if [ -x /usr/sbin/postfix ]; then<br />
	echo -n &#8216; postfix&#8217;<br />
	/usr/sbin/postfix start >/dev/null 2>&#038;1<br />
fiStarted the server:</p>
<p>$ sudo postfix startMaintenance<br />
Creating mailboxes<br />
$ sudo -u cyrus saslpasswd2 -c hex<br />
Password:<br />
Again (for verification):<br />
$ cyradm -a login -u cyradm localhost.<br />
IMAP Password:<br />
localhost> createmailbox user.hex<br />
localhost> quitDeleting mailboxes<br />
$ sudo -u cyrus saslpasswd2 -d hex<br />
$ cyradm -a login -u cyradm localhost.<br />
IMAP Password:<br />
localhost> setaclmailbox user.hex cyradm c<br />
localhost> deletemailbox user.hex<br />
localhost> quitInstalling sieve scripts<br />
I created a temporary file called tosser, then I installed it for user hex:</p>
<p>$ sieveshell -u hex localhost.<br />
connecting to localhost.<br />
Please enter your password:<br />
> put tosser<br />
> activate tosser<br />
> list<br />
tosser  <- active script<br />
> quit<br />
$ rm tosserHere is a self-explaining example of a sieve script. (I have found this script here and copied it just in case the original link dies.)</p>
<p>require &#8220;fileinto&#8221;;</p>
<p>if header :is &#8220;X-Mailinglist&#8221; &#8220;suse-linux&#8221; {<br />
	fileinto &#8220;INBOX.Listen.suse-linux&#8221;;<br />
}<br />
elsif header :contains &#8220;Mailing-List&#8221; &#8220;reiserfs&#8221; {<br />
	fileinto &#8220;INBOX.Listen.reiserfs&#8221;;<br />
}<br />
elsif address :contains :all ["to", "cc", "bcc"] &#8220;free-clim&#8221; {<br />
	fileinto &#8220;INBOX.Listen.free-clim&#8221;;<br />
}<br />
elsif header :contains &#8220;List-Id&#8221; &#8220;gnupg-users.gnupg.org&#8221; {<br />
	fileinto &#8220;INBOX.Listen.gnupg&#8221;;<br />
}<br />
elsif header :is &#8220;X-loop&#8221; &#8220;isdn4linux&#8221; {<br />
	fileinto &#8220;INBOX.Listen.isdn4linux&#8221;;<br />
}<br />
elsif header :contains  &#8220;Mailing-list&#8221; &#8220;qmail-help@list.cr.yp.to&#8221; {<br />
	fileinto &#8220;INBOX.Listen.qmail&#8221;;<br />
}<br />
elsif allof (header :contains &#8220;Sender&#8221; &#8220;owner-info-cyrus@list&#8221;,<br />
	address :contains :localpart ["to", "cc", "bcc"] &#8220;info-cyrus&#8221;) {<br />
		fileinto &#8220;INBOX.Listen.info-cyrus&#8221;;<br />
}<br />
elsif header :contains &#8220;Sender&#8221; &#8220;ntbugtraq@listserv&#8221; {<br />
	fileinto &#8220;INBOX.Listen.ntbugtraq&#8221;;<br />
}<br />
elsif header :is &#8220;list-id&#8221; &#8220;&#8221; {<br />
	fileinto &#8220;INBOX.Listen.sieve&#8221;;<br />
}<br />
elsif header :contains &#8220;From&#8221; &#8220;securityportal-l@listserv.securityportal.com&#8221; {<br />
	fileinto &#8220;INBOX.Newsletter.securityportal&#8221;;<br />
}<br />
elsif address :contains :all ["from"] &#8220;newsletter@ebay&#8221; {<br />
	fileinto &#8220;INBOX.Newsletter.ebay&#8221;;<br />
}<br />
elsif address :contains :all ["to", "cc", "bcc"] &#8220;allegro-cl@cs.berkeley.edu&#8221; {<br />
	fileinto &#8220;INBOX.Listen.allegro-cl&#8221;;<br />
}<br />
elsif address :contains :all ["to", "cc", "bcc"] &#8220;plob@lisp.de&#8221; {<br />
	fileinto &#8220;INBOX.Listen.plob&#8221;;<br />
}<br />
else {<br />
	fileinto &#8220;INBOX&#8221;;<br />
}Restarting cyrus<br />
I needed to do the following after changing /etc/imapd.conf or /etc/cyrus.conf:</p>
<p>$ sudo kill `head -1 /var/run/cyrus-master.pid`<br />
$ sudo /usr/cyrus/bin/master -dTrouble shooting<br />
SASL authentication failure<br />
This message in your mailer&#8217;s log file (usually /var/log/maillog) means that postfix could not verify the user name against userdb. Make sure that:</p>
<p>The userdb files are readable by postfix children processes.<br />
The userdb files are in the right location. If you run postfix chrooted, make sure that you add passwords to the right copy which is inside the chroot jail.<br />
Sometimes libsasl does not want to verify passwords if the domain name (&#8220;realm&#8221;) is not specified. Try logging in to the SMTP server using all available authentication data: username@domain.<br />
These notes are not only applicable to the OpenBSD installation described by this document (and most of these errors are not likely to happen); they might be useful to people attempting to use this guide to set up a similar mail server on a different operating system.</p>
<p>Undefined constant: _PATH_BSHELL<br />
This error may occur if you have nntpd installed, which also installs its own vision of system paths as /usr/local/include/paths.h. Remove this file and postfix should recompile smoothly. </p>
]]></content:encoded>
			<wfw:commentRss>http://www.evanjiang.net.cn/archives/847.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Step-by-Step Guide to Building an OpenBSD PPPoE Gateway, with Firewall</title>
		<link>http://www.evanjiang.net.cn/archives/845.html</link>
		<comments>http://www.evanjiang.net.cn/archives/845.html#comments</comments>
		<pubDate>Mon, 23 Mar 2009 14:21:18 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[dns]]></category>
		<category><![CDATA[ftp]]></category>
		<category><![CDATA[mail]]></category>
		<category><![CDATA[openbsd unix]]></category>
		<category><![CDATA[pf]]></category>
		<category><![CDATA[shell]]></category>
		<category><![CDATA[www]]></category>
		<category><![CDATA[Building  OpenBSD PPPoE Gateway]]></category>
		<category><![CDATA[with Firewall]]></category>

		<guid isPermaLink="false">http://www.evanjiang.net.cn/?p=845</guid>
		<description><![CDATA[<p>Introduction
Why would one install his own personal gateway to the Internet? Because it is quite easy to do. And also because it simply is the most reliable, safest way to connect machines to a dedicated xDSL modem. Moreover, we can stash a whole bunch of useful features in such a little box. Here is a [...]]]></description>
			<content:encoded><![CDATA[<p>Introduction<br />
Why would one install his own personal gateway to the Internet? Because it is quite easy to do. And also because it simply is the most reliable, safest way to connect machines to a dedicated xDSL modem. Moreover, we can stash a whole bunch of useful features in such a little box. Here is a list: </p>
<p>PPPoE Gateway<br />
PPPoE is a curious beast forced down our throats by some DSL providers. On one side, it does not really break anything, has low overhead and allows you to change IP adresses very easily &#038; quickly. On the other side, it sucks big time because it does add overhead to the IP packets, is proprietary, non-standard, forces you to change IP adresses unpredictably, and is unsupported in most operating systems. A good PPPoE gateway simply hides PPPoE from the machines on your internal network. It makes life much easier because you don&#8217;t have to install any special &#8220;access manager&#8221; software on your windoze boxen. They will just work (provided you set their IP address correctly). </p>
<p>Firewall<br />
A firewall is quite mandatory for any machine directly connected to the Big Bad Internet. We want an industrial-strength stateful inspection firewall and this is what we&#8217;ll get. </p>
<p>NAT (Network Adress Translation)<br />
The name seems complex, but it is really quite simple: this allows the gateway machine to act on the internet on behalf of all the machines located on the intranet (your internal home network). Even though you might have two, three or even ten computers on your local network, a NAT equipped gateway will hide them to outside observers. They will only see a single very busy machine, with a single IP address. </p>
<p>DNS (Domain Name Service) cache<br />
Having your own DNS server will lower the latency of getting DNS translations for all the machines on your intranet. This will not really decrease the traffic on your DSL modem by a large percentage, but it will improve the quality of the &#8220;internet experience&#8221; on your local network. </p>
<p>Dynamic DNS tracker<br />
Free dynamic DNS services are extremely useful to xDSL customers. They allow you to have your very own domain name, free of charge, which will follow in real-time your IP address changes. The catch is that the top-level part of your domain must be one of their supplied choices. They are not that bad, really&#8230; Personally, I use DYNDNS but any of the multiple free dynamic DNS providers out there will do just fine. Simply make sure they have a client &#8220;updater&#8221; which can compile and run under OpenBSD. </p>
<p>WEB server<br />
Most ISP&#8217;s only allow a few megabytes of disk for web service. Moreover, they never give you direct access to the web logs. Having your own web server allows you the luxury of using all the disk space you want, plus the added advantage of complete control over the web service (cgi-bin) and its logs. Moreover, OpenBSD comes with a crypto-enabled version of Apache and all the tools you need to create RSA-keyed certificates. </p>
<p>Mail server<br />
Have you ever wanted to create a temporary email address just to receive some password? Or simply wanted addresses tailored for specific domains of interest? These are only a few of the many advantages of having your own mail server. </p>
<p>NTP server<br />
The Network Time Protocol allow you to synchronize the gateway&#8217;s clock to one of the numerous atomic time references available on the internet. Moreover, the same program is also used as a local time server, so that all your intranet machines can themselves synchronize their clocks to the gateway&#8217;s clock. NTP synchronizations are made in tiers, like this, in order to lower the burden on the public time servers. </p>
<p>This page is for all those of you who have are lucky enough to enjoy a dedicated xDSL connection and would like to have a small firewall installation. In my search for the holy grail, i found the answer to most of my wishes in the OpenBSD package. This step-by-step guide is a collection of notes taken while I was installing the thing. They are intended to help my friends do their own setups very quickly and easily, without having to bug me too much <img src='http://www.evanjiang.net.cn/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' />  They should help you too.</p>
<p>Constructive comments can be sent there &#8230; Have fun and GOOD LUCK!</p>
<p><span id="more-845"></span><br />
Getting some hardware<br />
The first thing to think about when one embarks on the firewalling adventure is to establish on what hardware you are going to install the thing. This seems unimportant at first, but don&#8217;t forget that this box will be turned on 24/7, so the components you use must be reliable.</p>
<p>What are the minimum requirements? My system uses about 50% of its CPU to support Sympatico&#8217;s ADSL rate (around 900 kbps). It is built with the following components:</p>
<p>An ancient 486 motherboard (with an ISA bus) given to me by a friend (thanks Christian!). It runs at 66 MHz.<br />
32 MB of brand new RAM i bought for it.<br />
A 200 MB hard disk, which was dying after about 1 year of faithful use (it came with the motherboard). This disk was recently replaced with the cheapest brand new drive i could find. I didn&#8217;t know they still made those slow 3600 RPM drives <img src='http://www.evanjiang.net.cn/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' />  Anyway, the old drive is kept as a kind of extreme emergency backup.<br />
Two ISA-bus ethernet cards. I&#8217;ll talk more about this later.<br />
A CD-ROM drive. Very optional, but can make life easier.<br />
A &#8220;home&#8221; grade hub &#038; cat5 cabling. This is not strictly necessary if you&#8217;ll have only one machine connected to your firewall: you can make do with a special &#8220;crossover&#8221; cat5 cable instead. The cable that comes with xDSL modems is usually (always?) a crossover cable. Anyway, for two or more machines, the hub is mandatory. Small hubs can be bought for a very reasonable price (~40$ cdn).<br />
or<br />
Alternatively, many older ethernet cards come with a BNC female connector. This can be used to connect the machines on your network with coax cables, without any hub. However, be warned that a 10base-2 network must follow certain rules if you want it to work flawlessly. Follow them.<br />
This gives a good approximation of what you need. The MOST important part is the RAM. Make absolutely sure that whatever RAM you use is reliable. Old boxen were usually setup to run Windoze, and it was not a big deal if the machine had flaky RAM because of the way Windoze works&#8230;</p>
<p>OpenBSD (like any real OS out there) is much less tolerant of flaky RAM, because it actually uses all of it. It will crash quite quickly if your RAM is marginal, probably within 5-10 minutes. You have been warned.</p>
<p>Finally, the OpenBSD hardware list is there. Try to make sure that whatever hardware you use in your gateway box figures on that list. It&#8217;s a long list <img src='http://www.evanjiang.net.cn/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p>The ethernet cards<br />
There is a boring thing of which we must talk about here. You see, there are many kinds of ethernet cards, and you must make sure you have the right ones for your machine. If you have a PCI-based machine, then all is well. Whatever ethernet card you put in there will probably be supported by OpenBSD. However, you must be a bit more careful if you have an ISA-based machine.</p>
<p>It is most likely that your box will not have any ethernet cards to start with since most people did not have networks at home in the pre-historic era of 4 years ago. You need two cards. One will be connected to the DSL modem (the big, bad outerworld), while the other is connected to your internal network hub (your intranet). The gateway&#8217;s job will be to pass (or block) packets between those two network cards. For security, its very important that the outside world packets cannot reach directly any of the intranet machines. This is the reason why we use two ethernet cards: complete logical and electrical isolation. Why so much isolation? For example, if someone(s) were launching a full (distributed or not) denial of service attack on your gateway box, its internet-connected ethernet card would be extremely busy, but your intranet would see nothing of this. While any communication with the outside world would probably fail, at least your intranet machines would still be able to talk to each other.</p>
<p>ISA cards use dedicated I/O ports and IRQ&#8217;s in your machine. Those must be setup either with jumpers directly on the card, or with a special DOS program if the card is of the more recent &#8220;Plug &#038; Play&#8221; type. This DOS program is always supplied with the card, when purchased brand new.</p>
<p>If your card is Plug&#038;Play, you must disable the Plug&#038;Play, and program specific I/O port and IRQ values with the setup software that comes with the card. Make sure that you program both cards with different sets of I/O ports and IRQs! Otherwise they will battle each other for cycles on the bus and the result will not be pretty. Once you have set the parameters on the card it will remember them and you don&#8217;t have to reprogram anything later on, even if the computer is turned off.</p>
<p>It is good at this point to know a few magic numbers:</p>
<p>Card Type I/O #1 IRQ #1 Mem #1 I/O #2 IRQ #2 Mem #2<br />
NE2000 (ne) 0&#215;240 9 &#8212; 0&#215;300 10 &#8212;<br />
SMC WD-8003 (we) 0&#215;280 9 0xd0000 0&#215;300 10 0xcc000 </p>
<p>For example, i use two cards made by AOpen: the model ALN-101. They are Plug&#038;Play and use the NE2000 chip. The first one is setup at I/O port 0&#215;240, IRQ 9. It is known as &#8220;ne0&#8243; in the GENERIC openBSD kernel. The second one is set at I/O port 0&#215;300, IRQ 10. It is known as &#8220;ne1&#8243;. If the cards were programmed differently, the GENERIC kernel would not recognize them &#8220;out of the box&#8221; and you would have to re-configure the kernel. It can be done, but its much easier to setup the hardware once than re-configure the kernel every time it gets upgraded.</p>
<p>Some of you might have problems setting the card to an arbitrary combination of IO port and IRQ number. This is allright, just let the card decide what it wants and simply reconfigure your kernel to accomodate that. What is important is that both ethernet cards are not set to conflicting values. Otherwise, any combination that the cards like will be programmable in the kernel.</p>
<p>Last but not least: some cards can be used in the so-called &#8220;full-duplex&#8221; mode. Be aware that if you want to use an ethernet card in full-duplex, your hub must also be full-duplex, as well as the other ethernet cards in the system. A full-duplex hub is much more expensive and not necessary at all. Unless you know what you are doing, program your ethernet cards to use the half-duplex mode, otherwise it won&#8217;t play nice with the other components in your local network, including the xDSL modem <img src='http://www.evanjiang.net.cn/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /><br />
(注，这里需要说NE2000等旧款的基于486机的网卡也可以用，但现在这些网卡，其本难找，所以至少要用8139系列芯片的10-100M自适应的网卡来做应用）</p>
<p>The hard disk<br />
The most secure storage medium is one which can&#8217;t be erased. Some firewalls actually use setups like this (with CD-ROMS) but we&#8217;ll build our firewall with a classic, writeable hard drive because:</p>
<p>We don&#8217;t need &#8220;Absolute Security&#8221;, do we? We can&#8217;t have it anyway <img src='http://www.evanjiang.net.cn/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /><br />
We want to use an &#8220;out-of-the-box&#8221; OpenBSD distro. This will make maintenance (security, patches, etc&#8230;) much easier.<br />
Almost any hard disk out there will work OK, since 200 MB is a safe minimum size. The only thing you must remember is that this disk will run 24/7, so if you use an old drive, it will likely die relatively soon. The venerable drive my friend gave me lasted 6 months before i had to change it, YMMV.</p>
<p>No keyboard?<br />
Of course you&#8217;ll need a keyboard&#8230; and a monitor too, but just for the installation. After the firewall is successfully installed, you will be able to talk to it through encrypted ssh connections over your internal network, so a keyboard &#038; monitor will not be really useful at that point.</p>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;</p>
<p>Getting the software<br />
We will be using OpenBSD. Why? Because it is the most secure freely available operating system out there. All the source code included in the mainstream distribution CD&#8217;s has been audited for years by the OpenBSD team, which is why sometimes an exploit published on BugTraq is found not to work on OpenBSD simply because the faulty code was already fixed months ago.</p>
<p>I strongly suggest you buy their CD-ROM kit as it comes with a set of very cool stickers&#8230; You can also download their stuff for free, of course, but you won&#8217;t have the stickers then <img src='http://www.evanjiang.net.cn/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p>This Guide is written for OpenBSD 3.0.</p>
<p>The easiest way to install the software is to use a CD-ROM drive on your firewall box. If you don&#8217;t have that, you can do a network install with the &#8220;ftp&#8221; protocol, either directly to an outside OpenBSD mirror, or to one of your own internal machines equipped with an ftp server. Be aware that if your DSL provider forces you to use PPPoE (boooo!), then of course your link to the outside world will not be functional yet at installation time, which is one more reason to use the CD-ROM. If your machine can boot a CD-ROM, great! It will gladly boot the OpenBSD disc. Otherwise, simply create a boot diskette according to the README and boot that. This diskette is also your rescue disk, so don&#8217;t lose it.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;</p>
<p>Installing OpenBSD<br />
The installation of OpenBSD is very easy, once you have the right hardware, and the right answers to some of the questions. In the following steps, i&#8217;ll assume you can follow the instructions of the install program and focus only on the tricky little things you should know to make your life easier.</p>
<p>fdisk &#038; disklabel<br />
After you boot the installer, one of the very first things you&#8217;ll have to do is partition your disk. This is done with the &#8220;fdisk&#8221; and &#8220;disklabel&#8221; programs. The installer will ask you if you want to use the entire hard disk for OpenBSD. Answer No, even if it is not entirely true. If you say yes, the whole fdisk step will be bypassed, and you will not be able to change the default cylinder/head/sector configuration in order to boot off the hard disk without resorting to the silly &#8220;FDISK /MBR&#8221; DOS command which is a stupid solution to a stupid problem.<br />
The default OpenBSD fdisk partition setup choice is in slot #3. If you want, you can move your OpenBSD partition in slot #0 with no ill effect.</p>
<p>Important: On some systems, to make sure your system boots off the hard disk, you must set the starting CHS (cylinder/head/sector) to C=0, H=0, S=1, because fdisk suggested an incorrect value for H in OpenBSD 2.7, and still does in 2.8 &#8230; If you use &#8220;1&#8243;, as it suggests, your system will not be able to boot from the hard disk.</p>
<p>After the disk is partitioned with fdisk, you use disklabel to further organize the partition. A label behaves like a traditional partition (as used in Linux, for example), except that you can put as many labels as you want in the single OpenBSD partition. This is useful.</p>
<p>On a fully partitioned system, the disk labels might look like this: </p>
<p>  a:  2097648        0    4.2BSD     1024  8192    16   # /               1 GB<br />
  b:   262080  2097648      swap                        # SWAP          128 MB<br />
  c: 20015856        0    unused        0     0         # (whole disk)   10 GB<br />
  d:  2097648  2359728    4.2BSD     1024  8192    16   # /usr            1 GB<br />
  e:  2097648  4457376    4.2BSD     1024  8192    16   # /tmp            1 GB<br />
  f:  2097648  6555024    4.2BSD     1024  8192    16   # /var            1 GB<br />
  g:  4194288  8652672    4.2BSD     1024  8192    16   # /usr/local      2 GB<br />
  h:  7168896 12846960    4.2BSD     1024  8192    16   # /home           3 GB<br />
On my firewall, i like to keep things simpler, so it goes like this: </p>
<p>#        size   offset    fstype   [fsize bsize   cpg]<br />
  a: 18874800        0    4.2BSD     1024  8192    16   # (Cyl.    0 &#8211; 18724)<br />
  b:  1141056 18874800      swap                        # (Cyl. 18725 &#8211; 19856)<br />
  c: 20015856        0    unused        0     0         # (Cyl.    0 &#8211; 19856)As you see, the &#8216;c&#8217; label is a placeholder for the whole disk, in all cases. Don&#8217;t delete or otherwise change this, or you&#8217;ll be in trouble. </p>
<p>One of the main disadvantages of having a single partition is that one could do bad things in such quantity that the log files would simply fill up the whole drive. OpenBSD doesn&#8217;t like it when all its disk space is full. You can guess the rest of the story. In practice, this is not an issue, since i monitor my log files daily, but it could be an issue for someone out there. </p>
<p>On a fully partitioned system, the &#8220;df&#8221; command says this, after the OS is installed, with its complete source trees: </p>
<p>Filesystem      1K-blocks     Used    Avail Capacity  Mounted on<br />
/dev/wd0a         1015269    25985   938521     3%    /<br />
/dev/wd0d         1015269   480284   484222    50%    /usr<br />
/dev/wd0e         1015269        1   964505     0%    /tmp<br />
/dev/wd0f         1015269     5141   959365     1%    /var<br />
/dev/wd0g         2030307     8698  1920094     0%    /usr/local<br />
/dev/wd0h         3470505       27  3296953     0%    /home</p>
<p>On my system i have this:</p>
<p>Filesystem                           1K-blocks     Used    Avail Capacity  Mounted on<br />
/dev/wd0a                              9137589   503054  8177656     6%    /</p>
<p>In this example, the full OpenBSD source tree is installed, which explains why the thing uses up about 500 MB. Without the source tree, you only need about 120 MB in there, but having the source tree allows you to make security patches as they are published. This is important and i&#8217;ll talk about it more later.</p>
<p>Active FTP<br />
If you do an FTP install to a private FTP server, it might be necessary to use active FTP. </p>
<p>Crypto, SSL, etc&#8230;<br />
The crytographic packages are included in the CD&#8217;s since release 2.9 of OpenBSD. They will be automatically installed. </p>
<p>UTC time zone<br />
Keep your server in the UTC time zone. This way, your firewall logs will be timestamped in UTC time and it will be simpler to have them interpreted by the abuse@&#8230; services of ISP&#8217;s. Also, it is important to make sure the gateway is time-synchronized to one of the numerous public NTP servers out there, because having only an IP address is not enough to pin down internet abusers. In this age of dynamic IP allocations you need both IP address and exact time in order to positively identify the origin of an IP packet. Keep your gateway synchronized.<br />
Why not GMT instead? Read all about it there.</p>
<p>Normally, the installer will ask you for a time zone at install time. If you want to change it later, simply make /etc/localtime point to /usr/share/zoneinfo/UTC with a soft link: </p>
<p>ln -s /usr/share/zoneinfo/UTC /etc/localtime</p>
<p>First Boot<br />
reboot &#8230; did your machine boot correctly? If not, please consult the numerous FAQ&#8217;s available at the OpenBSD site. Are you sure you set H=0 in fdisk? By the way, if it doesn&#8217;t boot from hard disk, you can probably still force it by first booting the install diskette, and entering &#8220;boot wd0a:/bsd&#8221; at the initial prompt. You have about 5 seconds to make your mind, when you see this prompt, act swiftly.<br />
On first boot, you will probably get a message like &#8220;ssh-keygen: generating new DSA host key&#8230;&#8221;, followed with an equivalent message for the RSA host key. They might take quite a long time on a 486 (5-10 minutes), so Don&#8217;t Panic! &#8482; , the machine is not crashed, and the boot process will eventually follow its course, given time. This will happen only on the first boot.</p>
<p>Kernel extra configuration<br />
If, at this point, the kernel sees all you devices (including both ethernet cards), congratulations. If not, you can reconfigure the kernel without having to recompile it by simply using the config utility. Typically, you would copy your current kernel (the &#8220;/bsd&#8221; file) to an appropriate backup name (e.g. &#8220;/bsd.ORIGINAL&#8221;), and issue this command: </p>
<p>config -e -f /bsd<br />
and make whatever changes you need. You should know what you&#8217;re doing in order to use this command without blowing your system up into tiny bits &#038; pieces. Don&#8217;t forget to save your changes. If this modified kernel doesn&#8217;t work OK, just boot the &#8220;/bsd.ORIGINAL&#8221; kernel instead, and you will have another chance. </p>
<p>Sys control files<br />
The services allowed by OpenBSD are configured by a couple of files in the /etc directory. Actually, this directory contains all the configuration files of OpenBSD, for your convenience, but this is something you&#8217;ll only appreciate later, when you become an experienced BSD maintainer&#8230; We&#8217;ll come back to that /etc directory quite often.<br />
For now, just make sure that the following are enabled:</p>
<p>In the file /etc/sysctl.conf:<br />
net.inet.ip.forwarding=1</p>
<p>and in /etc/rc.conf:<br />
sendmail_flags=&#8221;-L sm-mta -bd -q30m&#8221;<br />
named_flags=&#8221;"<br />
httpd_flags=&#8221;-DSSL&#8221;</p>
<p>Important: If you plan to use PPPoE, don&#8217;t enable pf here because you want to start it in a controlled manner, after PPPoE is started. Enabling &#8220;pf&#8221; here would make it start at the very beginning of the boot process and this would not work. </p>
<p>PPP &#038; PPPoE<br />
Ahhhh&#8230; the Evil Beast. Installing a good, working PPP and PPPoE can be quite a tricky task. In OpenBSD 3.0, it is included and works well, once properly configured. This version of PPP supports the &#8220;mssfixup&#8221; instruction which magically allows you to avoid setting MTU&#8217;s at 1492 or less on all of your intranet&#8217;s machines. This is very recommended as it avoids a whole bunch of problems with Windows machines, internet appliances, etc&#8230;<br />
Notice that there is an excellent Network FAQ available from the OpenBSD site. It contains a lot of information on what to do with those ethernet adapters. </p>
<p>The configuration file for ppp is in /etc/ppp/ppp.conf. Mine contains exactly this:</p>
<p>default:<br />
 set log Phase Chat IPCP CCP tun command<br />
 set redial 15 0<br />
 set reconnect 15 10000</p>
<p>pppoe:<br />
 set device &#8220;!/usr/sbin/pppoe -i ne0&#8243;<br />
 disable acfcomp protocomp<br />
 deny acfcomp<br />
 set mtu max 1492<br />
 set speed sync<br />
 enable lqr<br />
 set lqrperiod 5<br />
 set cd 5<br />
 set dial<br />
 set login<br />
 set timeout 0<br />
 set authname xxxxxxx<br />
 set authkey xxxxxx<br />
 add! default HISADDR<br />
 enable dns<br />
 enable mssfixupNotice how we specify the real network interface ne0 to pppoe (with double quotes), and that i use &#8220;max 1492&#8243; for the MTU value, as suggested by many people. Also, no value is specified for the MRU, the PPP network address translation is not enabled, the magic &#8220;mssfixup&#8221; is enabled and i use the &#8220;add!&#8221; command instead of plain &#8220;add&#8221; (suggested by Chris Pockele).</p>
<p>Also notice that the authname and authkey fields don&#8217;t contain double-quote characters. You should put in there your own ISP identification and password. Some ISPs require authname to have a full identification (e.g. &#8220;username@sympatico.ca&#8221;), while other ISPs will want to have only &#8220;username&#8221; in the authname field. Experiment.</p>
<p>Robert Jameson (thanks Robert!) reports that some ISPs require you to specify the pppoe service you want. This is done on the &#8220;set device&#8221; line. For example: </p>
<p>      set device &#8220;!/usr/sbin/pppoe -n Shasta_1 -i ne0&#8243;</p>
<p>VERY IMPORTANT!</p>
<p>For some reason, the routes setup automatically by ppp at linkup time were not correctly defined prior to OpenBSD version 3.0. The MTU&#8217;s were wrong, leading to all sorts of subtle problems. This is now fixed, and we can safely use the &#8220;add default HISADDR&#8221; command in the ppp config file, with no special route commands at all in the ppp.linkup file. The MTUs will be properly set to 1492 on all the routes which go through the external interface. </p>
<p>The command &#8220;netstat -rn&#8221; confirms this:</p>
<p>pcreal# netstat -rn<br />
Routing tables</p>
<p>Internet:<br />
Destination        Gateway            Flags     Refs     Use    Mtu  Interface<br />
default            65.92.185.1        UGS         3    13423   1492   tun0<br />
65.92.185.1        65.92.185.97       UH          1        0   1492   tun0<br />
127.0.0.1          127.0.0.1          UH          1     1045  33224   lo0<br />
192.168.1/24       link#2             UC          0        0   1500   ne1<br />
192.168.1.1        0:e0:18:90:a7:c7   UHL         3    10475   1500   ne1<br />
&#8230;</p>
<p>A friend from Australia (thanks Doug!) suggested i clarify the following points:</p>
<p>(1) The 64.229.x.x adresses will NOT be the same in your setup! Those are the adress blocks of my PPPoE service provider (Sympatico). Your own setup will use, most likely, different address blocks.</p>
<p>(2) The ppp daemon creates a virtual network interface (&#8220;tun0&#8243;) out of thin air. This virtual network interface is internally linked to the actual physical interface (&#8220;ne0&#8243; in my system), but you will never have to deal directly with &#8220;ne0&#8243; in your configuration files. For example, the firewall rules are written with the virtual &#8220;tun0&#8243; interface, not the physical &#8220;ne0&#8243; interface. In my setup, the internal interface is &#8220;ne1&#8243;, and the external interface is &#8220;tun0&#8243;. Here is Doug&#8217;s analogy with the Windows world:</p>
<p>&#8220;&#8230; think of the PPPoE adaptor like the dialup adaptor in a Windows<br />
control panel. it doesn&#8217;t really exist but you gotta have it&#8230;&#8221;(3) The ppp daemon takes care of automatically assigning the name servers and the routes. Consequently, make sure there is no file &#8220;/etc/mygate&#8221;, and bear in mind that &#8220;/etc/resolv.conf&#8221; will be automatically generated as well, at connection time. This has the advantage that you don&#8217;t need to know anything about the details of your connection (name server adresses, etc&#8230;) to your ISP. Your user ID and password are sufficient, as the ppp daemon will negociate with the server and obtain the information it needs to open the connection.</p>
<p>(4) Since the ppp daemon will take are of the external network interface, you don&#8217;t need a &#8220;/etc/hostname.ne0&#8243; file. However, you do need a file to describe your internal network interface (in my case, &#8220;ne1&#8243;):</p>
<p>pcreal# cat /etc/hostname.ne1<br />
inet 192.168.1.2 255.255.255.0 NONENormally, this file should have been built by the setup program of OpenBSD, but if not, you must manually put it there and replace the &#8220;192.168.1.2&#8243; with whatever address you want your gateway to have as seen from your internal network.</p>
<p>Another friend, from France (thanks Xavier!), sent me this ascii picture of the network connections:</p>
<p>           |                                      |<br />
   internet| ====> |DSL Modem| ====>|server|=====>|LAN (HUB)<br />
           |                   tun0           ne1 |<br />
           |                   =ne0               |</p>
<p>Note: I consider this PPP/PPPoE setup to be a work in progress. I continually discover new things about it&#8230; so, please bear with me and do send me your feedback about your own experience regarding PPP/PPPoE. It really is a pain, but apparently we will be stuck with it for a long long time, so we might as well learn how to tame the thing!</p>
<p>Second Boot<br />
reboot &#8230; your machine should boot correctly. You won&#8217;t have internet access yet because the ppp program is not activated. If you want to try it out, just issue </p>
<p>ifconfig ne0 up<br />
ppp -ddial pppoeand ping/telnet away. Don&#8217;t worry if you get &#8220;carrier settings ignored&#8221;, or &#8220;change route failed&#8221; messages. Be careful because at this point you have no firewall rules set, so you are very vulnerable. Also, make sure your xDSL modem is plugged in the correct ethernet card&#8230;</p>
<p>If all works well, then you should kill the &#8220;ppp&#8221; process. Only restart it when the firewall rules are in place.</p>
<p>The afterboot phase<br />
Follow the instructions obtained by issuing the &#8220;man afterboot&#8221; command. Actually, quoting FAQ section 2.3, here is a list of the most useful man pages for new users: </p>
<p>     * [15]afterboot(8) &#8211; things to check after the first complete boot<br />
     * [16]boot(8) &#8211; system boot strapping procedures<br />
     * [17]passwd.conf(5) &#8211; format of the password configuration file<br />
     * [18]adduser_proc(8) &#8211; procedure for adding new users<br />
     * [19]adduser(8) &#8211; command for adding new users<br />
     * [20]vipw(8) &#8211; edit the pass word file<br />
     * [21]man(1) &#8211; display the on-line manual pages<br />
     * [22]sendbug(1) &#8211; send a problem report (PR) about OpenBSD to a<br />
       central support site.<br />
     * [23]disklabel(8) &#8211; Read and write disk pack label.<br />
     * [24]ifconfig(8) &#8211; configure network interface parameters.<br />
     * [25]route(8) &#8211; manually manipulate the routing tables.<br />
     * [26]netstat(1) &#8211; show network status.<br />
     * [27]reboot, halt(8) &#8211; Stopping and restarting the system.<br />
     * [28]shutdown(8) &#8211; close down the system at a given time.<br />
     * [29]boot_config(8) &#8211; how to change kernel configuration at boot</p>
<p>One of the first things you should do at this point is to add an unprivileged user and make him member of the wheel group. This is because, for security reasons, it is never a good idea to log in directly as root. The preferred way to gain root privileges is to login as a wheel member, and then use the &#8220;su -&#8221; command to gain root privileges.</p>
<p>OpenBSD will not prevent you from logging in directly as root, but will warn you every time against doing it.</p>
<p>Have fun!</p>
<p>Firewall and NAT rule sets<br />
This is a tricky one. Many people earn a good living just by knowing how to write firewall rule sets! Moreover, the whole packet filter and NAT code was completely rewritten from scratch in OpenBSD 3.0. It is now called &#8220;pf&#8221;, and is completely free of any external licensing strings so we will always have the latest, fully audited versions in future OpenBSD releases.<br />
Here are my own pf rules, in all their glory. They were heavily influenced by the various man pages and HOW-TO&#8217;s pertaining to &#8220;pf&#8221;. Be aware that they might be either too restrictive, or not enough, depending on your context. My philosophy about this is to disallow everything by default, and only open whatever is known to be useful. This restrictive ruleset will prevent ftp from working correctly, from the firewall itself. However, the ftp proxy currently available will work correctly for client machines located on the intranet. </p>
<p>Don&#8217;t forget to send me your tips for better rules&#8230; Thanks!</p>
<p>/etc/nat.conf<br />
nat on tun0 from 192.168.1.0/24 to any -> tun0<br />
rdr on ne1 proto tcp from any to any port 21 -> 127.0.0.1 port 8081</p>
<p>/etc/pf.conf<br />
#&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br />
# PF ruleset, 11 dec. 2001<br />
#<br />
# Liberally adapted from the pf man page, the OpenBSD &#8220;Network How-To&#8221;,<br />
# and my own rulesets.<br />
#&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;</p>
<p>#&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br />
# Definitions<br />
Ext = &#8220;tun0&#8243;            # External interface<br />
Int = &#8220;ne1&#8243;             # Internal interface<br />
Loop = &#8220;lo0&#8243;            # Loopback interface<br />
IntNet=&#8221;192.168.1.0/24&#8243; # Internal network</p>
<p>NoRoute = &#8220;{ 127.0.0.1/8, 192.168.0.0/16, 172.16.0.0/12, 10.0.0.0/8, 255.255.255.255/32 }&#8221;</p>
<p>InServicesTCP = &#8220;{ ssh, smtp, auth, http, https, pop3 }&#8221;<br />
#InServicesUDP = &#8220;{ domain }&#8221;<br />
OutServicesTCP = &#8220;{ http, https, smtp, pop3, whois, domain, ssh, telnet, ftp, ftp-data, nntp, auth, ntp }&#8221;<br />
OutServicesUDP = &#8220;{ ntp, domain }&#8221;</p>
<p>XMMS = &#8220;{ 6000, 7500, 8000, 8004, 8044, 8034, 8052, 8038, 8010, 8400, 8014, 8026, 8048, \<br />
          8002, 8024, 8028, 8080 }&#8221;<br />
RealAudio = &#8220;{ 554, 7070, 8080 }&#8221;</p>
<p>#&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br />
#&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br />
# Clean up fragmented and abnormal packets<br />
# By default in pf, packets which contain IP options are blocked. Good.<br />
scrub in on { $Ext, $Int } all<br />
#&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;</p>
<p>#&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
# Defaults<br />
# block and log everything<br />
block             out log on $Ext           all<br />
block             in  log on $Ext           all<br />
block return-rst  out log on $Ext proto tcp all<br />
block return-rst  in  log on $Ext proto tcp all<br />
block return-icmp out log on $Ext proto udp all<br />
block return-icmp in  log on $Ext proto udp all</p>
<p>block in  quick inet6 all<br />
block out quick inet6 all<br />
#&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-</p>
<p>#&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br />
# loopback packets left unmolested<br />
pass in quick on $Loop all<br />
pass out quick on $Loop all<br />
#&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;</p>
<p>#&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
# Immediate blocks<br />
# fuzz any &#8216;nmap&#8217; attempt<br />
block in log quick on $Ext inet proto tcp from any to any flags FUP/FUP<br />
block in log quick on $Ext inet proto tcp from any to any flags SF/SFRA<br />
block in log quick on $Ext inet proto tcp from any to any flags /SFRA</p>
<p># don&#8217;t allow anyone to spoof non-routeable addresses<br />
block in log quick on $Ext from $NoRoute to any<br />
block out log quick on $Ext from any to $NoRoute</p>
<p># silently drop broadcasts (cable modem noise)<br />
block in quick on $Ext from any to 255.255.255.255<br />
#&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-</p>
<p>#&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
# PASS rules</p>
<p># ALL  &#8212; we don&#8217;t normally do that. For debugging only.<br />
#pass out quick on $Ext all keep state</p>
<p># pass in data mode connections for ftp-proxy running on this host.<br />
pass in quick on $Ext inet proto tcp from any to any port > 49151 flags S/SA keep state</p>
<p># ICMP<br />
pass out     quick on $Ext inet proto icmp all icmp-type 8 code 0 keep state<br />
pass in  log quick on $Ext inet proto icmp all icmp-type 8 code 0 keep state</p>
<p># Services we provide to the outside world<br />
#pass in quick on $Ext inet proto udp from any to any port $InServicesUDP keep state<br />
pass in quick on $Ext inet proto tcp from any to any port $InServicesTCP flags S/SA keep state</p>
<p># Standard services we want to access in the world<br />
pass out quick on $Ext inet proto udp from any to any port $OutServicesUDP keep state<br />
pass out quick on $Ext inet proto tcp from any to any port $OutServicesTCP flags S/SA modulate state</p>
<p># Special services<br />
pass out quick on $Ext inet proto tcp from any to any port $XMMS flags S/SA modulate state<br />
pass out quick on $Ext inet proto tcp from any to any port $RealAudio flags S/SA modulate state<br />
IMPORTANT: Note that the &#8220;rdr&#8221; rule in the NAT file refers to the INTERNAL network interface. Its purpose is to redirect all ftp-data requests from the intranet to be redirected to the ftp-proxy on the firewall. Then the ftp-proxy channels those into ports 49152-65535, and outputs them on the internet. This is why we have this hole in the firewall starting at port 49152. I know, it is in the IN direction, but that is how passive ftp works&#8230; It is quite a broken protocol.<br />
That&#8217;s it! Nothing too painful, as you see. Since pf is a stateful inspection firewall, we can keep our ingress rules to a strict minimum. Notice the sheer elegance of the ruleset, with all services defined at once in a single IN or OUT rule. </p>
<p>One last thing: in order to automagically enable your firewall when the link comes up, you can put the following lines in the /etc/ppp/ppp.linkup file. Notice the extra space in front of each &#8220;!&#8221; character:</p>
<p>MYADDR:<br />
 ! sh -c &#8220;/sbin/ifconfig pflog0 up&#8221;<br />
 ! sh -c &#8220;/sbin/pfctl -e -l tun0 -F all -O aggressive -R /etc/pf.conf -N /etc/nat.conf&#8221;</p>
<p>The FTP proxy<br />
If you want tight security, and no FTP available on your intranet, simply remove the hole at 49152, and the &#8220;rdr&#8221; command in the file &#8220;nat.conf&#8221;. However, if you want to be able to use FTP from the intranet, then you must keep those, as well as enable the &#8220;ftp-proxy&#8221; service in inetd. Simply add this line to inetd.conf : </p>
<p>8081            stream  tcp     nowait  root    /usr/libexec/ftp-proxy  ftp-proxyDon&#8217;t forget that you still won&#8217;t be able to do FTP&#8217;ing from the firewall itself, when the packet filtering is enabled. Hopefully, it is very easy to temporarily disable pf with the command &#8220;pfctl -d&#8221;, and later re-enable it with the command &#8220;pfctl -e&#8221;. This comes in handy when we install packages from ftp.openbsd.org with the command &#8220;pkg_add&#8221;. </p>
<p>We are confident that ftp-proxy will improve with time and eventually dynamically manipulate the state tables of the firewall in order to open/close needed connections on-the-fly. </p>
<p>Addinc stuff to /etc/rc.local<br />
This is where our custom startup instructions go. Those things are started while the kernel is in secure level 1. If you need anything started in a lower security level, modify /etc/rc.securelevel instead. In order to start up PPPoE correctly, I added this at the end of my /etc/rc.local : </p>
<p>ifconfig ne0 up<br />
route flush<br />
ppp -ddial pppoe</p>
<p>This starts PPP, PPPoE, the firewall and the NAT translator (because the firewall and the NAT are started automatically in the ppp.linkup file). If you&#8217;re curious, you can reboot at this point, and confirm that you have a fully firewalled internet access:</p>
<p>pcreal# ifconfig -a<br />
lo0: flags=8009 mtu 33224<br />
        inet6 fe80::1%lo0 prefixlen 64 scopeid 0&#215;5<br />
        inet6 ::1 prefixlen 128<br />
        inet 127.0.0.1 netmask 0xff000000<br />
lo1: flags=8008 mtu 33224<br />
ne0: flags=8863 mtu 1500<br />
        media: Ethernet autoselect (10baseT)<br />
        inet6 fe80::240:f4ff:fe2b:190d%ne0 prefixlen 64 scopeid 0&#215;1<br />
ne1: flags=8863 mtu 1500<br />
        media: Ethernet autoselect (10baseT)<br />
        inet 192.168.1.2 netmask 0xffffff00 broadcast 192.168.1.255<br />
        inet6 fe80::240:f4ff:fe2b:16b1%ne1 prefixlen 64 scopeid 0&#215;2<br />
pflog0: flags=141 mtu 33224<br />
sl0: flags=c010 mtu 296<br />
sl1: flags=c010 mtu 296<br />
ppp0: flags=8010 mtu 1500<br />
ppp1: flags=8010 mtu 1500<br />
tun0: flags=8011 mtu 1492<br />
        inet 65.92.185.97 &#8211;> 65.92.185.1 netmask 0xffffffff<br />
tun1: flags=10 mtu 3000<br />
enc0: flags=0<> mtu 1536<br />
bridge0: flags=0<> mtu 1500<br />
bridge1: flags=0<> mtu 1500<br />
vlan0: flags=0<> mtu 1500<br />
vlan1: flags=0<> mtu 1500<br />
gre0: flags=8010 mtu 1450<br />
gif0: flags=8010 mtu 1280<br />
gif1: flags=8010 mtu 1280<br />
gif2: flags=8010 mtu 1280<br />
gif3: flags=8010 mtu 1280</p>
<p>pcreal# pfctl -sr<br />
@0 scrub in on ne1 all<br />
@1 scrub in on tun0 all<br />
@2 block out log on tun0 all<br />
@3 block in log on tun0 all<br />
@4 block return-rst out log on tun0 proto tcp all<br />
@5 block return-rst in log on tun0 proto tcp all<br />
@6 block return-icmp out log on tun0 proto udp all<br />
@7 block return-icmp in log on tun0 proto udp all<br />
@8 block in quick inet6 all<br />
@9 block out quick inet6 all<br />
@10 pass in quick on lo0 all<br />
@11 pass out quick on lo0 all<br />
@12 block in log quick on tun0 inet proto tcp all flags FPU/FPU<br />
@13 block in log quick on tun0 inet proto tcp all flags FS/FSRA<br />
@14 block in log quick on tun0 inet proto tcp all flags /FSRA<br />
@15 block in log quick on tun0 inet from 255.255.255.255/32 to any<br />
@16 block in log quick on tun0 inet from 10.0.0.0/8 to any<br />
@17 block in log quick on tun0 inet from 172.16.0.0/12 to any<br />
@18 block in log quick on tun0 inet from 192.168.0.0/16 to any<br />
@19 block in log quick on tun0 inet from 127.0.0.1/8 to any<br />
@20 block out log quick on tun0 inet from any to 255.255.255.255/32<br />
@21 block out log quick on tun0 inet from any to 10.0.0.0/8<br />
@22 block out log quick on tun0 inet from any to 172.16.0.0/12<br />
@23 block out log quick on tun0 inet from any to 192.168.0.0/16<br />
@24 block out log quick on tun0 inet from any to 127.0.0.1/8<br />
@25 block in quick on tun0 inet from any to 255.255.255.255/32<br />
@26 pass in quick on tun0 inet proto tcp from any to any port > 49151 flags S/SA keep state<br />
@27 pass out quick on tun0 inet proto icmp all icmp-type echoreq code 0 keep state<br />
@28 pass in log quick on tun0 inet proto icmp all icmp-type echoreq code 0 keep state<br />
@29 pass in quick on tun0 inet proto tcp from any to any port = pop3 flags S/SA keep state<br />
@30 pass in quick on tun0 inet proto tcp from any to any port = https flags S/SA keep state<br />
@31 pass in quick on tun0 inet proto tcp from any to any port = www flags S/SA keep state<br />
@32 pass in quick on tun0 inet proto tcp from any to any port = auth flags S/SA keep state<br />
@33 pass in quick on tun0 inet proto tcp from any to any port = smtp flags S/SA keep state<br />
@34 pass in quick on tun0 inet proto tcp from any to any port = ssh flags S/SA keep state<br />
@35 pass out quick on tun0 inet proto udp from any to any port = domain keep state<br />
@36 pass out quick on tun0 inet proto udp from any to any port = ntp keep state<br />
@37 pass out quick on tun0 inet proto tcp from any to any port = ntp flags S/SA modulate state<br />
@38 pass out quick on tun0 inet proto tcp from any to any port = auth flags S/SA modulate state<br />
@39 pass out quick on tun0 inet proto tcp from any to any port = nntp flags S/SA modulate state<br />
@40 pass out quick on tun0 inet proto tcp from any to any port = ftp-data flags S/SA modulate state<br />
@41 pass out quick on tun0 inet proto tcp from any to any port = ftp flags S/SA modulate state<br />
@42 pass out quick on tun0 inet proto tcp from any to any port = telnet flags S/SA modulate state<br />
@43 pass out quick on tun0 inet proto tcp from any to any port = ssh flags S/SA modulate state<br />
@44 pass out quick on tun0 inet proto tcp from any to any port = domain flags S/SA modulate state<br />
@45 pass out quick on tun0 inet proto tcp from any to any port = whois flags S/SA modulate state<br />
@46 pass out quick on tun0 inet proto tcp from any to any port = pop3 flags S/SA modulate state<br />
@47 pass out quick on tun0 inet proto tcp from any to any port = smtp flags S/SA modulate state<br />
@48 pass out quick on tun0 inet proto tcp from any to any port = https flags S/SA modulate state<br />
@49 pass out quick on tun0 inet proto tcp from any to any port = www flags S/SA modulate state<br />
&#8230;<br />
@72 pass out quick on tun0 inet proto tcp from any to any port = 6000 flags S/SA modulate state<br />
@73 pass out quick on tun0 inet proto tcp from any to any port = 8080 flags S/SA modulate state<br />
@74 pass out quick on tun0 inet proto tcp from any to any port = 7070 flags S/SA modulate state<br />
@75 pass out quick on tun0 inet proto tcp from any to any port = 554 flags S/SA modulate state</p>
<p>pflogd and tcpdump<br />
With the new pf firewall code comes a new way to log firewalled packets and look at them. The log is actually taken care of by a separate daemon ( pflogd ) which should be started in &#8220;ppp.linkup&#8221; and killed in &#8220;ppp.linkdown&#8221;. This daemon puts its data in a special log file ( /var/log/pflog ) which is not directly human readable, for performance reasons. To get a dump of the file, simply issue the command &#8220;tcpdump -n -e -ttt -r /var/log/pflog&#8221;, or , if you want a real-time display of the logs, simply issue &#8220;tcpdump -n -e -ttt -i pflog0&#8243;. </p>
<p>The Dynamic DNS<br />
Dynamic DNS is a wonderful thing. Basically, you just go to a dyndns provider like those nice people and 10 minutes later you have your very own domain, for free. In order to make that domain dynamically follow your IP address changes, you must use a special client program which must be called whenever your IP changes. </p>
<p>Until recently I liked ddup, but now i use ipcheck. The latter is truly compliant with all of dyndns&#8217;s client specification, and maintains its state automatically in system files. You will have to install the python package if you use &#8220;ipcheck&#8221;. Also, you&#8217;ll need your user ID and password from the dyndns provider.</p>
<p>One more advice: it is perfectly acceptable to have more than one domain pointing at the same IP address. Remember this when choosing one or more domain names&#8230;</p>
<p>Keeping your xDSL link alive 24/7<br />
xDSL connections are very reliable, but ISP&#8217;s are not <img src='http://www.evanjiang.net.cn/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' />  For many reasons unfathomable, you will sometimes lose your connection. There are many methods of re-establishing that connection automatically, and i&#8217;ll describe here the one i use. </p>
<p>The Method<br />
Make sure you initialise ppp with the &#8220;-ddial&#8221; command, and NOT the &#8220;-background&#8221; command&#8230;</p>
<p>The automatic restart of the ppp link is handled by ppp itself (using the &#8220;-ddial&#8221; command), which is quite handy. This leaves us with the dyndns updates, which are performed intelligently by ipcheck.py . An easy way of doing it is to create an executable file named &#8220;do_ipcheck&#8221; which contains this:</p>
<p>#!/bin/sh<br />
/usr/local/sbin/ipcheck.py -q -d /etc/ipcheck -i tun0  -w Username Password DomainName1,DomainName2with your own Username, Password and Domain names, of course. Then, all you have to do is to add the following line to crontab:</p>
<p>*/5     *       *       *       *       /usr/local/sbin/do_ipcheckAlso, don&#8217;t forget to create the directory /etc/ipcheck and make sure your /etc/ppp/ppp.linkup file looks like this:</p>
<p>MYADDR:<br />
 ! sh -c &#8220;/sbin/ifconfig pflog0 up&#8221;<br />
 ! sh -c &#8220;/sbin/pfctl -e -l tun0 -F all -O aggressive -R /etc/pf.conf -N /etc/nat.conf&#8221;<br />
 ! sh -c &#8220;/usr/local/sbin/ResetNTP.sh&#8221;<br />
 !bg sh -c &#8220;/usr/local/sbin/do_ipcheck&#8221;<br />
You can call &#8220;do_ipcheck&#8221; from &#8220;ppp.linkup&#8221; &#8230; however, you must use the special &#8220;!bg&#8221; construct, in order to instruct ppp to fork it in the background. Nasty stuff happens if you don&#8217;t use &#8220;!bg&#8221; here. Big thanks to Dan for this update!</p>
<p>This setup should garantee the proper restart of the firewall &#038; ipnat each time the ppp link is brought up again.</p>
<p>Apache<br />
Now would be a good time to install your htdocs directory. The way i like to do this is to mount a read-only NFS file system over the current htdocs. This is easily accomplished by adding a line like this to your /etc/fstab : </p>
<p>192.168.1.1:/usr/local/Apache/htdocs /var/www/htdocs nfs ro  Moreover, the web logs are kept in /var/www/logs. Interesting stuff.</p>
<p>We are in full virus season and i&#8217;m sure your log files will fill up as fast as mine with useless garbage, once your Apache is up. In order to remove some clutter, you can filter out the virus attacks and channel them to a specialized attack_log file. Simply insert the following lines into your /var/www/conf/httpd.conf file: </p>
<p>SetEnvIf Request_URI &#8220;^/default.ida&#8221; attacks # For Code Red<br />
SetEnvIf Request_URI &#8220;^/scripts&#8221; attacks # For nimda<br />
SetEnvIf Request_URI &#8220;^/c/winnt&#8221; attacks # &#8230; ditto all the way down<br />
SetEnvIf Request_URI &#8220;^/_mem_bin&#8221; attacks<br />
SetEnvIf Request_URI &#8220;^/_vti_bin&#8221; attacks<br />
SetEnvIf Request_URI &#8220;^/MSADC&#8221; attacks<br />
SetEnvIf Request_URI &#8220;^/msadc&#8221; attacks<br />
SetEnvIf Request_URI &#8220;^/d/winnt&#8221; attacks</p>
<p>CustomLog /var/www/logs/access_log combined env=!attacks<br />
CustomLog /var/www/logs/attack_log combined env=attacks<br />
This will send all virus-related requests to &#8220;attack_log&#8221;, while still logging other activities normally in access_log.</p>
<p>Named<br />
Someone (Chavous P. Camp, thanks!) sent me advice on optimizing &#8220;named&#8221; for faster throughput. He recommends to add two lines to the &#8220;/var/named/named.boot&#8221; file:</p>
<p>options forward-only<br />
forwarders ip.addresses.of.ISPs.nameservers.separated.by.spacesThis forces named to always use the same servers for dns. If your ISP&#8217;s servers are always on fixed IP adresses, then it works well. However, ISP&#8217;s who force you to use PPPoE will also sometimes change dynamically the DNS servers allocated to you (in &#8220;/etc/resolv.conf&#8221;, automatically created by ppp at startup). In that case, there is no garantee that the name servers you hardwire as forwarders will always be available.</p>
<p>Removing IPv6 related errors<br />
The GENERIC OpenBSD kernel comes precompiled with IP v6 support. This is the reason why you might see many &#8220;/bsd: tun0: not multicast capable, IPv6 not enabled&#8221; error messages in your logs. Those messages are completely harmless and do not alter the performance of your system. However, should you want to get rid of them, you can simply remove IPv6 support from your kernel by modifying &#8220;/usr/src/sys/conf/GENERIC&#8221; and removing the &#8220;option INET6&#8243; line. Then recompile your kernel in the usual way. Thanks Chavous for this info!</p>
<p>Setting permissions of scripts &#038; config files<br />
Another excellent suggestion from Chavous. Scripts and config files with passwords should have their permissions changed to 500 (for scripts) or 400 (for config files), for greater security. This includes &#8220;ppp.conf&#8221;, &#8220;do_ipcheck&#8221;, etc&#8230;</p>
<p>The NTP daemon<br />
The ntpd daemon is not installed by default. However, you can download it as a package, and install it with the pkg_add command. Since you have internet connectivity by now, you can download &#038; install it in a single command:</p>
<p>pkg_add ftp://ftp.openbsd.org/pub/OpenBSD/3.0/packages/i386/ntp-4.1.71.tgz Moreover, you will need a valid /etc/ntp.conf file:</p>
<p>pcreal# cat /etc/ntp.conf<br />
server 128.100.102.201<br />
driftfile /etc/ntp.driftFeel free to use any other atomic time server if you want. Also, the drift file will be created &#038; maintained automagically.</p>
<p>Important tip from Chavous:<br />
=========================================<br />
I found my ntp server would refuse to synchronize after a reboot because it<br />
had no route to the time server.  This was, of course, because PPPoE is<br />
loaded AFTER ntp, and sometimes the PPPoE negotiation after a reboot takes a<br />
few seconds.</p>
<p>Anyway, here is something you might want to add as a suggestion:</p>
<p>Turn ntpd OFF in the rc.conf file<br />
add this line to your ppp.linkup file &#8211; AFTER the firewall initialization</p>
<p> ! sh -c &#8220;/etc/ppp/ResetNTP.sh&#8221;</p>
<p>That script should then contain:</p>
<p>#!/bin/sh<br />
if [ -f /var/run/ntpd.pid ]; then<br />
        kill `cat /var/run/ntpd.pid`<br />
        rm -f /var/run/ntpd.pid<br />
fi<br />
/usr/local/sbin/ntpd -p /var/run/ntpd.pid</p>
<p>(as I have said before, remind your readers that this script is executed as<br />
root and should therefore be chmod 444 or less)</p>
<p>This kills the NTP daemon (if it exists) and restarts it.  On boot, it would<br />
not be restarted, but what if the link went down for a while? The ntp daemon<br />
would give up and stop sending queries because it couldn&#8217;t get a route to<br />
host.</p>
<p>REALLY, the ntp daemon SHOULD NOT stop querying the server just because it<br />
can&#8217;t get a route to the host, but it seems to be written as such now<br />
anyway.  I haven&#8217;t tested the ntp daemon over a long period of time (more<br />
than about a day) so I don&#8217;t know if it just gives up for some arbitrarily<br />
long period (MORE than a day) and then tries again. I seriously doubt it<br />
does, because a day is a LONG time.  This workaround isn&#8217;t ideal, because<br />
for time consistency, one would want the time server to stay running at all<br />
times.  According to the ntpd documentation, ntpd tends to become more<br />
accurate the longer it runs.</p>
<p>Chavous<br />
=========================================</p>
<p>Sendmail<br />
If you have followed all the steps of the recipe so far, your sendmail should be configured &#038; ready to receive mail from the internet, however you should know a few more things about this. First, if you want your gateway to receive mail for more than one domain, you must make sure the all fully qualified domains are setup as aliases for your host in the file /etc/hosts.</p>
<p>The mail popper<br />
All ingress mail is received &#038; kept on the gateway untill some POP client on the intranet gets it. I use the &#8220;popa3d&#8221; server package because it is written with security in mind. It is now part of the main OpenBSD 3.0 distribution, so you don&#8217;t have to download it as a separate package. Simply enable it in the file /etc/inetd.conf and you should be up &#038; running. </p>
<p>The installed packages<br />
Just to do a quick check, here are the packages i have installed on my system:</p>
<p>pcreal# pkg_info<br />
gmp-3.1.1          library for arbitrary precision arithmetic<br />
python-2.1.1       interpreted object-oriented programming language<br />
ntp-4.1.71         network time protocol implementation<br />
libiconv-1.7       character set conversion library<br />
gettext-0.10.40    GNU gettext<br />
mhash-0.8.9        strong hash library<br />
libtool-1.3.5p3    generic shared library support script<br />
postgresql-7.1.3   PostgreSQL RDBMS<br />
libmcrypt-2.4.15   interface to access block/stream encryption algorithms<br />
c-client-4.40p1    University of Washington&#8217;s c-client mail access routines<br />
php4-4.0.6p1-gettext-imap-mhash-no_x11-mcrypt-postgresql server-side HTML-embedded scripting language</p>
<p>The Secure Shell<br />
The secure shell looks &#038; feels exactly like telnet, except that all communication between the client and the server is encrypted. It is the only possible way to access your gateway, because the telnet daemon is disabled by default. Usage is very simple: just like telnet! </p>
<p>[real@pcreal Projects]$ ssh 192.168.1.2<br />
real@192.168.1.2&#8242;s password:<br />
Warning: Remote host denied X11 forwarding.<br />
Last login: Sun Nov  5 12:58:08 2000 from 192.168.1.1<br />
OpenBSD 2.7 (GENERIC) #1: Thu Nov  2 16:05:11 GMT 2000</p>
<p>pcreal:real {39}</p>
<p>Once you are logged in as an unprivileged user, member of the wheel group, you can use su to gain superuser privileges:</p>
<p>pcreal:real {39} su -<br />
Password:<br />
Terminal type? [nxterm]<br />
pcreal#</p>
<p>The log files<br />
There are many log files of high interest maintained automatically by your gateway. It is usually convenient to look at them with the &#8220;tail -f&#8221; command. The files i look at often are: </p>
<p>/var/log/messages<br />
/var/log/maillog<br />
/var/log/secure<br />
/var/www/logs/access_log</p>
<p>Moreover, you can grab interesting info about the blocked packets on your firewall with the &#8220;ipmon&#8221; utility.</p>
<p>There are many other log files available for all kinds of things. Dig around to find more about them.</p>
<p>Installing IPSEC<br />
Dave Cook has kindly provided us with a good description of how to install IPSEC on your OpenBSD boxen: file:///H:/OPENBSD/ipsec.pdf, in PDF (Acrobat) format. Be aware that it is a largish file (440K), and it might take some time for your Acrobat reader to load afterwards, so don&#8217;t hit the link repeatedly, it won&#8217;t make things load faster&#8230; <img src='http://www.evanjiang.net.cn/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p>Apply the security patches!<br />
Security patches are published there. APPLY THEM RELIGIOUSLY!<br />
It is not really difficult, but you will need a copy of the complete, original source tree of the distribution. The compressed source archives are to be found with the distribution files. These are the 3.0 source files:</p>
<p>      src.tar.gz      64447 Kb    Tue May  1 16:18:00 2001 Unix Tape Archive<br />
      srcsys.tar.gz   13837 Kb    Tue May  1 16:18:00 2001 Unix Tape ArchiveThey total about 80 MB. Once you have them, simply unpack them to &#8216;/usr/src&#8217; and &#8216;/usr/src/sys&#8217;. The latter is the kernel proper.</p>
<p>Once you have your source tree, you can start downloading the patches, and apply them. Usually, all the currently published patches are availble in a single file. For 3.0, it is there. After that, simply watch the patch page from time to time, to keep updated.</p>
<p>Patches are either applied to an application (in &#8216;/usr/src&#8217;), or to the kernel ( in &#8216;/usr/src/sys&#8217;). Since all kernel patches should be installed, the thing i do is to apply all the kernel patches in one session, then i recompile my kernel once.</p>
<p>The applications you don&#8217;t use (e.g. &#8216;X11&#8242;, for example) don&#8217;t have to be patched &#038; recompiled.</p>
<p>Reboot and enjoy!<br />
You should be able to ssh into your new gateway from any machine on the intranet. </p>
]]></content:encoded>
			<wfw:commentRss>http://www.evanjiang.net.cn/archives/845.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>分享mail服务器mysql数据库备份脚本</title>
		<link>http://www.evanjiang.net.cn/archives/252.html</link>
		<comments>http://www.evanjiang.net.cn/archives/252.html#comments</comments>
		<pubDate>Fri, 16 Jan 2009 07:54:33 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[mail]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[shell]]></category>
		<category><![CDATA[shell 备份脚本 mysql]]></category>

		<guid isPermaLink="false">http://www.hunttech.com.cn/wpblog/?p=252</guid>
		<description><![CDATA[<p>功能：备份mysql数据库中mail的数据库数据,并用gz压缩，先备份到本地，然后自动上传到指定的ftp服务器,备份日志email到指定的邮箱
</p>

?View Code SHELL[root@mail cron.daily]# cat mailmysql_backup_ftp
#!/bin/bash
#Mysql Autobackup Shell
&#160;
#DB env
dbuser=root
dbpasswd=root
dbserver=localhost
dbname=extmail
#dbopt=--opt
backupdir=/home/mysql-backup/
&#160;
#FTP 0 is disable,1 is enable
copytoftp=1
ftpserver=10.1.1.8
ftpuser=admin
ftppasswd=admin
fileprefix=extmail
dumpfilename=$backupdir`date +%F`.sql
newfile=$fileprefix-`date +%F`.gz
keepdays=16
&#160;
#Backup log
logfile=/tmp/mysqldump.log
logtmp=/tmp/mysqldump.tmp
&#160;
#mail 0 is diable,1 is enable
mailenable=1
mailaddress=ruochen0926@hotmail.com
&#160;
#Backup script
#===============================================
if [ ! -d $backupdir ]
then
        echo &#34;$backupdir is not exist, then make ...&#34; &#38;gt; $logfile
        mkdir -p $backupdir
fi
echo [...]]]></description>
			<content:encoded><![CDATA[<p>功能：备份mysql数据库中mail的数据库数据,并用gz压缩，先备份到本地，然后自动上传到指定的ftp服务器,备份日志email到指定的邮箱<br />
<span id="more-252"></span></p>

<div class="wp_codebox_msgheader wp_codebox_hide"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p252code2'); return false;">View Code</a> SHELL</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p2522"><td class="code" id="p252code2"><pre class="shell" style="font-family:monospace;">[root@mail cron.daily]# cat mailmysql_backup_ftp
#!/bin/bash
#Mysql Autobackup Shell
&nbsp;
#DB env
dbuser=root
dbpasswd=root
dbserver=localhost
dbname=extmail
#dbopt=--opt
backupdir=/home/mysql-backup/
&nbsp;
#FTP 0 is disable,1 is enable
copytoftp=1
ftpserver=10.1.1.8
ftpuser=admin
ftppasswd=admin
fileprefix=extmail
dumpfilename=$backupdir`date +%F`.sql
newfile=$fileprefix-`date +%F`.gz
keepdays=16
&nbsp;
#Backup log
logfile=/tmp/mysqldump.log
logtmp=/tmp/mysqldump.tmp
&nbsp;
#mail 0 is diable,1 is enable
mailenable=1
mailaddress=ruochen0926@hotmail.com
&nbsp;
#Backup script
#===============================================
if [ ! -d $backupdir ]
then
        echo &quot;$backupdir is not exist, then make ...&quot; &amp;gt; $logfile
        mkdir -p $backupdir
fi
echo &quot;start====================================&amp;gt;&quot;&amp;gt;$logfile
echo &quot;Beginning backup `date '+%F %T'`&quot; &amp;gt;&amp;gt;$logfile
echo &quot;Delete $keepdays days ago files ...&quot; &amp;gt;&amp;gt;$logfile
find $backupdir -name $fileprefix* -mtime +$keepdays -fls $logtmp -exec rm {} \;
echo &quot;Deleted Backup File Is :&quot;&amp;gt;&amp;gt;$logfile
cat $logtmp &amp;gt;&amp;gt;$logfile
echo &quot;Delete old file Success!&quot; &amp;gt;&amp;gt;$logfile
if [ -f $backupdir$newfile ]
then
echo &quot;$newfile backup exist, backup stop ...&quot; &amp;gt;&amp;gt;$logfile
else
        if [ -z $dbpasswd ]
        then
#        mysqldump -u$dbuser -h$dbserver $dbopt $dbname &amp;gt;$dumpfilename
        /usr/bin/mysqldump -u$dbuser -h$dbserver $dbopt $dbname &amp;gt;$dumpfilename
        else
#        /opt/lampp/bin/mysqldump -u$dbuser -p$dbpasswd -h$dbserver $dbopt $dbname | gzip &amp;gt; /opt/apache/mysqlbackup/$newfile
        /usr/bin/mysqldump -u$dbuser -p$dbpasswd -h$dbserver $dbopt $dbname | gzip &amp;gt; $backupdir/$newfile
        fi
#        tar czvf $backupdir$newfile $dumpfilename &amp;gt;&amp;gt;$logfile 2&amp;gt;&amp;amp;1
#        gzip $dumpfilename  $newfile  &amp;gt;&amp;gt;$logfile 2&amp;gt;&amp;amp;1
        echo &quot;$backupdir$newfile Backup Success!&quot; &amp;gt;&amp;gt;$logfile
        rm -fr $dumpfilename
&nbsp;
if [ $copytoftp = 1 ];  then
        if [ -z $ftpserver ];then
        echo &quot;Ftp Server not set,Copy to Ftp Failed ...&quot; &amp;gt;&amp;gt;$logfile
        exit 1
        elif [ -z $ftpuser ];then
        echo &quot;Ftp user not set, Copy to Ftp Failed ...&quot; &amp;gt;&amp;gt;$logfile
        exit 2
        elif [ -z $ftppasswd ]; then
        echo &quot;Ftp password not set, Copy to Ftp Failed ...&quot; &amp;gt;&amp;gt;$logfile
        exit 3
        else
        echo &quot;Start copy to Ftp server ....&quot; &amp;gt;&amp;gt; $logfile
ftp -n&amp;lt;&amp;gt;$logfile
echo &quot;End=======================================|&quot;&amp;gt;&amp;gt;$logfile
fi
&nbsp;
if [ $mailenable=1 ];
    then
      mail -s &quot;Mail Server Mysql Backup Status&quot; $mailaddress&amp;lt;$logfile
fi</pre></td></tr></table></div>

<p>
<!-- Begin alimama Adserver code -->
<script type="text/javascript"><!--
google_ad_client = "pub-8438729971248494";
/* 728x90, ������ 10-2-7 */
google_ad_slot = "4752526529";
google_ad_width = 728;
google_ad_height = 90;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
<!-- End Alimama Adserver code -->
</p>
]]></content:encoded>
			<wfw:commentRss>http://www.evanjiang.net.cn/archives/252.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Debian 4.0安装postfix邮件服务器</title>
		<link>http://www.evanjiang.net.cn/archives/121.html</link>
		<comments>http://www.evanjiang.net.cn/archives/121.html#comments</comments>
		<pubDate>Fri, 19 Dec 2008 13:24:09 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[debian linux]]></category>
		<category><![CDATA[mail]]></category>
		<category><![CDATA[debian postfix mail 服务器]]></category>

		<guid isPermaLink="false">http://www.hunttech.com.cn/wpblog/?p=121</guid>
		<description><![CDATA[<p> </p>
<p>安装nginx</p>
<p>tar -zxf nginx-0.7.26.tar.gz </p>
<p>cd nginx-0.7.26</p>
<p>apt-get install libpcre3-dev</p>
<p>apt-get install zlib1g-dev</p>
<p>apt-get install libssl-dev</p>
<p>./configure &#8211;prefix=/tmail/httpd &#8211;with-http_ssl_module  &#8211;with-http_sub_module  &#8211;with-http_gzip_static_module  &#8211;with-http_random_index_module &#8211;with-http_secure_link_module &#8211;with-http_stub_status_module</p>
<p>make &#38;&#38; make install</p>
<p></p>
<p>安装mysql</p>
<p>apt-get install libncurses5-dev</p>
<p>./configure &#8211;prefix=/tmail/mysql &#8211;with-charset=utf8  &#8211;with-extra-charsets=all &#8211;with-big-tables &#8211;with-mysqlmanager &#8211;with-pthread &#8211;enable-thread-safe-client</p>
<p>make</p>
<p>make install</p>
<p>安装php</p>
<p>apt-get install bzip2</p>
<p>bzip2 -cd php-5.2.6.tar.bz2 &#124; tar xf -</p>
<p>gzip -cd php-5.2.6-fpm-0.5.9.diff.gz &#124; patch -d php-5.2.6 -p1</p>
<p>cd php-5.2.6</p>
<p>apt-get install libxml2-dev</p>
<p>apt-get install libbz2-dev</p>
<p>apt-get install libjpeg62-dev</p>
<p>apt-get install libcurl3-dev</p>
<p>apt-get install [...]]]></description>
			<content:encoded><![CDATA[<p> </p>
<p>安装nginx</p>
<p>tar -zxf nginx-0.7.26.tar.gz </p>
<p>cd nginx-0.7.26</p>
<p>apt-get install libpcre3-dev</p>
<p>apt-get install zlib1g-dev</p>
<p>apt-get install libssl-dev</p>
<p>./configure &#8211;prefix=/tmail/httpd &#8211;with-http_ssl_module  &#8211;with-http_sub_module  &#8211;with-http_gzip_static_module  &#8211;with-http_random_index_module &#8211;with-http_secure_link_module &#8211;with-http_stub_status_module</p>
<p>make &amp;&amp; make install</p>
<p><span id="more-121"></span></p>
<p>安装mysql</p>
<p>apt-get install libncurses5-dev</p>
<p>./configure &#8211;prefix=/tmail/mysql &#8211;with-charset=utf8  &#8211;with-extra-charsets=all &#8211;with-big-tables &#8211;with-mysqlmanager &#8211;with-pthread &#8211;enable-thread-safe-client</p>
<p>make</p>
<p>make install</p>
<p>安装php</p>
<p>apt-get install bzip2</p>
<p>bzip2 -cd php-5.2.6.tar.bz2 | tar xf -</p>
<p>gzip -cd php-5.2.6-fpm-0.5.9.diff.gz | patch -d php-5.2.6 -p1</p>
<p>cd php-5.2.6</p>
<p>apt-get install libxml2-dev</p>
<p>apt-get install libbz2-dev</p>
<p>apt-get install libjpeg62-dev</p>
<p>apt-get install libcurl3-dev</p>
<p>apt-get install libpng12-dev</p>
<p>apt-get install libmcrypt-dev</p>
<p>./configure &#8211;prefix=/tmail/httpd/php &#8211;with-mysql=/tmail/mysql &#8211;with-mysqli=/tmail/mysql/bin/mysql_config &#8211;enable-fastcgi &#8211;enable-sockets &#8211;enable-ftp &#8211;enable-zip &#8211;enable-mbstring &#8211;enable-mbregex &#8211;enable-calendar &#8211;with-curl=/usr/include &#8211;with-curlwrappers &#8211;disable-debug &#8211;enable-inline-optimization &#8211;with-zlib &#8211;with-gd &#8211;with-kerberos &#8211;with-gettext &#8211;enable-force-cgi-redirect &#8211;with-jpeg-dir=/usr/include &#8211;with-png-dir=/usr/include &#8211;with-bz2 &#8211;enable-pcntl &#8211;with-iconv &#8211;enable-fpm &#8211;with-mcrypt</p>
<p>make</p>
<p>make install</p>
<p> 
<!-- Begin alimama Adserver code -->
<script type="text/javascript"><!--
google_ad_client = "pub-8438729971248494";
/* 728x90, ������ 10-2-7 */
google_ad_slot = "4752526529";
google_ad_width = 728;
google_ad_height = 90;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
<!-- End Alimama Adserver code -->
</p>
<p> </p>
<p>./mysql_install_db</p>
<p>adduser vmail &#8211;uid 1003 &#8211;home /dev/null  &#8211;disabled-password &#8211;disabled-login</p>
<p>addgroup mysql &#8211;system</p>
<p>adduser mysql &#8211;system &#8211;gid 104 &#8211;home /dev/null &#8211;disabled-password &#8211;disabled-login</p>
<p> </p>
<p>/tmail/mysql/bin/mysqladmin -u root password &#8216;hing4585&#8242;</p>
<p> </p>
<p> </p>
<p>./mysql_install_db</p>
<p> </p>
<p> </p>
<p>安装cyrus-sasl</p>
<p> </p>
<p>tar -zxf ../src/cyrus-sasl-2.1.22.tar.gz </p>
<p>cd cyrus-sasl-2.1.22/</p>
<p>patch &lt; ../../src/patch-linux </p>
<p>LDFLAGS=&#8221;-lcrypt&#8221; ./configure &#8211;prefix=/tmail/sasl2 &#8211;disable-anon -enable-plain &#8211;enable-login &#8211;enable-sql &#8211;with-mysql=/tmail/mysql &#8211;with-mysql-includes=/tmail/mysql/include/mysql &#8211;with-mysql-libs=/tmail/mysql/lib/mysql &#8211;with-authdaemond=/tmail/authlib/var/socket</p>
<p>make</p>
<p>make install</p>
<p> </p>
<p>安装postfix</p>
<p> </p>
<p>groupadd -g 12345 postfix</p>
<p>useradd -u 12345 -g 12345 postfix -d /dev/null -s /bin/false</p>
<p>groupadd -g 54321 postdrop</p>
<p> </p>
<p>apt-get install libdb4.3-dev</p>
<p> </p>
<p>make -f Makefile.init makefiles &#8216;AUXLIBS=-L/tmail/mysql/lib/mysql -lmysqlclient -lz -lm -L/tmail/sasl2/lib -lsasl2 -lssl -lcrypto&#8217; &#8216;CCARGS=-DHAS_MYSQL -I/tmail/mysql/include/mysql -DUSE_CYRUS_SASL -DUSE_SASL_AUTH -I/tmail/sasl2/include/sasl -DUSE_TLS \</p>
<p>-DHAS_MYSQL -I/tmail/mysql/include \</p>
<p>-DDEF_COMMAND_DIR=\&#8221;/tmail/postfix/sbin\&#8221; \</p>
<p>-DDEF_DAEMON_DIR=\&#8221;/tmail/postfix/libexec\&#8221; \</p>
<p>-DDEF_PROGRAM_DIR=\&#8221;/tmail/postfix/libexec\&#8221; \</p>
<p>-DDEF_QUEUE_DIR=\&#8221;/tmail/postfix/spool\&#8221; \</p>
<p>-DDEF_CONFIG_DIR=\&#8221;/tmail/postfix/etc\&#8221; \</p>
<p>-DDEF_SENDMAIL_PATH=\&#8221;/tmail/postfix/sbin/sendmail\&#8221; \</p>
<p>-DDEF_MAILQ_PATH=\&#8221;/tmail/postfix/bin/mailq\&#8221; \</p>
<p>-DDEF_NEWALIAS_PATH=\&#8221;/tmail/postfix/bin/newaliases\&#8221; \</p>
<p>-DDEF_SAMPLE_DIR=\&#8221;/tmail/postfix/doc/sample\&#8221; &#8216;</p>
<p> </p>
<p>make</p>
<p> </p>
<p>ldconfig /tmail/mysql/lib/mysql</p>
<p> </p>
<p>sh postfix-install -non-interactive \</p>
<p>install_root=/ \</p>
<p>config_directory=/tmail/postfix/etc \</p>
<p>daemon_directory=/tmail/postfix/libexec \</p>
<p>command_directory=/tmail/postfix/sbin \</p>
<p>queue_directory=/tmail/postfix/spool \</p>
<p>sendmail_path=/tmail/postfix/sbin/sendmail \</p>
<p>newaliases_path=/tmail/postfix/bin/newaliases \</p>
<p>mailq_path=/tmail/postfix/bin/mailq \</p>
<p>mail_owner=postfix \</p>
<p>setgid_group=postdrop \</p>
<p>manpage_directory=/tmail/postfix/man \</p>
<p>sample_directory=/tmail/postfix/doc/sample \</p>
<p>readme_directory=/tmail/postfix/doc/README_FILES </p>
<p> </p>
<p>安装courier-authlib</p>
<p> </p>
<p>tar -jxf ../src/courier-authlib-0.60.2.tar.bz2 </p>
<p>PATH=$PATH:/tmail/mysql/bin</p>
<p>export PATH</p>
<p>cd courier-authlib-0.60.2/</p>
<p>./configure &#8211;prefix=/tmail/courier/authlib &#8211;without-authuserdb &#8211;without-authpam  &#8211;without-authldap &#8211;without-authpwd  &#8211;without-authshadow &#8211;without-authpgsql &#8211;with-mysql-libs=/tmail/mysql/lib/mysql &#8211;with-mysql-includes=/tmail/mysql/include/mysql </p>
<p> </p>
<p>make</p>
<p>make install</p>
<p>make install-migrate</p>
<p>make install-configure</p>
<p> </p>
<p> </p>
<p>安装courier-imap</p>
<p>tar -jxf ../src/courier-imap-4.3.0.tar.bz2 </p>
<p> </p>
<p>apt-get install  libgdbm-dev</p>
<p>cd courier-imap-4.3.0/</p>
<p>COURIERAUTHCONFIG=/tmail/courier/authlib/bin/courierauthconfig</p>
<p>export COURIERAUTHCONFIG</p>
<p>./configure &#8211;prefix=/tmail/courier/imapd &#8211;silent &#8211;without-authpgsql &#8211;without-ipv6 &#8211;disable-root-check </p>
<p>cp /tmail/courier/authlib/include/* /usr/include/</p>
<p>make</p>
<p>make install</p>
<p>make install-configure</p>
<p> </p>
<p>安装Maildrop</p>
<p> </p>
<p>./configure &#8211;prefix=/tmail/courier/maildrop &#8211;silent  &#8211;mandir=/tmail/courier/man &#8211;enable-syslog=1 &#8211;enable-maildrop-uid=vmail &#8211;enable-maildrop-gid=vmail &#8211;enable-maildropmysql &#8211;disable-maildropldap &#8211;with-mysqlconfig=/tmail/courier/maildrop/etc/maildrop.cf &#8211;enable-maildirquota &#8211;disable-userdb &#8211;enable-authlib=1 &#8211;enable-sendmail=/tmail/postfix/sbin/sendmail</p>
<p>useradd vmail -u 1003 -d /dev/null -s /sbin/nologin</p>
<p>make</p>
<p>make install</p>
<p>make install-strip</p>
<p> </p>
<p> </p>
<p>/tmail/courier/maildrop/bin/maildrop -v</p>
<p>maildrop 2.0.4 Copyright 1998-2005 Double Precision, Inc.</p>
<p>GDBM extensions enabled.</p>
<p>Courier Authentication Library extension enabled.</p>
<p>Maildir quota extension enabled.</p>
<p>This program is distributed under the terms of the GNU General Public</p>
<p>License. See COPYING for additional information.</p>
<p> </p>
<p> </p>
<p> </p>
<p>install Digest::SHA1</p>
<p>install HTML::Parser</p>
<p>install Net::DNS</p>
<p>install Mail::SPF</p>
<p>install Mail::SPF::Query</p>
<p>install IP::Country</p>
<p>install Razor2</p>
<p>install Net::Ident</p>
<p>install IO::Socket::INET6</p>
<p>install IO::Socket::SSL</p>
<p>install Compress::Zlib</p>
<p>install Mail::DomainKeys</p>
<p>install Mail::DKIM</p>
<p>install DBI</p>
<p>install LWP::UserAgent</p>
<p>install HTTP::Date</p>
<p>install Archive::Tar</p>
<p>install IO::Zlib</p>
<p>install Encode::Detect</p>
<p> </p>
<p> </p>
<p> </p>
<p>vi smtpd.conf</p>
<p>pwcheck_method: authdaemond</p>
<p>log_level: 3</p>
<p>mech_list: PLAIN LOGIN</p>
<p>authdaemond_path:/tmail/courier/authlib/var/spool/authdaemon/socket</p>
<p> </p>
<p> </p>
<p>vi authmysqlrc</p>
<p>MYSQL_CRYPT_PWFIELD<span> </span>password</p>
<p>MYSQL_DATABASE<span> </span>postfix</p>
<p>MYSQL_GID_FIELD<span> </span>&#8217;1003&#8242;</p>
<p>MYSQL_HOME_FIELD<span> </span>&#8216;/var/mail&#8217;</p>
<p>MYSQL_LOGIN_FIELD<span> </span>username</p>
<p>MYSQL_MAILDIR_FIELD<span> </span>CONCAT(&#8216;/var/mail/&#8217;,maildir)</p>
<p>MYSQL_NAME_FIELD<span> </span>name</p>
<p>MYSQL_OPT<span> </span>0</p>
<p>MYSQL_PASSWORD<span> </span>tmail</p>
<p>MYSQL_QUOTA_FIELD<span> </span>quota</p>
<p>MYSQL_SERVER<span> </span>localhost</p>
<p>MYSQL_UID_FIELD<span> </span>&#8217;1003&#8242;</p>
<p>MYSQL_USERNAME<span> </span>tmail</p>
<p>MYSQL_USER_TABLE<span> </span>mailbox</p>
<p> </p>
<p> </p>
<p> </p>
<p>vi relay-domains.cf</p>
<p> </p>
<p>(Who we relay mail for (as a backup mx))</p>
<p> </p>
<p>user            = tmail</p>
<p>password        = tmail</p>
<p>dbname          = postfix</p>
<p>hosts           = localhost</p>
<p>query = SELECT domain FROM domain WHERE domain = &#8216;%s&#8217; AND backupmx = 1</p>
<p> </p>
<p>vi virtual-alias-maps.cf</p>
<p> </p>
<p>(Think: /etc/aliases or similar)</p>
<p> </p>
<p>user             = tmail</p>
<p>password         = tmail</p>
<p>dbname           = postfix</p>
<p>hosts            = localhost</p>
<p>query = SELECT goto FROM alias WHERE address=&#8217;%s&#8217; AND active = 1</p>
<p> </p>
<p>vi virtual-domains.cf</p>
<p> </p>
<p>(Domains we accept mail for&#8230;)</p>
<p> </p>
<p>user        = tmail</p>
<p>password    = tmail</p>
<p>dbname      = postfix</p>
<p>hosts       = localhost</p>
<p>query = SELECT domain FROM domain WHERE domain=&#8217;%s&#8217; AND backupmx = false AND active = 1</p>
<p> </p>
<p>vi virtual-mailbox-limit-maps.cf</p>
<p> </p>
<p>(Only used if you&#8217;re checking quota etc)</p>
<p> </p>
<p>user = tmail</p>
<p>password = tmail</p>
<p>hosts = localhost</p>
<p>dbname = postfix</p>
<p>query = SELECT quota FROM mailbox WHERE username = &#8216;%s&#8217;</p>
<p> </p>
<p>vi virtual-mailbox-maps.cf</p>
<p> </p>
<p>user      = tmail</p>
<p>password  = tmail</p>
<p>dbname    = postfix</p>
<p>hosts     = localhost</p>
<p>query = SELECT maildir FROM mailbox WHERE username=&#8217;%s&#8217; AND active = 1</p>
<p> </p>
<p>smtpd_recipient_limit = 15</p>
<p>bounce_queue_lifetime = 12h</p>
<p>maximal_queue_lifetime = 24h</p>
<p> </p>
<p>myhostname = smtp.mx1.postfix.cn</p>
<p>smtp_helo_name = $myhostname</p>
<p>local_transport = virtual</p>
<p>mailbox_transport = virtual</p>
<p>#disable_dns_lookups = yes</p>
<p>smtpd_error_sleep_time = 0</p>
<p>smtpd_soft_error_limit = 10</p>
<p>smtpd_hard_error_limit = 20</p>
<p>default_process_limit = 500</p>
<p> </p>
<p> </p>
<p>virtual_mailbox_base = /var/mail</p>
<p> </p>
<p> </p>
<p>virtual_mailbox_domains = proxy:mysql:/tmail/postfix/etc/mysql/virtual-domains.cf</p>
<p> </p>
<p>virtual_mailbox_maps = proxy:mysql:/tmail/postfix/etc/mysql/virtual-mailbox-maps.cf</p>
<p>virtual_uid_maps = static:1003</p>
<p>virtual_gid_maps = static:1003</p>
<p> </p>
<p>virtual_alias_maps = proxy:mysql:/tmail/postfix/etc/mysql/virtual-alias-maps.cf</p>
<p> </p>
<p>relay_domains = proxy:mysql:/tmail/postfix/etc/mysql/relay-domains.cf</p>
<p>local_transport = virtual</p>
<p>local_recipient_maps = $virtual_mailbox_maps</p>
<p> </p>
<p>broken_sasl_auth_clients = yes</p>
<p>smtpd_recipient_restrictions = </p>
<p>  permit_mynetworks,</p>
<p>  permit_sasl_authenticated,</p>
<p>  reject_non_fqdn_hostname,</p>
<p>  reject_non_fqdn_sender,</p>
<p>  reject_non_fqdn_recipient,  </p>
<p>  reject_unauth_destination,</p>
<p>  reject_unauth_pipelining,   </p>
<p>  reject_invalid_hostname,</p>
<p> </p>
<p>smtpd_sasl_authenticated_header = yes</p>
<p>smtpd_sasl_auth_enable = yes</p>
<p>smtpd_sasl_security_options = noanonymous</p>
<p> </p>
<p> </p>
<p>smtpd_peername_lookup = no </p>
<p>smtpd_delay_reject = yes</p>
<p>smtpd_proxy_timeout = 180s</p>
<p>smtpd_helo_required = yes</p>
<p>strict_rfc821_envelopes = yes</p>
<p> </p>
<p> 
<!-- Begin alimama Adserver code -->
<script type="text/javascript"><!--
google_ad_client = "pub-8438729971248494";
/* 728x90, ������ 10-2-7 */
google_ad_slot = "4752526529";
google_ad_width = 728;
google_ad_height = 90;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
<!-- End Alimama Adserver code -->
</p>
<p>disable_vrfy_command=yes</p>
<p> </p>
<p> </p>
<p>/tmail/postfix/sbin/postmap -q test.com mysql:/tmail/postfix/etc/mysql/relay-domains.cf</p>
<p> </p>
<p> </p>
<p> </p>
<p>相关脚本</p>
<p>cat maildirdel.sh </p>
<p>#!/bin/bash</p>
<p>rm -rf /var/mail/$1/$2</p>
<p> </p>
<p> </p>
<p>cat mkmaildir.sh </p>
<p>#!/bin/bash</p>
<p>set -e</p>
<p>if [ ! -d /var/mail/$1 ]</p>
<p>then</p>
<p>mkdir -p /var/mail/$1</p>
<p>fi</p>
<p>chown -R vmail:vmail /var/mail/$1</p>
<p> </p>
<p>if [ ! -d /var/mail/$1/$2 ]</p>
<p>then</p>
<p>mkdir -p /var/mail/$1/$2</p>
<p>fi</p>
<p> </p>
<p>cd &#8220;/var/mail/$1&#8243;</p>
<p>/tmail/courier/maildrop/bin/maildirmake $2/Maildir/</p>
<p>chown -R vmail:vmail /var/mail/$1</p>
<p> </p>
<p> </p>
<p> postfixadmin</p>
<p>vi create_mailbox.php</p>
<p> </p>
<p>    294       $tQuota = $CONF['maxquota'];</p>
<p>    295         system(&#8220;/tmail/courier/maildrop/bin/mkmaildir.sh $fDomain &#8220;.$_POST['fUsername']);</p>
<p>    296 </p>
<p>    297       if ($fMail == &#8220;on&#8221;)</p>
<p> </p>
<p> </p>
<p>vi delete.php</p>
<p> </p>
<p>    107       $result = db_query (&#8220;DELETE FROM $table_alias WHERE address=&#8217;$fDelete&#8217; AND domain=&#8217;$fDomain&#8217;&#8221;);</p>
<p>    108         $userarray=explode(&#8220;@&#8221;,$fDelete);</p>
<p>    109         $user=$userarray[0];</p>
<p>    110         $domain=$userarray[1];</p>
<p>    111         system(&#8220;/tmail/courier/maildrop/bin/maildirdel.sh $domain $user&#8221;);</p>
]]></content:encoded>
			<wfw:commentRss>http://www.evanjiang.net.cn/archives/121.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
