<?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; openbsd unix</title>
	<atom:link href="http://www.evanjiang.net.cn/archives/category/operating_system/openbsd-unix/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>openbsd 4.5 livecd 试用心得</title>
		<link>http://www.evanjiang.net.cn/archives/1233.html</link>
		<comments>http://www.evanjiang.net.cn/archives/1233.html#comments</comments>
		<pubDate>Mon, 06 Jul 2009 16:09:24 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[openbsd unix]]></category>

		<guid isPermaLink="false">http://www.evanjiang.net.cn/archives/1233.html</guid>
		<description><![CDATA[<p>


 <p>昨天，无意在某个QQ群看到这条信息，有BSD fans 贴出一条openbsd live cd 的信息，列出OpenBSD 4.5 Live CD 的下载地址：ftp://bsd.pls.msu.edu/pub/livecd ，俺记得几年前，用过livecd 4.0 ，但由于没深入研究。所以印象不深。用了一两次就没再用。今天无意中看到这条信息。无意中又沟起俺对openbsd 的美好回忆。openbsd 是俺很喜欢的一种BSD系统。以前常用来作防火墙安全等研究。后来，就没再继续深入研究。今天又忽然心血来潮。想玩玩openbsd livecd .因为俺从openbsd3.8开始。就没怎样研究过openbsd 。今天，又忽然想玩一下。就在 那个网站下载livecd .俺下载到是xfce桌面的livcd .gz 压缩版本。才几百M。不大。。。下载完。俺就习惯用winrar解压。用vmware来安装与尝试。安装很需利。livecd 正常启动。启动提示设置root 与普通user账户的密码。设置密码。然后会提示你是选择终端login模式，还是桌面图形模式。俺一开始。顺便按了回车，系统就默认用终端来lgoin 。login后 ，俺习惯打入：startx 启动桌面。发觉桌面是熟悉的xfce桌面。。俺动了动mouse，发觉mouse很不灵活。很艰难地右击一下，弹出常用菜单，然后选了setting中的mouse setting ，将mouse 的灵敏度调到最右边。也是最高的位置。但发觉mouse的灵敏度还是很低。。。俺没时间，也没耐心断续玩下去。就顺手打开一个终端。运行halt 关机了事。。。到了晚上。。俺想着，总不能就这样对openbsd livecd 说声再见，总要看看mouse 反应不够灵敏的问题出在哪里吧?那俺又再一次运行livecd .到了选择login模式，这次。俺是直接选了图形login模式，跟着。弹出一个图形login窗口，输入root账号与密码后。进入一个xfce桌面。俺动了动mouse，发觉这回mouse灵活很多，基本不影晌使用。。俺随便看看，发觉这些LIVECD 整合的软件比较少。除了一个firefox3.06外，其它都是桌面的基本设置。例如mouse ,keyborad等等。。俺打开firefox，想尝试打开网页。发现无法打开网页。随手打开一个终端，运行ifconfig .发 觉没有自动获取到ip&#8230;俺了想想，想可能是openbsdlivecd 是用vmware安装的。而俺的winxp 是无线上网。而 vmware没有开发nat转换功能。所以。livecd 没有获得ip，并且将网络信号转换出去，所以无法上网。。。俺再四周看看。发觉这个xfce 桌面的openbsd4.5 livecd 整合的软件太少。没什么吸引力。就随手halt掉。就没再弄。。。</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>昨天，无意在某个QQ群看到这条信息，有BSD fans 贴出一条openbsd live cd 的信息，列出OpenBSD 4.5 Live CD 的下载地址：ftp://bsd.pls.msu.edu/pub/livecd ，俺记得几年前，用过livecd 4.0 ，但由于没深入研究。所以印象不深。用了一两次就没再用。今天无意中看到这条信息。无意中又沟起俺对openbsd 的美好回忆。openbsd 是俺很喜欢的一种BSD系统。以前常用来作防火墙安全等研究。后来，就没再继续深入研究。今天又忽然心血来潮。想玩玩openbsd livecd .因为俺从openbsd3.8开始。就没怎样研究过openbsd 。今天，又忽然想玩一下。就在 那个网站下载livecd .俺下载到是xfce桌面的livcd .gz 压缩版本。才几百M。不大。。。下载完。俺就习惯用winrar解压。用vmware来安装与尝试。安装很需利。livecd 正常启动。启动提示设置root 与普通user账户的密码。设置密码。然后会提示你是选择终端login模式，还是桌面图形模式。俺一开始。顺便按了回车，系统就默认用终端来lgoin 。login后 ，俺习惯打入：startx 启动桌面。发觉桌面是熟悉的xfce桌面。。俺动了动mouse，发觉mouse很不灵活。很艰难地右击一下，弹出常用菜单，然后选了setting中的mouse setting ，将mouse 的灵敏度调到最右边。也是最高的位置。但发觉mouse的灵敏度还是很低。。。俺没时间，也没耐心断续玩下去。就顺手打开一个终端。运行halt 关机了事。。。到了晚上。。俺想着，总不能就这样对openbsd livecd 说声再见，总要看看mouse 反应不够灵敏的问题出在哪里吧?那俺又再一次运行livecd .到了选择login模式，这次。俺是直接选了图形login模式，跟着。弹出一个图形login窗口，输入root账号与密码后。进入一个xfce桌面。俺动了动mouse，发觉这回mouse灵活很多，基本不影晌使用。。俺随便看看，发觉这些LIVECD 整合的软件比较少。除了一个firefox3.06外，其它都是桌面的基本设置。例如mouse ,keyborad等等。。俺打开firefox，想尝试打开网页。发现无法打开网页。随手打开一个终端，运行ifconfig .发 觉没有自动获取到ip&#8230;俺了想想，想可能是openbsdlivecd 是用vmware安装的。而俺的winxp 是无线上网。而 vmware没有开发nat转换功能。所以。livecd 没有获得ip，并且将网络信号转换出去，所以无法上网。。。俺再四周看看。发觉这个xfce 桌面的openbsd4.5 livecd 整合的软件太少。没什么吸引力。就随手halt掉。就没再弄。。。</p>
]]></content:encoded>
			<wfw:commentRss>http://www.evanjiang.net.cn/archives/1233.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Openbsd 4.5 live cd 下载网址以及制作过程</title>
		<link>http://www.evanjiang.net.cn/archives/1209.html</link>
		<comments>http://www.evanjiang.net.cn/archives/1209.html#comments</comments>
		<pubDate>Sat, 04 Jul 2009 02:53:01 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[openbsd unix]]></category>

		<guid isPermaLink="false">http://www.evanjiang.net.cn/archives/1209.html</guid>
		<description><![CDATA[<p style="float: right;margin: 4px;">


</p> <p>OpenBSD 4.5 Live CD</p>
<p>ftp://bsd.pls.msu.edu/pub/livecd</p>
<p>另符一篇livecd 的制作过程文章。仅作参考</p>
<p>OpenBSD LiveCD制作过程
    刚开始接触OpenBSD时，我就很想使用OpenBSD LiveCD，但没找到。今年1月那时起就想</p>
<p>自己做一个LiveCD，一个新年一过， 就将它放下，现在又重新开始制作，今天写这篇文章</p>
<p>只是我思路的一个开始，制作的LiveCD，还不完善，我会后续为其改进。 </p>
<p>    制作过程：
一、	准备工作：
1、	一个能运行OpenBSD系统的所需要的必备文件，这里我就没像一些mini LiveCD那样</p>
<p>对系统进行剔牛肉进行精减，只是将一个能运行的系统的所有文件进行备份。而且如果备份</p>
<p>的文件不大， 那制作出的LiveCD就很小， 我们就可以将这个备份的系统文件也一起放进CD</p>
<p>中， 到时就可以用这个LiveCD安装系统，
2、	OpenBSD系统的源程序，我们在制作过程中需要编译光盘镜像。 </p>
<p>二、	将备份的系统文件解开到一个目录下，我将以这个目录作为LiveCD的根目录制作CD</p>
<p>，如/usr/live/。
三、	将OpenBSD源程序解开到/usr/src下，然后：
1、	安装必须的程序：
# cd /usr/src/distrib/crunch/crunchgen
#make; make install
#cd /usr/src/distrib/crunch/crunchide
#make; make install </p>
<p>2、	定制内核
内核文件是/usr/src/sys/arch/i386/conf/RAMDISK_CD，我们需要对这个文件进行修改，其</p>
<p>中有三行最重要，一定不能少：
 option  MFS
 option  UNION
 config  bsd root on cd0a
LiveCD运行于MFS上，而且它的根目录在CD上。 </p>
<p>还有其它一些选项如：
 option SMALL_KERNEL
 option NO_PROPLICE
 option TIMEZONE=0
 option DST=0
 [...]]]></description>
			<content:encoded><![CDATA[<p>OpenBSD 4.5 Live CD</p>
<p>ftp://bsd.pls.msu.edu/pub/livecd</p>
<p>另符一篇livecd 的制作过程文章。仅作参考</p>
<p>OpenBSD LiveCD制作过程<br />
    刚开始接触OpenBSD时，我就很想使用OpenBSD LiveCD，但没找到。今年1月那时起就想</p>
<p>自己做一个LiveCD，一个新年一过， 就将它放下，现在又重新开始制作，今天写这篇文章</p>
<p>只是我思路的一个开始，制作的LiveCD，还不完善，我会后续为其改进。 </p>
<p>    制作过程：<br />
一、	准备工作：<br />
1、	一个能运行OpenBSD系统的所需要的必备文件，这里我就没像一些mini LiveCD那样</p>
<p>对系统进行剔牛肉进行精减，只是将一个能运行的系统的所有文件进行备份。而且如果备份</p>
<p>的文件不大， 那制作出的LiveCD就很小， 我们就可以将这个备份的系统文件也一起放进CD</p>
<p>中， 到时就可以用这个LiveCD安装系统，<br />
2、	OpenBSD系统的源程序，我们在制作过程中需要编译光盘镜像。 </p>
<p>二、	将备份的系统文件解开到一个目录下，我将以这个目录作为LiveCD的根目录制作CD</p>
<p>，如/usr/live/。<br />
三、	将OpenBSD源程序解开到/usr/src下，然后：<br />
1、	安装必须的程序：<br />
# cd /usr/src/distrib/crunch/crunchgen<br />
#make; make install<br />
#cd /usr/src/distrib/crunch/crunchide<br />
#make; make install </p>
<p>2、	定制内核<br />
内核文件是/usr/src/sys/arch/i386/conf/RAMDISK_CD，我们需要对这个文件进行修改，其</p>
<p>中有三行最重要，一定不能少：<br />
 option  MFS<br />
 option  UNION<br />
 config  bsd root on cd0a<br />
LiveCD运行于MFS上，而且它的根目录在CD上。 </p>
<p>还有其它一些选项如：<br />
 option SMALL_KERNEL<br />
 option NO_PROPLICE<br />
 option TIMEZONE=0<br />
 option DST=0<br />
 option RAMDISK_HOOKS<br />
 option MINIROOTSIZE=3560 </p>
<p>需要将一些多余的东西删除，因此这个内核大小控制在2.88M以内， 太大时会编译失败。我</p>
<p>的RAMDISK_CD是将/usr/src/sys/arch/i386/conf/GENERIC 和/usr/src/sys/conf/GENERIC</p>
<p>这两个文章合并然后去掉一些内容整理出来的。 </p>
<p>3、	编译内核<br />
# cd /usr/src/distrib/i386/ramdisk_cd<br />
#make<br />
成功后会在目录下生成cdrom36.fs这个文件，我们将这个文件复制到制作LiveCD的目录</p>
<p>下/usr/live/。 </p>
<p>四、	修改/usr/live/etc中的各类文件<br />
1、fstab </p>
<p>/dev/cd0a / cd9660 ro,noatime 0 0</p>
<p>swap	/dev	mfs	rw,noatime,union,-s=16384	0 0</p>
<p>swap	/tmp	mfs	rw,nodev,noexec,nosuid,noatime,-s=32768	0 0</p>
<p>swap	/etc	mfs	rw,noatime,-s=16384	0 0</p>
<p>swap	/var	mfs	rw,noatime,-s=16384	0 0</p>
<p>swap	/home mfs	rw,noatime,-s=16384	0 0</p>
<p>以前我没发现fstab的功能居然如此强大, 以为它只能mount已分好的挂载点, 原来它在光盘</p>
<p>系统中还可以在启动时自动挂载写入fstab中的mfs. </p>
<p>2、rc<br />
   OpenBSD启动时首先读取这个文件， 如果找不到它就会读取根目录下的/.profile文件进</p>
<p>行初始配置。<br />
   修改/etc/rc文件, 三个地方修改 </p>
<p>#	$OpenBSD: rc,v 1.251 2004/08/21 08:17:28 hshoexer Exp $</p>
<p># System startup script run by init on autoboot</p>
<p># or after single-user.</p>
<p># Output and error are redirected to console by init,</p>
<p># and the console is the controlling terminal.</p>
<p># Subroutines (have to come first).</p>
<p># Strip comments (and leading/trailing whitespace if IFS is set)</p>
<p># from a file and spew to stdout<br />
<span id="more-1209"></span></p>
<p>stripcom() {</p>
<p>	local _file=&#8221;$1&#8243;</p>
<p>	local _line</p>
<p>	{</p>
<p>		while read _line ; do</p>
<p>			_line=${_line%%#*}		# strip comments</p>
<p>			test -z &#8220;$_line&#8221; &#038;&#038; continue</p>
<p>			echo $_line</p>
<p>		done</p>
<p>	} < $_file</p>
<p>}</p>
<p># End subroutines</p>
<p>stty status '^T'</p>
<p># Set shell to ignore SIGINT (2), but not children;</p>
<p># shell catches SIGQUIT (3) and returns to single user after fsck.</p>
<p>trap : 2</p>
<p>trap : 3	# shouldn't be needed</p>
<p>HOME=/; export HOME</p>
<p>PATH=/sbin:/bin:/usr/sbin:/usr/bin</p>
<p>export PATH</p>
<p>if [ $1x = shutdownx ]; then</p>
<p>	dd if=/dev/urandom of=/var/db/host.random bs=1024 count=64 >;/dev/null </p>
<p>2>;&#038;1</p>
<p>	chmod 600 /var/db/host.random >;/dev/null 2>;&#038;1</p>
<p>	if [ $? -eq 0 -a -f /etc/rc.shutdown ]; then</p>
<p>		echo /etc/rc.shutdown in progress&#8230;</p>
<p>		. /etc/rc.shutdown</p>
<p>		echo /etc/rc.shutdown complete.</p>
<p>		# bring carp interfaces down gracefully</p>
<p>		for hn in /etc/hostname.carp[0-9]*; do</p>
<p>			# Strip off /etc/hostname. prefix</p>
<p>			if=${hn#/etc/hostname.}</p>
<p>			test &#8220;$if&#8221; = &#8220;carp[0-9]*&#8221; &#038;&#038; continue</p>
<p>			ifconfig $if >; /dev/null 2>;&#038;1</p>
<p>			if [ "$?" != "0" ]; then</p>
<p>				ifconfig $if down</p>
<p>			fi</p>
<p>		done</p>
<p>		if [ "X${powerdown}" = X"YES" ]; then</p>
<p>			exit 2</p>
<p>		fi</p>
<p>	else</p>
<p>		echo single user: not running /etc/rc.shutdown</p>
<p>	fi</p>
<p>	exit 0</p>
<p>fi</p>
<p># Configure ccd devices.</p>
<p>if [ -f /etc/ccd.conf ]; then</p>
<p>	ccdconfig -C</p>
<p>fi</p>
<p># Configure raid devices.</p>
<p>for dev in 0 1 2 3; do</p>
<p>	if [ -f /etc/raid$dev.conf ]; then</p>
<p>		raidctl -c /etc/raid$dev.conf raid$dev</p>
<p>	fi</p>
<p>done</p>
<p># Check parity on raid devices.</p>
<p>raidctl -P all</p>
<p>swapctl -A -t blk</p>
<p>if [ -e /fastboot ]; then</p>
<p>	echo &#8220;Fast boot: skipping disk checks.&#8221;</p>
<p>elif [ $1x = autobootx ]; then</p>
<p>	echo &#8220;Automatic boot in progress: starting file system checks.&#8221;</p>
<p>#	fsck –p      这一行要注释掉</p>
<p>	case $? in</p>
<p>	0)</p>
<p>		;;</p>
<p>	2)</p>
<p>		exit 1</p>
<p>		;;</p>
<p>	4)</p>
<p>		echo &#8220;Rebooting&#8230;&#8221;</p>
<p>		reboot</p>
<p>		echo &#8220;Reboot failed; help!&#8221;</p>
<p>		exit 1</p>
<p>		;;</p>
<p> <img src='http://www.evanjiang.net.cn/wp-includes/images/smilies/icon_cool.gif' alt='8)' class='wp-smiley' /> </p>
<p>		echo &#8220;Automatic file system check failed; help!&#8221;</p>
<p>		exit 1</p>
<p>		;;</p>
<p>	12)</p>
<p>		echo &#8220;Boot interrupted.&#8221;</p>
<p>		exit 1</p>
<p>		;;</p>
<p>	130)</p>
<p>		# interrupt before catcher installed</p>
<p>		exit 1</p>
<p>		;;</p>
<p>	*)</p>
<p>		echo &#8220;Unknown error; help!&#8221;</p>
<p>		exit 1</p>
<p>		;;</p>
<p>	esac</p>
<p>fi</p>
<p>trap &#8220;echo &#8216;Boot interrupted.&#8217;; exit 1&#8243; 3</p>
<p>umount -a >;/dev/null 2>;&#038;1</p>
<p>mount -a -t nonfs</p>
<p>mount -uw /		# root on nfs requires this, others aren&#8217;t hurt</p>
<p>rm -f /fastboot		# XXX (root now writeable)</p>
<p>这里需要在/dev下建立三个设备点, 不然后一步tar出错, 系统启动时会问题多多</p>
<p>mknod /dev/stdout c 22 1</p>
<p>mknod /dev/stdin c 22 0</p>
<p>mknod /dev/stderr c 22 2</p>
<p>if [ -f /mfs/mfs.tgz ]; then</p>
<p>	tar zxpf /mfs/mfs.tgz -C /</p>
<p>	echo &#8216;Fixed up mfs from /mfs/mfs.tgz&#8217;</p>
<p>fi</p>
<p>chmod 755 /dev /etc /var</p>
<p>chmod a+rwx,a+t /tmp</p>
<p># set flags on ttys.  (do early, in case they use tty for SLIP in netstart)</p>
<p>echo &#8216;setting tty flags&#8217;</p>
<p>ttyflags -a</p>
<p>if [ "X${pf}" != X"NO" ]; then</p>
<p>	RULES=&#8221;block all&#8221;</p>
<p>	RULES=&#8221;$RULES\npass on lo0&#8243;</p>
<p>	RULES=&#8221;$RULES\npass in proto tcp from any to any port 22 keep state&#8221;</p>
<p>	RULES=&#8221;$RULES\npass out proto { tcp, udp } from any to any port 53 keep </p>
<p>state&#8221;</p>
<p>	RULES=&#8221;$RULES\npass out inet proto icmp all icmp-type echoreq keep </p>
<p>state&#8221;</p>
<p>	RULES=&#8221;$RULES\npass out inet6 proto icmp6 all icmp6-type routersol&#8221;</p>
<p>	RULES=&#8221;$RULES\npass in inet6 proto icmp6 all icmp6-type routeradv&#8221;</p>
<p>	RULES=&#8221;$RULES\npass proto { pfsync, carp }&#8221;</p>
<p>	case `sysctl vfs.mounts.nfs 2>;/dev/null` in</p>
<p>	*[1-9]*)</p>
<p>		# don&#8217;t kill NFS</p>
<p>		RULES=&#8221;scrub in all no-df\n$RULES&#8221;</p>
<p>		RULES=&#8221;$RULES\npass in proto udp from any port { 111, 2049 } to </p>
<p>any&#8221;</p>
<p>		RULES=&#8221;$RULES\npass out proto udp from any to any port { 111, </p>
<p>2049 }&#8221;</p>
<p>		;;</p>
<p>	esac</p>
<p>	echo $RULES | pfctl -f &#8211; -e</p>
<p>fi</p>
<p>if [ -f /etc/sysctl.conf ]; then</p>
<p>(</p>
<p>	# delete comments and blank lines</p>
<p>	set &#8212; `stripcom /etc/sysctl.conf`</p>
<p>	while [ $# -ge 1 ] ; do</p>
<p>		sysctl $1</p>
<p>		shift</p>
<p>	done</p>
<p>)</p>
<p>fi</p>
<p># set hostname, turn on network</p>
<p>echo &#8220;Setting Network&#8230;&#8230;&#8221;     修改这里, 加入我写的setnetwork脚本, </p>
<p>. /etc/setnetwork                     这样网络设置在每台机上都可以重新设置而不是</p>
<p>更改文件.</p>
<p>3、上一步最后有一个setnetwork脚本，这一步写出。我的脚本编写不会， 只好从其它地方</p>
<p>抄过来，有一些错误，需要请高手改写。这个文件有点大， 贴在最后吧！ </p>
<p>4、将一些网络配置的文件删除如：hosts, mygate等。上一步的network在启动时会生成这</p>
<p>些配置文件。 </p>
<p>五、	备份几个目录，在4.3 rc脚本中的MFS部分那个文件。<br />
在/usr/live/ LiveCD根目录下建立文件夹：mfs 然后：<br />
# tar cvzfp mfs/mfs.tgz dev etc home var </p>
<p>六、	制作ISO镜像：<br />
# cd /usr/live<br />
# mkhybrid –b cdrom36.fs –c boot.catalog –R –v –o /usr/OpenBSD-LiveCD.iso </p>
<p>/usr/live </p>
<p>现在制作完成， 你可以用虚拟机测试这个生成的ISO镜像。<br />
参考网上许多文章, 这里就不一一列出来, 感谢那些大哥写出那么好的教程. </p>
<p>我现在还有几个问题需要解决，主要是MFS这方面的，另外shell脚本的错误也需要大家来解</p>
<p>决。<br />
设置网络用的setnetwork脚本:<br />
setnetwork： </p>
<p>#!/bin/sh</p>
<p>get_dkdevs() {</p>
<p>	bsort `sed -ne &#8220;${MDDISKDEVS:-/^[sw]d[0-9][0-9]* /s/ .*//p}&#8221; </p>
<p>/var/run/dmesg.boot`</p>
<p>}</p>
<p>get_cddevs() {</p>
<p>	bsort `sed -ne &#8220;${MDCDDEVS:-/^cd[0-9][0-9]* /s/ .*//p}&#8221; </p>
<p>/var/run/dmesg.boot`</p>
<p>}</p>
<p>get_ifdevs() {</p>
<p>	ifconfig -a \</p>
<p>	    | egrep -v &#8216;^[[:space:]]|</p>
<p>(bridge|enc|gif|gre|lo|pflog|pfsync|ppp|sl|tun|vlan)[[:digit:]]+:&#8217; \</p>
<p>	    | sed -ne &#8216;s/^\(.*\):.*/\1/p&#8217;</p>
<p>}</p>
<p>askpass() {</p>
<p>	set -o noglob</p>
<p>	stty -echo</p>
<p>	read resp?&#8221;$1 &#8221;</p>
<p>	stty echo</p>
<p>	set +o noglob</p>
<p>	echo</p>
<p>}</p>
<p>ask() {</p>
<p>	local _question=$1 _default=$2</p>
<p>	set -o noglob</p>
<p>	while : ; do</p>
<p>		echo -n &#8220;$_question &#8221;</p>
<p>		[[ -z $_default ]] || echo -n &#8220;[$_default] &#8221;</p>
<p>		read resp</p>
<p>		case $resp in</p>
<p>		!)	echo &#8220;Type &#8216;exit&#8217; to return to install.&#8221;</p>
<p>			sh</p>
<p>			;;</p>
<p>		!*)	eval ${resp#?}</p>
<p>			;;</p>
<p>		*)	: ${resp:=$_default}</p>
<p>			break</p>
<p>			;;</p>
<p>		esac</p>
<p>	done</p>
<p>	set +o noglob</p>
<p>}</p>
<p>ask_until() {</p>
<p>	resp=</p>
<p>	while [[ -z $resp ]] ; do</p>
<p>		ask &#8220;$1&#8243; &#8220;$2&#8243;</p>
<p>	done</p>
<p>}</p>
<p>ask_yn() {</p>
<p>	local _q=$1 _a=${2:-no} _resp</p>
<p>	typeset -l _resp</p>
<p>	while : ; do</p>
<p>		ask &#8220;$_q&#8221; &#8220;$_a&#8221;</p>
<p>		_resp=$resp</p>
<p>		case $_resp in</p>
<p>		y|yes)	resp=y ; return ;;</p>
<p>		n|no)	resp=n ; return ;;</p>
<p>		esac</p>
<p>	done</p>
<p> }</p>
<p>ask_which() {</p>
<p>	local _name=$1 _query=$2 _devs=$3 _defdev=$4 _err=$5</p>
<p>	set &#8212; $_devs</p>
<p>	if [[ $# -lt 1 ]]; then</p>
<p>		echo &#8220;${_err:=No ${_name}s found}.&#8221;</p>
<p>		resp=done</p>
<p>		return</p>
<p>	fi</p>
<p>	: ${_defdev:=$1}</p>
<p>	_devs=&#8221;$*&#8221;</p>
<p>	while : ; do</p>
<p>		ask &#8220;Available ${_name}s are: ${_devs}.\nWhich one ${_query}? </p>
<p>(or &#8216;done&#8217;)&#8221; &#8220;$_defdev&#8221;</p>
<p>		[[ $resp == done ]] &#038;&#038; break</p>
<p>		if isin &#8220;$resp&#8221; $_devs; then</p>
<p>			makedev $resp &#038;&#038; break</p>
<p>		else</p>
<p>			echo &#8220;&#8216;$resp&#8217; is not a valid choice.&#8221;</p>
<p>		fi</p>
<p>	done</p>
<p>}</p>
<p>isin() {</p>
<p>	local	_a=$1 _b</p>
<p>	shift</p>
<p>	for _b; do</p>
<p>		[ "$_a" = "$_b" ] &#038;&#038; return 0</p>
<p>	done</p>
<p>	return 1</p>
<p>}</p>
<p>addel() {</p>
<p>	local	_a=$1</p>
<p>	shift</p>
<p>	echo -n &#8220;$*&#8221;</p>
<p>	isin &#8220;$_a&#8221; $* || echo -n &#8221; $_a&#8221;</p>
<p>}</p>
<p>rmel() {</p>
<p>	local	_a=$1 _b</p>
<p>	shift</p>
<p>	for _b; do</p>
<p>		[ "$_a" != "$_b" ] &#038;&#038; echo -n &#8220;$_b &#8221;</p>
<p>	done</p>
<p>}</p>
<p>edit_tmp_file() {</p>
<p>	local _file=$1</p>
<p>	ask_yn &#8220;Edit $_file with $EDITOR?&#8221;</p>
<p>	[[ $resp == y ]] &#038;&#038; $EDITOR /tmp/$_file</p>
<p>}</p>
<p>manual_net_cfg() {</p>
<p>	ask_yn &#8220;Do you want to do any manual network configuration?&#8221;</p>
<p>	[[ $resp == y ]] &#038;&#038; { echo &#8220;Type &#8216;exit&#8217; to return to $MODE.&#8221; ; sh ; }</p>
<p>}</p>
<p>makedev() {</p>
<p>	local _dev=$1 _node=/dev/r${1}c</p>
<p>	if isin $_dev $IFDEVS || [[ -c $_node || -z ${_dev##+([0-9])} ]] ; then</p>
<p>		return 0</p>
<p>	fi</p>
<p>	if [[ ! -r /dev/MAKEDEV ]] ; then</p>
<p>		echo &#8220;No /dev/MAKEDEV. Can&#8217;t create device nodes for ${_dev}.&#8221;</p>
<p>		return 1</p>
<p>	fi</p>
<p>	(cd /dev; sh MAKEDEV $_dev)</p>
<p>	[[ -c $_node ]] || return 1</p>
<p>	DEVSMADE=`addel $_dev $DEVSMADE`</p>
<p>}</p>
<p>addhostent() {</p>
<p>	sed &#8220;/ $2\$/d&#8221; /etc/hosts >; /etc/hosts.new</p>
<p>	mv /etc/hosts.new /etc/hosts</p>
<p>	echo &#8220;$1 $2&#8243; >;>; /etc/hosts</p>
<p>}</p>
<p>configure_ifs() {</p>
<p>	local _IFDEVS=$IFDEVS _ifs _name _media _hn</p>
<p>	while : ; do</p>
<p>		ask_which &#8220;interface&#8221; &#8220;do you wish to initialize&#8221; &#8220;$_IFDEVS&#8221; \</p>
<p>			&#8220;&#8221; &#8220;No more interfaces to initialize&#8221;</p>
<p>		[[ $resp == done ]] &#038;&#038; break</p>
<p>		_ifs=$resp</p>
<p>		_hn=/etc/hostname.$_ifs</p>
<p>		ask &#8220;Symbolic (host) name for $_ifs?&#8221; &#8220;$(hostname -s)&#8221;</p>
<p>		_name=$resp</p>
<p>		_media=$(ifconfig -m $_ifs | grep &#8220;media &#8220;)</p>
<p>		if [[ -n $_media ]]; then</p>
<p>			cat << __EOT</p>
<p>The media options for $_ifs are currently</p>
<p>$(ifconfig -m $_ifs | sed -n '/supported/D;/media:/p')</p>
<p>__EOT</p>
<p>			ask_yn "Do you want to change the media options?"</p>
<p>			case $resp in</p>
<p>			y)	cat << __EOT</p>
<p>Supported media options for $_ifs are:</p>
<p>$_media</p>
<p>__EOT</p>
<p>				ask "Media options for $_ifs?"</p>
<p>				_media=$resp</p>
<p>				ifconfig $_ifs $_media || return 1</p>
<p>				;;</p>
<p>			n)	_media=</p>
<p>				;;</p>
<p>			esac</p>
<p>		fi</p>
<p>		rm -f $_hn</p>
<p>		v4_config "$_ifs" "$_media" "$_name" "$_hn"</p>
<p>		[[ -f $_hn ]] &#038;&#038; _IFDEVS=$(rmel "$_ifs" $_IFDEVS)</p>
<p>	done</p>
<p>}</p>
<p>v4_info() {</p>
<p>	ifconfig $1 inet | sed -n '</p>
<p>		1s/.*<UP,.*/UP/p</p>
<p>		1s/.*<.*/DOWN/p</p>
<p>		/inet/s/netmask//</p>
<p>		/inet/s///p'</p>
<p>}</p>
<p>dhcp_request() {</p>
<p>	local _ifs=$1 _hostname=$2</p>
<p>	echo "initial-interval 1;" >; /etc/dhclient.conf</p>
<p>	if [[ -n $_hostname ]]; then</p>
<p>		echo &#8220;send host-name \&#8221;$_hostname\&#8221;;&#8221; >;>; /etc/dhclient.conf</p>
<p>		echo &#8220;Issuing hostname-associated DHCP request for $_ifs.&#8221;</p>
<p>	else</p>
<p>		echo &#8220;Issuing free-roaming DHCP request for $_ifs.&#8221;</p>
<p>	fi</p>
<p>	cat >;>; /etc/dhclient.conf << __EOT</p>
<p>request subnet-mask,</p>
<p>	broadcast-address,</p>
<p>	routers,</p>
<p>	domain-name,</p>
<p>	domain-name-servers,</p>
<p>	host-name;</p>
<p>__EOT</p>
<p>	cat >;>; /etc/resolv.conf.tail << __EOT</p>
<p>lookup file bind</p>
<p>__EOT</p>
<p>	dhclient $_ifs</p>
<p>	set -- $(v4_info $_ifs)</p>
<p>	if [[ $1 == UP &#038;&#038; $2 == "0.0.0.0" ]]; then</p>
<p>		ifconfig $_ifs delete down</p>
<p>		rm /etc/dhclient.conf /etc/resolv.conf.tail</p>
<p>		return 1</p>
<p>	fi</p>
<p>#	cp /etc/dhclient.conf /tmp/dhclient.conf</p>
<p>#	cp /etc/resolv.conf.tail /tmp/resolv.conf.tail</p>
<p>	return 0</p>
<p>}</p>
<p>v4_config() {</p>
<p>	local _ifs=$1 _media=$2 _name=$3 _hn=$4 _prompt</p>
<p>	set -- $(v4_info $_ifs)</p>
<p>	if [[ -n $2 ]]; then</p>
<p>		ifconfig $_ifs inet $2 delete</p>
<p>		[[ $2 != "0.0.0.0" ]] &#038;&#038; { _addr=$2; _mask=$3; }</p>
<p>	fi</p>
<p>	[[ -x /sbin/dhclient ]] &#038;&#038; _prompt=" or 'dhcp'"</p>
<p>	_prompt="IPv4 address for $_ifs? (or 'none'$_prompt)"</p>
<p>	ask_until "$_prompt" "$_addr"</p>
<p>	case $resp in</p>
<p>	none)	;;</p>
<p>	dhcp)	if [[ ! -x /sbin/dhclient ]]; then</p>
<p>			echo "DHCP not possible - no /sbin/dhclient."</p>
<p>		elif dhcp_request $_ifs "$_name" || dhcp_request $_ifs ; then</p>
<p>			addhostent "127.0.0.1" "$_name"</p>
<p>			echo "dhcp NONE NONE NONE $_media" >; $_hn</p>
<p>		fi</p>
<p>		;;</p>
<p>	*)	_addr=$resp</p>
<p>		ask_until &#8220;Netmask?&#8221; &#8220;${_mask:=255.255.255.0}&#8221;</p>
<p>		if ifconfig $_ifs inet $_addr netmask $resp up ; then</p>
<p>			addhostent &#8220;$_addr&#8221; &#8220;$_name&#8221;</p>
<p>			echo &#8220;inet $_addr $resp NONE $_media&#8221; >; $_hn</p>
<p>		fi</p>
<p>		;;</p>
<p>	esac</p>
<p>}</p>
<p>v4_defroute() {</p>
<p>	local _dr _prompt=&#8221; or &#8216;none&#8217;&#8221;</p>
<p>	[[ -x /sbin/dhclient ]] &#038;&#038; _prompt=&#8221;, &#8216;dhcp&#8217;$_prompt&#8221;</p>
<p>	_prompt=&#8221;Default IPv4 route? (IPv4 address$_prompt)&#8221;</p>
<p>	_dr=$(route -n show -inet | sed -ne &#8216;/^default */{s///; s/ .*//; p;}&#8217;)</p>
<p>	[[ -f /tmp/dhclient.conf ]] &#038;&#038; _dr=dhcp</p>
<p>	while : ; do</p>
<p>		ask_until &#8220;$_prompt&#8221; &#8220;$_dr&#8221;</p>
<p>		case $resp in</p>
<p>		none|dhcp) break ;;</p>
<p>		esac</p>
<p>		route delete -inet default >; /dev/null 2>;&#038;1</p>
<p>		route -n add -inet -host default &#8220;$resp&#8221; &#038;&#038; { echo &#8220;$resp&#8221; </p>
<p>>;/etc/mygate ; break ; }</p>
<p>		route -n add -inet -host default $_dr >;/dev/null 2>;&#038;1</p>
<p>	done</p>
<p>}</p>
<p>isalphanumeric() {</p>
<p>	local _n=$1</p>
<p>	while [[ ${#_n} -ne 0 ]]; do</p>
<p>		case $_n in</p>
<p>		[A-Za-z0-9]*)	;;</p>
<p>		*)		return 1;;</p>
<p>		esac</p>
<p>		_n=${_n#?}</p>
<p>	done</p>
<p>	return 0</p>
<p>}</p>
<p>enable_network() {</p>
<p>	local _netfile</p>
<p>#	for _netfile in hosts dhclient.conf resolv.conf resolv.conf.tail </p>
<p>protocols services; do</p>
<p>#		if [ -f /mnt/etc/${_netfile} ]; then</p>
<p>#			cp /mnt/etc/${_netfile} /etc/${_netfile}</p>
<p>#		fi</p>
<p>#	done</p>
<p>	ifconfig lo0 inet 127.0.0.1</p>
<p>	for hn in /etc/hostname.*; do</p>
<p>		if=${hn#/etc/hostname.}</p>
<p>		if ! isalphanumeric &#8220;$if&#8221;; then</p>
<p>			continue</p>
<p>		fi</p>
<p>		ifconfig $if >; /dev/null 2>;&#038;1</p>
<p>		if [ $? -ne 0 ]; then</p>
<p>			continue</p>
<p>		fi</p>
<p>		while :; do</p>
<p>			if [ "$cmd2" ]; then</p>
<p>				set &#8212; $cmd2</p>
<p>				af=$1 name=$2 mask=$3 bcaddr=$4 ext1=$5 cmd2=</p>
<p>				i=1; while [ i -lt 6 -a -n "$1" ]; do shift; let </p>
<p>i=i+1; done</p>
<p>				ext2=&#8221;$@&#8221;</p>
<p>			else</p>
<p>				read af name mask bcaddr ext1 ext2 || break</p>
<p>			fi</p>
<p>			case $af in</p>
<p>			&#8220;#&#8221;*|&#8221;!&#8221;*|&#8221;bridge&#8221;|&#8221;"|&#8221;rtsol&#8221;)</p>
<p>				continue</p>
<p>				;;</p>
<p>			&#8220;dhcp&#8221;)	[ "$name" = "NONE" ] &#038;&#038; name=</p>
<p>				[ "$mask" = "NONE" ] &#038;&#038; mask=</p>
<p>				[ "$bcaddr" = "NONE" ] &#038;&#038; bcaddr=</p>
<p>				ifconfig $if $name $mask $bcaddr $ext1 $ext2 </p>
<p>down</p>
<p>				cmd=&#8221;dhclient $if&#8221;</p>
<p>				;;</p>
<p>			&#8220;up&#8221;)</p>
<p>				cmd=&#8221;ifconfig $if $name $mask $bcaddr $ext1 </p>
<p>$ext2 up&#8221;</p>
<p>				;;</p>
<p>			*)	read dt dtaddr</p>
<p>				if [ "$name" = "alias" ]; then</p>
<p>					alias=$name</p>
<p>					name=$mask</p>
<p>					mask=$bcaddr</p>
<p>					bcaddr=$ext1</p>
<p>					ext1=$ext2</p>
<p>					ext2=</p>
<p>				else</p>
<p>					alias=</p>
<p>				fi</p>
<p>				cmd=&#8221;ifconfig $if $af $alias $name &#8221;</p>
<p>				case $dt in</p>
<p>				dest)	cmd=&#8221;$cmd $dtaddr&#8221;</p>
<p>					;;</p>
<p>				[a-z!]*)</p>
<p>					cmd2=&#8221;$dt $dtaddr&#8221;</p>
<p>					;;</p>
<p>				esac</p>
<p>				if [ ! -n "$name" ]; then</p>
<p>					echo &#8220;/etc/hostname.$if: invalid network </p>
<p>configuration file&#8221;</p>
<p>					return</p>
<p>				fi</p>
<p>				case $af in</p>
<p>				inet)	[ "$mask" ] &#038;&#038; cmd=&#8221;$cmd netmask $mask&#8221;</p>
<p>					if [ "$bcaddr" -a "$bcaddr" != "NONE" ]; </p>
<p>then</p>
<p>						cmd=&#8221;$cmd broadcast $bcaddr&#8221;</p>
<p>					fi</p>
<p>					[ "$alias" ] &#038;&#038; rtcmd=&#8221;; route -qn add </p>
<p>-host $name 127.0.0.1&#8243;</p>
<p>					;;</p>
<p>				inet6)</p>
<p>					continue</p>
<p>					;;</p>
<p>				*)	cmd=&#8221;$cmd $mask $bcaddr&#8221;</p>
<p>				esac</p>
<p>				cmd=&#8221;$cmd $ext1 $ext2$rtcmd&#8221; rtcmd=</p>
<p>				;;</p>
<p>			esac</p>
<p>			eval &#8220;$cmd&#8221;</p>
<p>		done </etc/hostname.$if</p>
<p>	done</p>
<p>	if [ -f /etc/mygate ]; then</p>
<p>		route delete default >;/dev/null 2>;&#038;1</p>
<p>		route -qn add -host default $(< /etc/mygate)</p>
<p>	fi</p>
<p>	route -qn add -host `hostname` 127.0.0.1 >;/dev/null</p>
<p>	route -qn add -net 127 127.0.0.1 -reject >;/dev/null</p>
<p>	echo &#8220;Network interface configuration:&#8221;</p>
<p>	ifconfig -am</p>
<p>	route -n show</p>
<p>	if [ -f /etc/resolv.conf ]; then</p>
<p>		echo &#8220;\nResolver enabled.&#8221;</p>
<p>	else</p>
<p>		echo &#8220;\nResolver not enabled.&#8221;</p>
<p>	fi</p>
<p>}</p>
<p>get_fqdn() {</p>
<p>	local _dn</p>
<p>	_dn=$(hostname)</p>
<p>	_dn=${_dn#$(hostname -s)}</p>
<p>	_dn=${_dn#.}</p>
<p>	echo &#8220;${_dn:=my.domain}&#8221;</p>
<p>}</p>
<p>donetconfig() {</p>
<p>	local _dn _ns</p>
<p>	configure_ifs</p>
<p>	if [ -f /etc/resolv.conf.shadow ]; then</p>
<p>		mv /etc/resolv.conf.shadow /etc/resolv.conf</p>
<p>		_ns=$(sed -ne &#8216;/^nameserver /s///p&#8217; /etc/resolv.conf)</p>
<p>		_dn=$(sed -n \</p>
<p>			-e &#8216;/^domain[[:space:]][[:space:]]*/{s///;s/\([^</p>
<p>[:space:]]*\).*$/\1/;h;}&#8217; \</p>
<p>			-e &#8216;/^search[[:space:]][[:space:]]*/{s///;s/\([^</p>
<p>[:space:]]*\).*$/\1/;h;}&#8217; \</p>
<p>			-e &#8216;${g;p;}&#8217; /tmp/resolv.conf)</p>
<p>	fi</p>
<p>	ask &#8220;DNS domain name? (e.g. &#8216;bar.com&#8217;)&#8221; &#8220;${_dn:=$(get_fqdn)}&#8221;</p>
<p>	hostname &#8220;$(hostname -s).$resp&#8221;</p>
<p>	ask &#8220;DNS nameserver? (IP address or &#8216;none&#8217;)&#8221; &#8220;${_ns:=none}&#8221;</p>
<p>	if [[ $resp != none ]]; then</p>
<p>		echo &#8220;lookup file bind&#8221; >; /etc/resolv.conf</p>
<p>		for _ns in $resp; do</p>
<p>			echo &#8220;nameserver $_ns&#8221; >;>; /etc/resolv.conf</p>
<p>		done</p>
<p>		ask_yn &#8220;Use the nameserver now?&#8221; yes</p>
<p>		[[ $resp == y ]] &#038;&#038; cp /etc/resolv.conf /etc/resolv.conf.shadow</p>
<p>	fi</p>
<p>	[[ -n $(ifconfig -a | sed -ne '/[ 	]inet .* broadcast /p&#8217;) ]] &#038;&#038; </p>
<p>v4_defroute</p>
<p>#	edit_tmp_file hosts</p>
<p>#	manual_net_cfg</p>
<p>}</p>
<p>IFDEVS=$(get_ifdevs)</p>
<p>MODE=OpenBSD-LiveCD</p>
<p>EDITOR=mg</p>
<p>ask_until &#8220;\nSystem hostname? (short form, e.g. &#8216;foo&#8217;)&#8221; &#8220;$(hostname -s)&#8221;</p>
<p>[[ ${resp%%.*} != $(hostname -s) ]] &#038;&#038; hostname $resp</p>
<p>( cd /etc; rm -f host* my* resolv.* dhclient.* )</p>
<p>cat >; /etc/hosts << __EOT</p>
<p>::1 localhost</p>
<p>127.0.0.1 localhost</p>
<p>::1 $(hostname -s)</p>
<p>127.0.0.1 $(hostname -s)</p>
<p>__EOT</p>
<p>ask_yn "Configure the network?" yes</p>
<p>[[ $resp == y ]] &#038;&#038; donetconfig</p>
<p>( cd /etc</p>
<p>hostname >; myname</p>
<p>_dn=$(get_fqdn)</p>
<p>while read _addr _hn _aliases; do</p>
<p>	if [[ -n $_aliases || $_hn != ${_hn%%.*} || -z $_dn ]]; then</p>
<p>		echo &#8220;$_addr $_hn $_aliases&#8221;</p>
<p>	else</p>
<p>		echo &#8220;$_addr $_hn.$_dn $_hn&#8221;</p>
<p>	fi</p>
<p>done < hosts >; hosts.new</p>
<p>mv hosts.new hosts</p>
<p>)</p>
<p>ask &#8220;HTTP/FTP proxy URL? (e.g. &#8216;http://proxy:8080&#8242;, or &#8216;none&#8217;)&#8221; \</p>
<p>	    &#8220;${ftp_proxy:-none}&#8221;</p>
<p>unset ftp_proxy http_proxy</p>
<p>[[ $resp == none ]] || export ftp_proxy=$resp http_proxy=$resp</p>
]]></content:encoded>
			<wfw:commentRss>http://www.evanjiang.net.cn/archives/1209.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>OpenBSD.Nginx.MySQL.PHP环境搭建手册(网上转摘）</title>
		<link>http://www.evanjiang.net.cn/archives/1176.html</link>
		<comments>http://www.evanjiang.net.cn/archives/1176.html#comments</comments>
		<pubDate>Mon, 08 Jun 2009 14:32:00 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[mysql]]></category>
		<category><![CDATA[openbsd unix]]></category>
		<category><![CDATA[pf]]></category>
		<category><![CDATA[www服务]]></category>

		<guid isPermaLink="false">http://www.evanjiang.net.cn/?p=1176</guid>
		<description><![CDATA[<p>很久没弄过OPENBSD，而且，听说现在的NGINX很红，性能比传统的APACHE要好很多倍，因而，一直想弄个NGINX服务器环境。加上，俺也想熟悉回OPENBSD，就想着弄个OPENBSD，NGINX，MYSQL，PHP的环境。。弄来玩玩，就当复习一下技术。出于习惯，俺还是在网上找了这篇文档。初步看过，好像写得不错，，就先弄过来，暂没时间实操过，待俺忙过这段时间。就再次重点研究一下俺熟悉而喜欢的UNIX服务器与数据库技术。。。</p>
<p>本手册以在OpenBSD 4.4环境下搭建Nginx、MySQL、PHP环境为例进行讲解。按照惯例，root权限。</p>
<p>=====================================================</p>
<p>目录</p>
<p>一、OpenBSD的安装及注意事项
二、系统性能调优
Ⅰ、/etc/fstab调优
Ⅱ、/etc/sysctl.conf调优</p>
<p>三、O.N.M.P.软件环境的安装
四、Nginx配置
Ⅰ、Nginx配置文件的修改
Ⅱ、Nginx日志截断</p>
<p>五、MySQL与phpMyAdmin的配置
Ⅰ、MySQL的配置
Ⅱ、phpMyAdmin的配置</p>
<p>六、强化PHP的安全
七、强化SSH的安全
Ⅰ、SSH配置文件的修改
Ⅱ、使用KEY进行验证
Ⅲ、按需启动SSH
Ⅳ、一点安全小常识</p>
<p>八、启用Packet Filter防火墙
九、系统启动脚本的修改</p>
<p>=====================================================</p>
<p>一、OpenBSD的安装及注意事项</p>
<p>OpenBSD的安装这里就不多说了，主要是安装时系统组件的选择、分区和系统服务的部分。对于系统组件部分，作为生产系统来说，偶并不推荐安装comp44.tgz这个组件。因为comp44.tgz实际就是编译器，不装这个，可以在很大程度上避免安装一些非授权的软件，从而提高远程主机的安全性。如果真的需要安装什么软件，也可以在非重要的机器上进行编译，然后使用PSFTP等软件上传到远程主机上使用。关于PSFTP软件的使用，二楼有详细的介绍。</p>
<p>系统分区时，推荐将/usr、/usr/local、/var、/var/mysql、/var/mail、/var/log、/var/nginx等分区单独分出来，也就是说，进行比较细致的分区，防止某个目录中的文件膨胀占满整个分区导致的死锁等问题。假定你有一个80G的硬盘，一个分区示例在下面：</p>
<p>/	200M
(swap)	1G
/tmp	200M
/usr	500M
/usr/local	200M
/var	100M
/var/mysql	10G
/var/mail	100M
/var/log	5G~10G
/home	200M
/var/nginx	剩余空间</p>
<p>至于系统服务部分，建议所有的服务都选择“n”，亦即不随系统启动。

二、系统性能调优</p>
<p>对于多核的机器，使用bsd.mp这个核心。</p>
<p>[Copy to clipboard] [ - ]CODE:
mv /bsd /obsd
mv /bsd.mp /bsd</p>
<p>Ⅰ、/etc/fstab调优</p>
<p>[Copy to clipboard] [ - ]CODE:
vi /etc/fstab</p>
<p>在文件系统描述符部分，加入&#8221;noatime&#8221;和&#8221;softdep&#8221;。示例如下：</p>
<p>QUOTE:
/dev/wd0a / ffs rw,noatime,softdep 1 1
/dev/wd0l /home ffs rw,nodev,nosuid,noatime,softdep 1 2
/dev/wd0d /tmp ffs rw,nodev,nosuid,noatime,softdep 1 2
/dev/wd0e /usr ffs rw,nodev,noatime,softdep 1 2
/dev/wd0f /usr/local ffs rw,nodev,noatime,softdep 1 2
/dev/wd0g /var ffs rw,nodev,nosuid,noatime,softdep 1 2
/dev/wd0i /var/log ffs rw,nodev,nosuid,noatime,softdep 1 2
/dev/wd0j /var/mail ffs [...]]]></description>
			<content:encoded><![CDATA[<p>很久没弄过OPENBSD，而且，听说现在的NGINX很红，性能比传统的APACHE要好很多倍，因而，一直想弄个NGINX服务器环境。加上，俺也想熟悉回OPENBSD，就想着弄个OPENBSD，NGINX，MYSQL，PHP的环境。。弄来玩玩，就当复习一下技术。出于习惯，俺还是在网上找了这篇文档。初步看过，好像写得不错，，就先弄过来，暂没时间实操过，待俺忙过这段时间。就再次重点研究一下俺熟悉而喜欢的UNIX服务器与数据库技术。。。</p>
<p>本手册以在OpenBSD 4.4环境下搭建Nginx、MySQL、PHP环境为例进行讲解。按照惯例，root权限。</p>
<p>=====================================================</p>
<p>目录</p>
<p>一、OpenBSD的安装及注意事项<br />
二、系统性能调优<br />
Ⅰ、/etc/fstab调优<br />
Ⅱ、/etc/sysctl.conf调优</p>
<p>三、O.N.M.P.软件环境的安装<br />
四、Nginx配置<br />
Ⅰ、Nginx配置文件的修改<br />
Ⅱ、Nginx日志截断</p>
<p>五、MySQL与phpMyAdmin的配置<br />
Ⅰ、MySQL的配置<br />
Ⅱ、phpMyAdmin的配置</p>
<p>六、强化PHP的安全<br />
七、强化SSH的安全<br />
Ⅰ、SSH配置文件的修改<br />
Ⅱ、使用KEY进行验证<br />
Ⅲ、按需启动SSH<br />
Ⅳ、一点安全小常识</p>
<p>八、启用Packet Filter防火墙<br />
九、系统启动脚本的修改</p>
<p>=====================================================</p>
<p>一、OpenBSD的安装及注意事项</p>
<p>OpenBSD的安装这里就不多说了，主要是安装时系统组件的选择、分区和系统服务的部分。对于系统组件部分，作为生产系统来说，偶并不推荐安装comp44.tgz这个组件。因为comp44.tgz实际就是编译器，不装这个，可以在很大程度上避免安装一些非授权的软件，从而提高远程主机的安全性。如果真的需要安装什么软件，也可以在非重要的机器上进行编译，然后使用PSFTP等软件上传到远程主机上使用。关于PSFTP软件的使用，二楼有详细的介绍。</p>
<p>系统分区时，推荐将/usr、/usr/local、/var、/var/mysql、/var/mail、/var/log、/var/nginx等分区单独分出来，也就是说，进行比较细致的分区，防止某个目录中的文件膨胀占满整个分区导致的死锁等问题。假定你有一个80G的硬盘，一个分区示例在下面：</p>
<p>/	200M<br />
(swap)	1G<br />
/tmp	200M<br />
/usr	500M<br />
/usr/local	200M<br />
/var	100M<br />
/var/mysql	10G<br />
/var/mail	100M<br />
/var/log	5G~10G<br />
/home	200M<br />
/var/nginx	剩余空间</p>
<p>至于系统服务部分，建议所有的服务都选择“n”，亦即不随系统启动。<br />
<span id="more-1176"></span><br />
二、系统性能调优</p>
<p>对于多核的机器，使用bsd.mp这个核心。</p>
<p>[Copy to clipboard] [ - ]CODE:<br />
mv /bsd /obsd<br />
mv /bsd.mp /bsd</p>
<p>Ⅰ、/etc/fstab调优</p>
<p>[Copy to clipboard] [ - ]CODE:<br />
vi /etc/fstab</p>
<p>在文件系统描述符部分，加入&#8221;noatime&#8221;和&#8221;softdep&#8221;。示例如下：</p>
<p>QUOTE:<br />
/dev/wd0a / ffs rw,noatime,softdep 1 1<br />
/dev/wd0l /home ffs rw,nodev,nosuid,noatime,softdep 1 2<br />
/dev/wd0d /tmp ffs rw,nodev,nosuid,noatime,softdep 1 2<br />
/dev/wd0e /usr ffs rw,nodev,noatime,softdep 1 2<br />
/dev/wd0f /usr/local ffs rw,nodev,noatime,softdep 1 2<br />
/dev/wd0g /var ffs rw,nodev,nosuid,noatime,softdep 1 2<br />
/dev/wd0i /var/log ffs rw,nodev,nosuid,noatime,softdep 1 2<br />
/dev/wd0j /var/mail ffs rw,nodev,nosuid,noatime,softdep 1 2<br />
/dev/wd0h /var/mysql ffs rw,nodev,nosuid,noatime,softdep 1 2<br />
/dev/wd0k /var/nginx ffs rw,nodev,nosuid,noatime,softdep 1 2</p>
<p>友情提醒：softdep是一种非同步的文件系统，意外掉电可能造成数据的遗失/损坏，生产系统请谨慎使用！</p>
<p>改完后保存退出，reboot，看能不能正常启动。</p>
<p>一般情况下是没有问题的，个别机器或虚拟机可能会因为兼容性的缘故，无法启动。那么就把根目录的softdep拿掉，其他目录保留，仍然会有作用。</p>
<p>更多关于OpenBSD环境下磁盘性能调优的内容，请参看偶博客的文章，地址在下面：</p>
<p>http://blog.chinaunix.net/u2/81136/showart_1841280.html</p>
<p>Ⅱ、/etc/sysctl.conf调优</p>
<p>[Copy to clipboard] [ - ]CODE:<br />
vi /etc/sysctl.conf</p>
<p>跳到最后，加入下面的内容：</p>
<p>QUOTE:<br />
# 增大文件系统缓存到1M<br />
kern.maxvnodes=131072</p>
<p># 允许最多65536个进程<br />
kern.maxproc=65536</p>
<p># 同时最多打开65536个文件<br />
kern.maxfiles=65536</p>
<p># 并发连接最大65536<br />
kern.somaxconn=65536</p>
<p># 保留的最少连接数<br />
kern.sominconn=256<br />
kern.maxclusters=32768</p>
<p># 增大TCP接收/发送缓存到64K<br />
net.inet.tcp.recvspace=65536<br />
net.inet.tcp.sendspace=65536</p>
<p># 增大UDP接收/发送缓存到64K<br />
net.inet.udp.recvspace=65536<br />
net.inet.udp.sendspace=65536</p>
<p>注意：虚拟机测试只加最上面一行kern.maxvnodes=65536即可，其他的不必加了，否则会有各种问题。独立机器的可以加上。</p>
<p>保存退出，reboot。不能正常启动的就把除kern.maxvnodes以外的数字调小或者禁用再试。</p>
<p>三、OpenBSD.Nginx.MySQL.PHP软件环境的安装</p>
<p>OpenBSD环境下软件的安装是非常简单的，因为在官方的ftp中提供了已经编译好的二进制包，需要安装的软件都在ftp中，从ftp中安装即可。</p>
<p>小提示：如果你机器比较多，你可以把需要安装的软件包都down回来，其他机器再来这里安装，速度会非常快！</p>
<p>[Copy to clipboard] [ - ]CODE:<br />
export PKG_PATH=ftp://ftp.openbsd.org/pub/OpenBSD/4.4/packages/i386/</p>
<p>pkg_add mysql-server php5-fastcgi php5-gd-5.2.6-no_x11 phpMyAdmin lighttpd-1.4.19p3 nginx pecl-APC</p>
<p>以偶的1M ADSL小水管为例，大约也就二十分钟左右就安装完毕了！真的是非常快！和其他系统的wget源码、./configure &amp;&amp; make &amp;&amp; make install&#8230;所需要的时间相比，效率是非常高！而且，由于OpenBSD默认采用比较高的安全策略，装上的环境安全性也比其他系统要高！</p>
<p>等所需的软件都安装完成后，按提示作链接并创建PHP临时工作目录：</p>
<p>QUOTE:<br />
ln -s /var/www/conf/modules.sample/php5.conf /var/www/conf/modules<br />
ln -fs /var/www/conf/php5.sample/apc.ini /var/www/conf/php5/apc.ini<br />
ln -fs /var/www/conf/php5.sample/gd.ini /var/www/conf/php5/gd.ini<br />
ln -fs /var/www/conf/php5.sample/mbstring.ini /var/www/conf/php5/mbstring.ini<br />
ln -fs /var/www/conf/php5.sample/mcrypt.ini /var/www/conf/php5/mcrypt.ini<br />
ln -fs /var/www/conf/php5.sample/mysql.ini /var/www/conf/php5/mysql.ini<br />
mkdir /var/nginx/sesstmp<br />
chmod 0777 /var/nginx/sesstmp</p>
<p>pkg_info检查一下系统中安装了些什么软件包：</p>
<p>可以看到，所需的软件包和依赖的包都安装好了！</p>
<p>四、Nginx配置</p>
<p>Ⅰ、Nginx配置文件的修改</p>
<p>修改nginx的默认配置文件：</p>
<p>[Copy to clipboard] [ - ]CODE:<br />
vi /etc/nginx/nginx.conf</p>
<p>按下面的内容修改Nginx的配置文件。兰色表示需要手动修改的内容，红色表示增加的内容：</p>
<p>QUOTE:<br />
#user  nobody;</p>
<p># 指定子进程数，酌情修改<br />
worker_processes  4;</p>
<p>#error_log  logs/error.log;<br />
#error_log  logs/error.log  notice;<br />
#error_log  logs/error.log  info;</p>
<p>#pid        logs/nginx.pid;</p>
<p># 最多可打开文件数<br />
worker_rlimit_nofile 8196;</p>
<p>events {<br />
# 最大并发数<br />
worker_connections  1024;<br />
}</p>
<p>http {<br />
include       mime.types;<br />
default_type  application/octet-stream;</p>
<p># 关掉错误日志<br />
error_log       /dev/null  crit;<br />
# 如果需要错误日志，就用下面这行替换上面这行<br />
#error_log     /var/log/nginx/error.log  notice;</p>
<p># 定义日志格式，对日志使用缓存，避免频繁的磁盘I/O操作<br />
access_log   /var/log/nginx/access.log combined buffer=1m;</p>
<p>sendfile        on;<br />
tcp_nopush      on;<br />
tcp_nodelay     on;</p>
<p>keepalive_timeout  10;</p>
<p># 对静态文件和可压缩文件启用压缩，以节约网络带宽，提高访问速度<br />
gzip              on;<br />
gzip_min_length   1k;<br />
gzip_buffers      4 8k;<br />
gzip_http_version 1.1;<br />
gzip_comp_level   3;<br />
gzip_types        text/html text/css text/xml text/plain application/x-javascript application/xml application/pdf application/x-perl application/x-tcl application/msword application/rtf application/vnd.ms-excel application/vnd.ms-powerpoint application/vnd.wap.xhtml+xml image/x-ms-bmp;<br />
gzip_disable      &#8220;MSIE [1-6] \.&#8221;;<br />
gzip_vary         on;</p>
<p># 定义输出缓存大小<br />
output_buffers   4 32k;</p>
<p># 最大允许可上传文件大小<br />
client_max_body_size 20m;</p>
<p># 定义一个叫“myzone”的记录区，总容量为 10M<br />
# 和下面的limit_conn一起限制单个IP的并发连接数为10<br />
limit_zone myzone $binary_remote_addr  10m;</p>
<p>server {<br />
listen       80;<br />
server_name  localhost;</p>
<p>location / {<br />
root   /var/nginx/html;<br />
index  index.php index.html index.htm;<br />
limit_conn  myzone 10;<br />
}</p>
<p>error_page   500 502 503 504  /50x.html;</p>
<p>location = /50x.html {<br />
root   /var/nginx/html;<br />
}</p>
<p>location ~ \.php$ {<br />
root           html;<br />
fastcgi_pass   127.0.0.1:9000;<br />
fastcgi_index  index.php;<br />
fastcgi_param  SCRIPT_FILENAME  /var/nginx/html$fastcgi_script_name;<br />
include        fastcgi_params;<br />
}</p>
<p># 在浏览器本地暂存图片和静态文件，不记录日志，以节约机器资源<br />
location ~* \.(gif|png|jpg|jpeg|bmp|css|js|swf)$<br />
{<br />
root           /var/nginx/html;<br />
access_log off;<br />
expires max;<br />
}</p>
<p># 在浏览器中输入http://xxx.xxx.xxx/status可以看到Nginx的运行信息<br />
# 需要密码验证，不记录日志，限制IP访问<br />
location ~ /status<br />
{<br />
auth_basic  &#8220;O.N.M.P.&#8221;;<br />
auth_basic_user_file password;<br />
stub_status on;<br />
access_log   off;<br />
allow 192.168.0.0/24;<br />
deny all;<br />
}<br />
}</p>
<p>}</p>
<p>其他的部分请酌情修改。</p>
<p>运行下面的命令生成查看Nginx运行状态的密码文件：</p>
<p>[Copy to clipboard] [ - ]CODE:<br />
htpasswd -c /etc/nginx/password webadmin</p>
<p>按提示输入两遍密码即可。</p>
<p>在查看status的时候，输入用户名webadmin（见上面这行）和密码就能够看到Nginx的运行数据了。</p>
<p>Nginx能够流行和它的高负载能力是分不开的，在追求性能表现的场合，推荐使用Nginx+PHP-fastcgi的组合以获得强健的性能表现。而对于那些重视安全性的场合来说，可能OpenBSD内核集成的Apache更合适。OpenBSD下搭建Apache、MySQL、PHP环境的详细内容请参见偶的另篇博文，地址在下面：（博客速度可能较慢，四楼有转帖）</p>
<p>http://blog.chinaunix.net/u2/81136/showart_1860332.html</p>
<p>当然，你也可以利用Nginx内置的负载均衡功能，在前端分配访问流量，后端由Apache来运行PHP环境。Nginx负载均衡的配置可以去Nginx的主页参看相关内容，地址：http://wiki.nginx.org/Main。</p>
<p>下面为一个Nginx负载均衡的示例：</p>
<p>QUOTE:<br />
http {<br />
upstream myproject {<br />
ip_hash;<br />
server 192.168.1.1:80;<br />
server 192.168.1.2:80;<br />
server 192.168.1.3:80;<br />
server 192.168.1.4:80;<br />
}</p>
<p>server {<br />
listen 80;<br />
server_name www.domain.com;<br />
location / {<br />
proxy_pass http://myproject;<br />
}<br />
}<br />
}</p>
<p>网络拓扑示意图如下：</p>
<p>Ⅱ、Nginx日志截断</p>
<p>OpenBSD默认每天00:00会执行/etc/daily.local脚本中的内容，我们只需要把Nginx日志截断的命令加入到这个文件中即可。</p>
<p>[Copy to clipboard] [ - ]CODE:<br />
vi /etc/daily.local</p>
<p>加入下面的内容：</p>
<p>QUOTE:<br />
#!/bin/sh<br />
# 对Nginx日志进行截断和压缩，以节约log分区空间<br />
# 在张宴的基础上修改，感谢！<br />
mkdir -p /var/log/nginx/$(date -d &#8220;yesterday&#8221; +&#8221;%Y&#8221;)/$(date -d &#8220;yesterday&#8221; +&#8221;%m&#8221;)/<br />
mv /var/log/nginx/access.log /var/log/nginx/$(date -d &#8220;yesterday&#8221; +&#8221;%Y&#8221;)/$(date -d &#8220;yesterday&#8221; +&#8221;%m&#8221;)/access.$(date -d &#8220;yesterday&#8221; +&#8221;%Y%m%d&#8221;).log<br />
kill -USR1 `cat /var/run/nginx.pid`<br />
sleep 1<br />
gzip /var/log/nginx/$(date -d &#8220;yesterday&#8221; +&#8221;%Y&#8221;)/$(date -d &#8220;yesterday&#8221; +&#8221;%m&#8221;)/access.$(date -d &#8220;yesterday&#8221; +&#8221;%Y%m%d&#8221;).log</p>
<p>保存退出，为/etc/daily.local加上执行权限：</p>
<p>[Copy to clipboard] [ - ]CODE:<br />
chmod 0755 /etc/daily.local</p>
<p>其他需要每天运行的命令也都可以加在这个脚本里面，各位自行处理。</p>
<p>五、MySQL与phpMyAdmin的配置</p>
<p>Ⅰ、MySQL的配置</p>
<p>安全起见，MySQL需要运行在自己的daemon下：</p>
<p>[Copy to clipboard] [ - ]CODE:<br />
vi /etc/login.conf</p>
<p>跳到最后，加入MySQL所需的修改：</p>
<p>QUOTE:<br />
mysql:\<br />
 <img src='http://www.evanjiang.net.cn/wp-includes/images/smilies/icon_surprised.gif' alt=':o' class='wp-smiley' /> penfiles-cur=2048:\<br />
 <img src='http://www.evanjiang.net.cn/wp-includes/images/smilies/icon_surprised.gif' alt=':o' class='wp-smiley' /> penfiles-max=4096:\<br />
:tc=daemon:</p>
<p>使修改生效：<br />

<!-- 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 -->
<br />
[Copy to clipboard] [ - ]CODE:<br />
cap_mkdb /etc/login.conf</p>
<p>初始化MySQL数据库：</p>
<p>[Copy to clipboard] [ - ]CODE:<br />
/usr/local/bin/mysql_install_db</p>
<p>MySQL自带了几个配置文件，在/usr/local/share/mysql目录中，可以拷贝为/etc/my.cnf使用。关于MySQL的配置和优化等内容，可以自行Google，这里不再赘述。<br />
MySQL安全须知<br />
不要用root身份运行数据库或PHP应用。并且，最好是数据库名和数据库用户名不同，以提高安全性。</p>
<p>例如，域名为example.net，则数据库名设为abcxyz，数据库用户名设为xyzabc。总之，关联度越低越好，数据库名和数据库用户名越复杂越难猜测越好。</p>
<p>控制权限的分配，PHP应用仅给予必要的权限。</p>
<p>例如，安装/升级Discuz!和PHPWind论坛程序，仅需要下图所示的权限即可：</p>
<p>在安装/升级完毕后，还可以把CREATE、ALTER、DROP权限去掉，不会影响论坛程序的运行，而且提高了安全性！<br />
Ⅱ、phpMyAdmin的配置</p>
<p>由于OpenBSD中的phpMyAdmin默认是安装在/var/www/phpMyAdmin目录中的，直接使用Nginx是无法访问的，我们需要把它拷贝到Nginx目录下，这样就可以通过浏览器来管理MySQL数据库了。</p>
<p>[Copy to clipboard] [ - ]CODE:<br />
mkdir /var/nginx/html/pma/<br />
cp -rf /var/www/phpMyAdmin/* /var/nginx/html/pma/</p>
<p>修改phpMyAdmin的配置文件，使之可用。</p>
<p>[Copy to clipboard] [ - ]CODE:<br />
vi +17 /var/nginx/html/pma/config.inc.php</p>
<p>将下面这行修改成：</p>
<p>QUOTE:<br />
$cfg['blowfish_secret'] = &#8216;a&#8217;; /* YOU MUST FILL IN THIS FOR COOKIE AUTH! */</p>
<p>（仅是加入了字母a而已）</p>
<p>保存退出。<br />
小提示：<br />
上面新建了/var/nginx/html/pma目录来保存phpMyAdmin的文件，目录名很简单。你可以用一个更复杂的目录名来代替，例如：pma2YAY5jRpfFfLXQVm这样的目录名，以防止黑客利用字典攻击等方法渗透你的phpMyAdmin！</p>
<p>你还可以在Nginx的配置文件中，将/var/nginx/html/pma配置成某个虚拟主机的根目录，并限定可以访问这个虚拟主机的IP。这样，就可以在很大程度上提高数据库的安全性了！一个配置示例在下面：</p>
<p>QUOTE:<br />
location / {<br />
allow   192.168.0.0/24;<br />
deny    all;<br />
}</p>
<p>假如平时只是偶尔用到phpMyAdmin，你还可以在用完后删除/var/nginx/html/pma目录，需要用的时候再拷贝过去。</p>
<p>你还可以将以上方法结合起来灵活使用，既建立一个无法被猜测的目录名，又限制IP访问，这样你的系统被黑的机会就会小了很多！<br />
六、强化PHP的安全</p>
<p>OpenBSD软件包中的PHP已经自带了suhosin这个补丁，可以在很大程度上提高PHP脚本的安全。本节主要讨论在php.ini文件中进行相关的设置，进一步提升安全性。具体来说，就是禁用某些危险函数和启用PHP安全模式。</p>
<p>偶一般是把对PHP的所有修改都放在一个单独的文件中进行，包括对PHP参数以及扩展模块的修改，都放在这个文件中一并处理，这样查找、修改和管理会方便许多：</p>
<p>[Copy to clipboard] [ - ]CODE:<br />
vi /var/www/conf/php5/addphp.ini</p>
<p>加入下面的内容：</p>
<p>QUOTE:<br />
; 禁止动态加载模块<br />
enable_dl = Off</p>
<p>; 隐藏PHP信息<br />
expose_php = Off</p>
<p>; 限定可访问目录<br />
open_basedir = /var/nginx/html/</p>
<p>;设定session暂存目录<br />
session.save_path=/var/nginx/sesstmp</p>
<p>; 设定PHP上传文件的临时目录<br />
upload_tmp_dir=/var/nginx/tmp</p>
<p>; 禁用危险函数（注意下面的内容应该是一行，编排的原因分成了多行）<br />
disable_functions = phpinfo,com,shell,exec,system,passthru,error_log,<br />
stream_socket_server,putenv,ini_alter,ini_restore,ini_set,dl,openlog,<br />
syslog,readlink,symlink,link,leak,fsockopen,pfsockopen,proc_open,<br />
popepassthru,escapeshellcmd,escapeshellarg,chroot,scandir,<br />
chgrp,chown,shell_exec,proc_get_status,popen,shmop_close,<br />
shmop_delete,shmop_open,shmop_read,shmop_size,shmop_write</p>
<p>; 启用PHP的安全模式<br />
; PHP在安全模式下运行是用性能换安全。据简单测试，性能下降到50%左右，各位请酌情使用<br />
; 启用安全模式后，某些程序可能受到影响。例如，Discuz!将无法上传附件<br />
safe_mode = On</p>
<p>; pecl-APC只使用16M的共享内存用以加速PHP程序的运行<br />
apc.shm_size=16M</p>
<p>保存退出。<br />
七、强化SSH的安全<br />
Ⅰ、SSH配置文件的修改</p>
<p>[Copy to clipboard] [ - ]CODE:<br />
vi /etc/ssh/sshd_config</p>
<p>跳到最后，加入下面的部分：</p>
<p>QUOTE:<br />
# 使用高位端口，防止黑客扫描22端口。可选范围1024~65535，推荐32768~65535。<br />
Port 58937</p>
<p># 登录时间控制在30秒内<br />
LoginGraceTime 30</p>
<p># 不允许root远程直接登录<br />
PermitRootLogin no<br />
StrictModes yes</p>
<p># 最多允许三次错误<br />
MaxAuthTries 3</p>
<p># 最多允许三个SSH线程<br />
MaxSessions 3</p>
<p># 使用SSH协议2<br />
Protocol 2</p>
<p># 不使用密码认证<br />
PasswordAuthentication no</p>
<p># 使用KEY的方式认证<br />
PubkeyAuthentication yes</p>
<p># KEY文件存放位置<br />
AuthorizedKeysFile      .ssh/authorized_keys</p>
<p>Ⅱ、使用KEY进行验证</p>
<p>下面以Windows环境下PuTTY为例讲解使用KEY验证的方法，Linux/UNIX下与此类似。</p>
<p>首先，从下面的网址下载PuTTY的安装包（Windows）：</p>
<p>http://the.earth.li/~sgtatham/putty/latest/x86/putty-0.60-installer.exe</p>
<p>下完后双击安装，不再赘述。这个软件包自带了下面几个非常实用的软件：</p>
<p>QUOTE:<br />
PuTTYgen:生成KEY；</p>
<p>Pageant:管理KEY；</p>
<p>PuTTY:SSH客户端；</p>
<p>PSFTP:使用SSH上传/下载文件。</p>
<p>下面就来实例讲解用PuTTY的这几个软件对远程主机进行KEY认证和管理的方法。假设我们要在192.168.0.132这个远程主机上使用young_king这个用户名进行KEY认证和登录。<br />
1.生成KEY</p>
<p>启动PuTTYgen，如下图：</p>
<p>在密钥长度栏输入想要的密钥长度，越大越安全。这里以最大的2048位为例，然后点“Generate”按钮，会开始生成KEY，生成过程中需要在下面的空白部分移动鼠标来生成随机数。</p>
<p>KEY生成完毕后，你可以输入一些标识信息，如下图：</p>
<p>还可以在下面的passphrase框内输入“保护码”，注意要输入两遍。“保护码”也就是密码的意思，用来保密私钥的，一定要记住这个哦！</p>
<p>都输入完毕后，点击下面的“Save public key”按钮保存公钥，如下图所示：</p>
<p>然后点击“Save private key”按钮保存私钥，如下图：</p>
<p>这个私钥最好不要保存在电脑上，我们把它拷贝到U盘上，随身带着，这就是我们的“KEY盘”。</p>
<p>要养成每月更换“保护码”的好习惯，更换“保护码”仍然要用到PuTTYgen这个软件，启动后点击“Load”，载入私钥，重新输入“保护码”，再确认一遍，然后点击“Save private key”保存即可！</p>
<p>2.启用KEY</p>
<p>上面生成了公钥和私钥，我们需要把公钥上传到远程主机的用户目录中，就要用到PSFTP这个软件了。启动它，如下图：</p>
<p>输入命令：open 192.168.0.132</p>
<p>接下来，PSFTP会列出远程主机上的RSA指纹以供识别，如下图：</p>
<p>这个指纹可以在远程主机上输入下面的命令查看：</p>
<p>[Copy to clipboard] [ - ]CODE:<br />
ssh-keygen -l -f /etc/ssh/ssh_host_rsa_key</p>
<p>请把这个指纹记在纸上，随身携带，和远程主机连接的时候就拿出来对比一下（这么做主要是为了防止连接被人劫持和指纹被伪造）。</p>
<p>如果上面PSFTP显示的指纹和远程主机上的不一致，那么毫无疑问是伪造的了，直接回车断开连接。如果相符，你可以输入“y”来保存这个指纹到本地计算机上（不推荐），或输入“n”只是这次连接使用。</p>
<p>随后PSFTP会让你输入登录用户名和密码，并自动进入该用户的根目录，如下图（以root为例）：</p>
<p>现在我们要把第一步生成的公钥上传到远程主机上（请把这个公钥复制到C:\Documents and Settings\Administrator目录先，如果你的Windows不是用Administrtor登录的，就替换成你登录用的用户名）。输入命令：put young_king，可以看到，公钥已经上传到/root目录了，见下图：</p>
<p>PuTTY生成的KEY并不能直接使用，需要转换一下。用PuTTY登录（此时上面修改的端口尚未启用，还是默认的22端口），以root身份执行：</p>
<p>[Copy to clipboard] [ - ]CODE:<br />
ssh-keygen -X -f /root/young_king &gt; /home/young_king/.ssh/authorized_keys</p>
<p>这就把公钥成功导入到young_king的目录中了，就可以被young_king这个用户使用了！</p>
<p>导入成功后，要删除多余的公钥：</p>
<p>[Copy to clipboard] [ - ]CODE:<br />
rm /root/young_king</p>
<p>下面介绍几个PSFTP常用的命令：</p>
<p>QUOTE:<br />
open xxx.xxx.xxx.xxx：打开远程主机（xxx.xxx.xxx.xxx为IP或域名）；</p>
<p>put xxxxxxxx：向远程主机上传文件（该文件需要事先拷贝到C:\Documents and Settings\Administrator目录）；</p>
<p>get xxxxxxxx：从远程主机下载文件（下载后保存在C:\Documents and Settings\Administrator目录）；</p>
<p>cd xxxxxx:进入远程主机的相应目录；</p>
<p>exit：退出PSFTP（也可以点右上角的叉关闭，不过不推荐这样做）。</p>
<p>更多的命令可以参看PuTTY的帮助文件，这个帮助写得不错。</p>
<p>3.使用KEY登录</p>
<p>我们上面虽然修改了SSH的配置文件（/etc/ssh/sshd_config），但还没有启用。输入下面的命令启用新的SSH配置，以便我们用KEY登录：</p>
<p>[Copy to clipboard] [ - ]CODE:<br />
kill -HUP `cat /var/run/sshd.pid`</p>
<p>PuTTY提供了一个KEY的管理程序，上面已经提到，是Pageant，我们使用这个程序来进行KEY登录。</p>
<p>启动Pageant，它会自动缩小到任务栏的通知区域，右键单击，选择“Add key”，会弹出个对话框让我们选择。插入上面制作好的“KEY盘”，并选择保存的私钥，会弹出个对话框让我们输入“保护码”，如下图：</p>
<p>如果安装PuTTY时选择了让Pageant关联.ppk文件，则双击私钥可以自动启动Pageant。</p>
<p>输入在生成KEY时输入的“保护码”，私钥就被导入到Pageant中了。再右键单击任务栏通知区的Pageant图标，选择第一项“New session”，Pageant会自动启动PuTTY，等待输入远程主机的相关信息，如下图：</p>
<p>输入IP（或域名）和端口号，点击最下面的“Open”按钮，PuTTY就会登录远程主机了。和PSFTP类似，会弹出个对话框让你确认远程主机的RSA指纹，如下图。同理，指纹不同就表示连接被劫持或指纹被伪造，点“取消”断开连接；指纹相同就点“否”，不保存主机公钥到本地计算机。</p>
<p>随后会让你输入用户名，输入“young_king”，看看，自动就登录上去了！</p>
<p>前面更改SSH配置的时候，已经禁用了root远程登录和使用密码登录，只能使用KEY才能登录进系统。想要维护系统的时候，就用这个KEY登录，再su成root。而且，需要上传/下载文件的时候，就用PSFTP，所有的操作都在SSH连接下进行，还有KEY的保护，安全性不知道提升了多少倍！黑客想要破解真是难于上青天！<br />
Ⅲ、按需启动SSH</p>
<p>我们只在必要的时候启动sshd服务，用完即停止，不给黑客扫描的机会。输入下面的命令：</p>
<p>[Copy to clipboard] [ - ]CODE:<br />
crontab -e</p>
<p>跳到最后，输入下面的内容（中间的空白部分为Tab）：</p>
<p>QUOTE:<br />
# 每天的10:30启动sshd服务<br />
30      10      *       *       *       /usr/sbin/sshd</p>
<p># 10:35即停止sshd服务，也就是说，你只有五分钟的时间可以登录进系统<br />
35      10      *       *       *       kill `cat /var/run/sshd.pid`</p>
<p>保存退出。</p>
<p>上面的时间请酌情修改。sshd服务启动的时间尽量不要太长，5~10分钟应该够了！</p>
<p>Ⅳ、一点安全小常识<br />
私钥请一定保存在安全的地方，不要保存在本地计算机上，并加上足够强度的“保护码”；</p>
<p>本地计算机不要保存远程主机的“指纹”，用一次确认一次（远程主机的指纹保存在注册表的HKEY_CURRENT_USER\Software\SimonTatham\PuTTY项下，可以手动删除）；</p>
<p>不要使用DSA密钥，据说有漏洞的；</p>
<p>不要在公用计算机上连接远程主机，有键盘记录器、木马什么的就麻烦了；</p>
<p>多个远程主机不要使用相同的公钥，最好是使用各自的公钥、私钥；</p>
<p>少用，最好是不用无线网络，加密强度太差，容易被破解；</p>
<p>M$系统下的病毒、木马太多了，推荐客户端转换到Linux/UNIX环境，安全性更高，而且仍然有PuTTY及工具可用；</p>
<p>注意清除本地机器上不必要保留的文件（例如私钥、公钥、主机RSA指纹、C:\Documents and Settings\Administrator目录下的文件等等）。</p>
<p>八、启用Packet Filter防火墙</p>
<p>Packet Filter是非常优秀的包过滤防火墙，OpenBSD核心已经集成了Packet Filter防火墙，不过默认并没有启用，下面我们来启用Packet Filter的强大功能！</p>
<p>[Copy to clipboard] [ - ]CODE:<br />
vi /etc/pf.conf</p>
<p>跳到最后，加入下面的内容：</p>
<p>QUOTE:<br />
# 宏定义<br />
# 请把下面的fxp0换成你自己用的外网网卡，不知道的可以输入ifconfig查看<br />
ext_if=&#8221;fxp0&#8243;</p>
<p># 指定可以使用SSH登录的IP，支持CIDR<br />
admin_add=&#8221;192.168.0.0/24&#8243;</p>
<p># 指定SSH端口。<br />
# 注意，如果在/etc/ssh/sshd_config文件中更改了SSH端口号，这里的也需要同样修改。否则连不上了不要怪偶没有提醒！<br />
ssh_port=&#8221;58937&#8243;</p>
<p># 维持一个持久的表，里面存放的是对本机发动DDoS攻击的IP<br />
table  persist</p>
<p># 选项设定<br />
set require-order yes<br />
set block-policy drop<br />
set optimization aggressive<br />
set loginterface none<br />
set skip on lo0</p>
<p># TCP参数设定<br />
set timeout {interval 3,frag 10}<br />
set timeout {tcp.first 10,tcp.opening 2,tcp.established 600,tcp.closing 20,tcp.finwait 10,tcp.closed 10}</p>
<p># UDP、ICMP及其它参数设定<br />
set timeout {udp.first 20,udp.single 10,udp.multiple 10}<br />
set timeout {icmp.first 10,icmp.error 5}<br />
set timeout {other.first 20,other.single 10,other.multiple 20}<br />
set timeout {adaptive.start 0,adaptive.end 0}</p>
<p># 允许最多有65536个连接<br />
set limit { states 65535, frags 200, src-nodes 65536, tables 65536, table-entries 1048576 }</p>
<p># 包整形<br />
scrub in all<br />
scrub out all</p>
<p># 阻止所有不匹配的包和从DDoS主机来的包<br />
block quick from<br />
block return<br />
block in all<br />
block out all</p>
<p># 防止IP欺骗<br />
antispoof quick for {lo0,$ext_if}</p>
<p># 允许本机访问其他机器<br />
pass out quick on $ext_if inet from $ext_if to any flags S/SA keep state</p>
<p># 允许IPv4地址的客户机访问本地80（www）端口，发起过快连接（DDoS）的主机加入阻止列表。注意是一行，下同<br />
pass in quick on $ext_if inet proto tcp from any to $ext_if port 80 flags S/SA synproxy state (source-track rule,max-src-nodes 200,max-src-states 100,max-src-conn 100,max-src-conn-rate 1000/10,overload  flush global )</p>
<p># 允许IPv6地址的客户机访问本地80（www）端口，发起过快连接（DDoS）的主机加入阻止列表<br />
pass in quick on $ext_if inet6 proto tcp from any to $ext_if port 80 flags S/SA synproxy state (source-track rule,max-src-nodes 200,max-src-states 100,max-src-conn 100,max-src-conn-rate 1000/10,overload  flush global )</p>
<p># 允许管理IP远程连接本机SSH端口<br />
pass in quick on $ext_if inet proto tcp from $admin_add to $ext_if port $ssh_port flags S/SA synproxy state</p>
<p>保存退出。</p>
<p>修改系统配置，使得开机启用PF防火墙：</p>
<p>[Copy to clipboard] [ - ]CODE:<br />
vi /etc/rc.conf.local</p>
<p>跳到最后，加入下面这行：</p>
<p>QUOTE:<br />
pf=YES<br />

<!-- 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 -->
<br />
保存退出。</p>
<p>九、系统启动脚本的修改</p>
<p>修改系统启动脚本，使得MySQL、PHP(fastcgi)、Nginx可以在系统启动的时候自动启动，免去手动启动的麻烦。</p>
<p>[Copy to clipboard] [ - ]CODE:<br />
vi /etc/rc.local</p>
<p>跳到最后，加入下面的内容：</p>
<p>QUOTE:<br />
# 启动时校时。这行也可以加在/etc/daily.local文件的最前面，每天零点自动校时<br />
rdate -n 210.72.145.44<br />
# Start MySQL<br />
if [ -x /usr/local/bin/mysqld_safe ] ; then<br />
echo -n &#8216;Starting MySQL&#8230;&#8217;<br />
su -c mysql root -c &#8216;/usr/local/bin/mysqld_safe &gt;/dev/null 2&gt;&amp;1 &amp;&#8217;<br />
echo &#8220;DONE&#8221;<br />
fi<br />
# Start php-fastcgi<br />
if [ -x /usr/local/bin/spawn-fcgi ] ; then<br />
echo -n &#8216;Starting php-fastcgi&#8230;&#8217;<br />
/usr/local/bin/spawn-fcgi -a 127.0.0.1 -p 9000 -C 6 -u www -f /usr/local/bin/php-fastcgi &gt; /var/run/fcgi.pid<br />
echo &#8220;DONE&#8221;<br />
fi<br />
# Start nginx<br />
if [ -x /usr/local/sbin/nginx ] ; then<br />
echo -n &#8216;Starting nginx&#8230;&#8217;<br />
/usr/local/sbin/nginx<br />
echo &#8220;DONE&#8221;<br />
fi</p>
<p>保存退出。</p>
<p>reboot重启，启动后输入top看看，O.N.M.P.环境已经搭建好！</p>
<p>系统启动后，还要把MySQL自带的测试数据库和匿名用户删除，防止被黑客利用。</p>
<p>默认情况下，新安装的MySQL数据库，root密码为空！同样需要第一时间进行设置，方法见下图：</p>
<p>好了，至此，O.N.M.P.环境的搭建已经结束，剩下的就看各位自行发挥了！</p>
<p>写在最后</p>
<p>其实，系统的安全是个整体工程，并不是用上了OpenBSD这个最安全的操作系统就算万事OK，还有很多事情要做。</p>
<p>更多的是需要在日常工作中积累经验，多分析系统整体的运行情况，多关注网络安全方面的内容，这样才能尽可能的打造安全的运维环境。</p>
<p>本手册只是起到抛砖引玉的作用，希望能吸引更多的人来关注系统安全，希望有更多的人能用上OpenBSD这个主动安全的操作系统，希望能推动OpenBSD在国内的更多普及。如此，则幸甚！</p>
]]></content:encoded>
			<wfw:commentRss>http://www.evanjiang.net.cn/archives/1176.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>unix常用指令及参数</title>
		<link>http://www.evanjiang.net.cn/archives/893.html</link>
		<comments>http://www.evanjiang.net.cn/archives/893.html#comments</comments>
		<pubDate>Wed, 08 Apr 2009 13:48:23 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[debian linux]]></category>
		<category><![CDATA[freebsd unix]]></category>
		<category><![CDATA[netbsd unix]]></category>
		<category><![CDATA[openbsd unix]]></category>
		<category><![CDATA[other linux]]></category>
		<category><![CDATA[redhat linux]]></category>
		<category><![CDATA[sco unix]]></category>
		<category><![CDATA[shell]]></category>
		<category><![CDATA[sun unix]]></category>
		<category><![CDATA[suse linux]]></category>
		<category><![CDATA[www]]></category>
		<category><![CDATA[unix 常用命令 及参数]]></category>

		<guid isPermaLink="false">http://www.evanjiang.net.cn/?p=893</guid>
		<description><![CDATA[<p>常用组合键
ctrl+h,backspace :删除前面的字符.
ctrl+u:删除一整行.
ctrl+c,del,break: 强行终止正在运行的程序.
ctrl+d:
常用指令
1.date:查看当前时间.
2.cal:查看某一个月的月历.
3.Finger 命令:显示一个用户的详细信息.
4.who命令:显示所有登陆用户.who an i
5.clear 命令:执行清屏动作.
6.echo 命令:将命令名后跟随的参数显示在屏幕echo hello </p>
<p>world
7.banner 命令:将命令名后跟的ACSSII字符串以大字的方式显</p>
<p>示在屏幕上banner hello
8.wc 命令:用于计算一个指定的文件中的行数单词及字符数:
   格式wc[-c(计算字符的数目)] [-l(计算行的数目)] [-w(计算</p>
<p>单词的数目)] filename
9.passwd 命令,用于修改口令.
10.man 命令:联机手册
六.shell的基本功能:命令解释器,程序设计语言.
shell的退出命令.
1.exit 主要用于退出B_shell
2.logout 主要用于退出C_shell
3.ctrl+d 用于退出各类shell
第三章 通信
内部通信
外部通信





下.
mail命令模式常用命令
 如有下页则显示,否则退出mail.
p      显示本邮件信息
d      删除当前邮件
n      显示下一个邮件
q      退出 mail,把末删除的邮件保存到个人邮箱中.
R     [...]]]></description>
			<content:encoded><![CDATA[<p>常用组合键<br />
ctrl+h,backspace :删除前面的字符.<br />
ctrl+u:删除一整行.<br />
ctrl+c,del,break: 强行终止正在运行的程序.<br />
ctrl+d:<br />
常用指令<br />
1.date:查看当前时间.<br />
2.cal:查看某一个月的月历.<br />
3.Finger 命令:显示一个用户的详细信息.<br />
4.who命令:显示所有登陆用户.who an i<br />
5.clear 命令:执行清屏动作.<br />
6.echo 命令:将命令名后跟随的参数显示在屏幕echo hello </p>
<p>world<br />
7.banner 命令:将命令名后跟的ACSSII字符串以大字的方式显</p>
<p>示在屏幕上banner hello<br />
8.wc 命令:用于计算一个指定的文件中的行数单词及字符数:<br />
   格式wc[-c(计算字符的数目)] [-l(计算行的数目)] [-w(计算</p>
<p>单词的数目)] filename<br />
9.passwd 命令,用于修改口令.<br />
10.man 命令:联机手册<br />
六.shell的基本功能:命令解释器,程序设计语言.<br />
shell的退出命令.<br />
1.exit 主要用于退出B_shell<br />
2.logout 主要用于退出C_shell<br />
3.ctrl+d 用于退出各类shell<br />
第三章 通信<br />
内部通信<br />
外部通信<1,电子邮件,2.即时通信<br />
一.即时通讯<br />
1.write 交谈命令 (半双工通信)<br />
格式 write student1<br />
ctrl+d 退出write<br />
Write协议:消息发送结束用O(结束)<br />
结束谈话用OO(结束并退出)<br />
2.mesg 消息开关命令.用于查询和开关本终端的消息接收状态.<br />
格式:mesg [-y] [-n]<br />
$ mesg 查询本终端当前的消息接收状态<br />
is y 可以接收消息<br />
is n 拒绝接收消息<br />
$ mesg n 设置关闭状态<br />
$ mesg y 设置打开状态<br />
3.talk 双向通信命令 (全双工方式)<br />
4.wall 广播信息命令<br />
二,电子邮件<br />
$ mail username  发送邮件<br />
$ mail                 接收邮件<br />
系统邮箱:在/usr/mail或/var/mail下,每个用户都有一个以其名字</p>
<p>命名的邮箱.例如:student8的系统邮箱可能为:/var/mail/student8<br />
个人邮箱:个人邮箱通常为用户自己的主目录(home)下的mbox<br />
<span id="more-893"></span><br />
文件.用户读过的邮件如果末删除或转存,则存放在个人邮箱中</p>
<p>.例如:student8的个人邮箱可能是:/home/student8/mbox<br />
1.发送邮件:<br />
$ mail student8<br />
给多个用户发送邮件<br />
a.$ mail student1 student2 student3 把用户列出来.<br />
b.$ mail TEACHER TEACHER为用户组名,即向属于TEACHER</p>
<p>组所有用记发邮件.<br />
c.$ alias usr_list student1 student2 student3给student1 student2 </p>
<p>student3等多个名字建立一个部的别名usr_list,该别名只在本</p>
<p>shell中起作用,退出shell后无效.<br />
$ mail usr_list<br />
把已有的文件作为邮件发送给用户:<br />
$ mail student8 < my_letter<br />
发邮件给不存在的用户:<br />
$ mail meizhegeren<br />
mail命令本身能正常执行,由于无有效的接收方,所以系统把邮</p>
<p>件退回到用户主目录下dead.letter中.<br />
2.接收邮件<br />
不带参数输入mial表示读取邮件.此时已进入出境mail命令模式<br />

<!-- 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 -->
<br />
下.<br />
mail命令模式常用命令<br />
<cr> 如有下页则显示,否则退出mail.<br />
p      显示本邮件信息<br />
d      删除当前邮件<br />
n      显示下一个邮件<br />
q      退出 mail,把末删除的邮件保存到个人邮箱中.<br />
R     回复邮件<br />
!      执行shell命令.<br />
?      显示mail的内部命令.<br />
第四章 文件系统<br />
与目录相关的命令(pwd,cd,mkdir,rmdir,ls)<br />
与文件相关的命令(cp,mv,ln,more,rm)<br />
1.pwd 显示当前工作目录<br />
2.cd  改变当前目录<br />
3.mkdir 创建目录<br />
格式 mkdir dir_name<br />
4.rmdir 删除目录<br />
格式 rmdir dir_name<br />
     a.只能是空目录.<br />
      b.有写的权限<br />
一次操作多个目录<br />
- p 选项.在当前目录下逐级创建目录,也可以逐级删除目录.<br />
5.ls 显示目录<br />
$ ls -a 显示所有文件(以点开头的文件名是隐藏文件)<br />
$ ls -R 显示所有子目录的内容<br />
$ ls &#8211; l  能得到目录中的文件的详细信息.<br />
-:普通 d: 目录 c: 字符设备 b: 块设备 p:管道<br />
$ ls &#8211; C 以多列的格式列表,按列排序.<br />
$ ls &#8211; F 如果是目录,文件名后加/,如果是可执行文件,加*表示.<br />
$ ls &#8211; m 按页宽列文件,以逗号分隔.<br />
$ ls &#8211; p 如果是目录,文件名后加/<br />
$ ls &#8211; r 以字母反序列表<br />
$ ls &#8211; s 以文件块为单位显示文件大小<br />
$ ls &#8211; x 以多列的格式列表,按行排序.<br />
$ ls -G 以不同的颜色显示.<br />
$ ls -lc 显示更新时间<br />
$ ls -i   inode序号将列在第一列<br />
$ ls -lu 显示访问时间<br />
$ ls -I   显示更改时间<br />
6.touch 命令:作用是用来修改文件访问时间更改时间的.并可以</p>
<p>用来创建0字节长度的文件.<br />
格式 touch 命令参数<br />
7.cp 命令:复制文件<br />
格式 cp source target<br />
         $ cp file1 file2 &#8230; Target-dir<br />
$ cp -i 如果目标文件存在,请求确认<br />
$ cp -r 复制目录到新的目录<br />
8.mv 命令:移动文件或命名文件<br />
格式:mv source target<br />
9.ln 命令:ln命令的主要功能是给一个已经存在的文件再取一个</p>
<p>名字.新的文件名与原文件名可以在同一个目录下,也可以以在</p>
<p>不同的目录下,新老文件名代表同一个文件.<br />
格式ln source-file target-file<br />
作用:在现有的文件与新文件之间建立新链接,使一个文件具有</p>
<p>一个以上的名字.<br />
显示文件内容命令<br />
10.cat 命令:用来显示.创建或者合并文件<br />
格式cat filename<br />
11.more 命令:逐屏显示文件内容.翻屏时用<space>键.<br />
格式:$ more filename<br />
12.rm 命令:删除文件(删除后无法恢复)<br />
格式:$ rm file<br />
         $ rm file1 file2<br />
$ rm -i 删除文件前,给出确认<br />
$ rm -r 删除指定的目录及目录中的所有文件和子目录.即删除</p>
<p>整个目录结构.<br />
13.lp 命令:打印命令<br />
14.cut 命令:切取文件内容,用于切取文件中的列或字段.它把文</p>
<p>本文件中每一行的一部分显示输出.运行时必须指定功能选项.<br />
- f 指定字段的位置<br />
-c 指定列的位置<br />
-d 指定字段分隔符,缺省的字段分隔符是制表符tab<br />
15.paste 命令:连接文件.<br />
作用:把文件一行接一行地连接在一起,或者把两个或多个文件</p>
<p>的域连到一个新文件里.<br />
格式: $paste 选项 参数<br />
选项:-d 指定分隔符.默认是制表符<br />
第五章 文件权限<br />
16.chmod 命令:修改文件权限,常用chmod命令修改文件(包括普</p>
<p>通,目录和设备)的访问权限,<br />
格式: chmod pattern filename &#8230;<br />
finename 为要修改的权限文件名.可以有多个.<br />
pattern 为将改变成的权限,可以用两种形式表示:字母式和数字</p>
<p>形式.<br />
a,字母形式(符号模式)<br />
字母形式由用户类别(u,g,o). 如何改变(+,-)和权限(r,w,x)三部分</p>
<p>组成.<br />
u:本用户g:同组用户o:其它用户. + :增加权限 -:删除权限<br />
r:读w:写x:执行<br />
例如:chmod u+x file1<br />
         chmod o-w file2 file3<br />
          chmod go+r file4<br />
b,    数值形式<br />
格式: chmod 777 file1<br />
*新建文件或目录最大权限=状态掩码+新建文件或目录缺省</p>
<p>权限.此时unask为000<br />
对一个新建的文件,umask值为022则指定该文件的权限为644:<br />
对一个新建的目录,umask值为022则指定该目录的权限为755<br />
17.sort 命令:作用在于将指定的文件中的文件进行排序,并把排</p>
<p>序的结果输出到指定的标准输出中.<br />
格式:$srot [-t delimiter] [+field] [.column]][option]<br />
选项: -d 以字典顺序进行排序<br />
          -<br />
18.head 命令:用于查看一个文件.或多个文件的前面几行的内</p>
<p>容.<br />
格式:$ head [-number_of_lines] file(s)<br />
19.tail 命令:用于显示从指定行开始直到文件末尾的文件内容<br />
格式;tail [-number_of_lines | +number_of_lines]file<br />
20.tee 命令:在获得输入后,将把该输入数据送到两个地点:标准<br />

<!-- 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 -->
<br />
输出和文件.<br />
21.grep 命令: 用于选项定包含特定模式的文本行.<br />
21.find 命令:在目录中递归地搜索包括有特定字符的文件名.<br />
22.df 命令:磁盘空间监测命令.显示当前系统中各个逻辑磁盘</p>
<p>中空闲的磁盘块数和空闲的索引节点(即可建立的新文件数)<br />
23.du 命令:查看磁盘使用情况统计,统计指定的目录及所有子</p>
<p>目录的磁盘使用情况,统计单位是磁盘块数.<br />
选项:-a 显示所有文件及子目录<br />
24.fsck 命令:文件系统管理:用于检测和修复文件文件的错误,<br />
25.tar命令:文件存储与备份.该命令可以把文件系统中的一个</p>
<p>或一组文件打成一个文件包.存放到外存上或硬盘上文件系统</p>
<p>的其它地方.常用于多个文件(包括目录)的备份或转移.<br />
格式: tar -cvf target file1 file2 file3 &#8230;把file1 file2 file3等文件备份到</p>
<p>档案文件target中.<br />
         tar -tvf target 检查档案文件target中包含的文件信息.<br />
         tar -xvf targer [file1] 从档案文件target中提取全部或file指定</p>
<p>的文件.<br />
26.shutdown 命令:系统关机<br />
选项:-h 完全关机<br />
         -r 关机并重新启动系统<br />
         time 关机时间,如17:30<br />
         message 关机前向所有已登陆用户发送消息<br />
例如: shutdown -r now 现在关机重启.<br />
27.crypt 文件加密命令:用于对文本文件进行加密和解密.以防</p>
<p>止文件内容泄密.<br />
例如:$ crypt < file > file.cry 对file加密,结果保存在file.cry中.key:加</p>
<p>密口令<br />
        $ crypt <aaa.cry > aaa 对aaa.cry解密,结果保存到aaa中. key:</p>
<p>解密口令<br />
附:$ vi -x file.cry 编辑一个加密后的文件<br />
28.compress/uncompress 文件压缩和解压命令<br />
格式:compress data_file 加压后自动在文件名后加一个.Z<br />
         umcompress abc.Z<br />
29.at 定时执行任务:在指定的时间一次性执行规定的任务.<br />
at 15:30 在15:30分执行<br />
who >> userlist 把上机用户清单发到userlist<br />
30,cron 系统定量执行任务:<br />
31,crontab 任务描述文件的管理命令.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.evanjiang.net.cn/archives/893.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>OpenBSD4.4下架设CS1.6服务器</title>
		<link>http://www.evanjiang.net.cn/archives/875.html</link>
		<comments>http://www.evanjiang.net.cn/archives/875.html#comments</comments>
		<pubDate>Mon, 06 Apr 2009 11:08:42 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[openbsd unix]]></category>
		<category><![CDATA[www]]></category>
		<category><![CDATA[Openbsd cs 服务器 驾设]]></category>

		<guid isPermaLink="false">http://www.evanjiang.net.cn/?p=875</guid>
		<description><![CDATA[<p>Setp 1：环境
1、操作系统OpenBSD4.4。
2、开启Linux支持
#mg /etc/sysctl.conf
去掉#kern.emul.linux=1前的#
#cd /usr/ports/emulators/redhat
#make install</p>
<p>Setp 2：下载所需软件
1：先到http://www.okgogogo.com/download/view.asp?id=393下载hlds_l_02162004.tar.gz
2：接下来下载NoSteamAuthEngines，这个是nosteam补丁：
wget http://www.cstrike.ro/cstrike_files/engine.v15.tgz</p>
<p>Setp 3：安装
#cd /var
#tar zxvf hlds_l_02162004.tar.gz</p>
<p>Setp 4：破解
#tar zxvf engine.tgz
#mv engine_amd.so hlds_l/
#mv engine_i486.so hlds_l/
#mv engine_i686.so hlds_l/</p>
<p>Setp 5：配置
#cd hlds_l
#mg cs
#!/bin/sh
./hlds_run -game cstrike -port 27015 -insecure -ip x.x.x.x +servercfgfile server2.cfg +maxplayers 32 +map de_dust2 -nojoy -noipx -nomaster +localinfo

Setp 6：server.cfg的设置(根据个人情况增添)
rcon_password “rconpassword”
// OP 密码
// “” 表示没有</p>
<p>hostname “CS1.6比赛专用服务器 #A01″
// 服务器名称</p>
<p>sv_region 4
// 服务器所在区域注册参数\r
// 255=全球
// 0=美国东部
// 1=美国西部
// 2=南美洲\r
// [...]]]></description>
			<content:encoded><![CDATA[<p>Setp 1：环境<br />
1、操作系统OpenBSD4.4。<br />
2、开启Linux支持<br />
#mg /etc/sysctl.conf<br />
去掉#kern.emul.linux=1前的#<br />
#cd /usr/ports/emulators/redhat<br />
#make install</p>
<p>Setp 2：下载所需软件<br />
1：先到http://www.okgogogo.com/download/view.asp?id=393下载hlds_l_02162004.tar.gz<br />
2：接下来下载NoSteamAuthEngines，这个是nosteam补丁：<br />
wget http://www.cstrike.ro/cstrike_files/engine.v15.tgz</p>
<p>Setp 3：安装<br />
#cd /var<br />
#tar zxvf hlds_l_02162004.tar.gz</p>
<p>Setp 4：破解<br />
#tar zxvf engine.tgz<br />
#mv engine_amd.so hlds_l/<br />
#mv engine_i486.so hlds_l/<br />
#mv engine_i686.so hlds_l/</p>
<p>Setp 5：配置<br />
#cd hlds_l<br />
#mg cs<br />
#!/bin/sh<br />
./hlds_run -game cstrike -port 27015 -insecure -ip x.x.x.x +servercfgfile server2.cfg +maxplayers 32 +map de_dust2 -nojoy -noipx -nomaster +localinfo<br />
<span id="more-875"></span><br />
Setp 6：server.cfg的设置(根据个人情况增添)<br />
rcon_password “rconpassword”<br />
// OP 密码<br />
// “” 表示没有</p>
<p>hostname “CS1.6比赛专用服务器 #A01″<br />
// 服务器名称</p>
<p>sv_region 4<br />
// 服务器所在区域注册参数\r<br />
// 255=全球<br />
// 0=美国东部<br />
// 1=美国西部<br />
// 2=南美洲\r<br />
// 3=欧洲<br />
// 4=亚洲<br />
// 5=澳洲<br />
// 6=中东<br />
// 7=非洲</p>
<p>sv_rcon_maxfailures 9999<br />
// 输入OP密码 错误次数上限<br />
// 达到上限则封禁对方的IP</p>
<p>sv_rcon_banpenalty 5<br />
// 封禁的时限 单位 分钟<br />
// 0=永久<br />

<!-- 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 -->
<br />
sv_maxupdaterate 30<br />
// 服务器每秒更新最大频率\r<br />
// 根据实际网络状况调节<br />
// 默认=30<br />
// 局域=101</p>
<p>sv_minupdaterate 20<br />
// 服务器每秒更新最小频率\r</p>
<p>sv_unlag 1<br />
// 玩家延时补偿<br />
// 0=关闭<br />
// 1=开启 (默认)</p>
<p>sv_maxunlag 0.5<br />
// 延时补偿最大值默认 0.5<br />
// 0.5=500毫秒 (默认)</p>
<p>sv_voiceenable 1<br />
// 服务器是否允许麦克风语音通讯<br />
// 0=禁止<br />
// 1=允许 (默认)</p>
<p>sv_unlagsamples 1<br />
// 延时补偿数据包平均采样数量\r<br />
// 默认=1</p>
<p>sv_unlagpush 0<br />
// 服务器推进延时补偿\r<br />
// 0=关闭 (默认)<br />
// 1=开启\r</p>
<p>mp_autokick 0<br />
// 自动踢除不动的玩家\r<br />
// 0=关闭<br />
// 1=开启 (比赛默认)</p>
<p>mp_autocrosshair 0<br />
// 自动瞄准<br />
// 0=关闭 (默认)<br />
// 1=开启\r</p>
<p>mp_autoteambalance 0<br />
// 自动平衡双方人数<br />
// 0=关闭 (比赛默认)<br />
// 1=开启\r</p>
<p>mp_buytime 0.25<br />
// 每回合购买武器装备时间单位分钟\r<br />
// 比赛默认=0.25</p>
<p>mp_consistency 1<br />
// 防止某些模型被更改\r<br />
// 0=关闭<br />
// 1=开启 (默认)</p>
<p>mp_c4timer 35<br />
// C4爆炸倒计时单位秒<br />
// 比赛默认=35</p>
<p>mp_decals 300<br />
// 墙壁上的血花弹孔贴图细节数据传送(200-300)</p>
<p>mp_falldamage 1<br />
// 高处落下伤害<br />
// 0=关闭<br />
// 1=开启 (默认)</p>
<p>mp_fadetoblack 0<br />
// 死后黑屏<br />
// 0=关闭 (默认)<br />
// 1=开启\r</p>
<p>mp_flashlight 1<br />
// 手电筒\r<br />
// 0=禁止<br />
// 1=允许 (默认)</p>
<p>mp_forcechasecam 2<br />
// 死后跟随<br />
// 0=所有玩家\r<br />
// 1=仅队友\r<br />
// 2=仅队友，主视角 (比赛默认)</p>
<p>mp_forcecamera 2<br />
// 死后视角选择<br />
// 0=全部视角<br />
// 1=仅队友，全部视角<br />
// 2=仅队友，主视角 (比赛默认)</p>
<p>mp_footsteps 1<br />
// 脚步声\r<br />
// 0=关闭<br />
// 1=开启 (默认)</p>
<p>mp_fraglimit 0<br />
//杀人数上限(1~n)，超过上限就换地图\r<br />
// 0=关闭 (默认)</p>
<p>mp_freezetime 7<br />
// 每回合开始冻结时间单位秒</p>
<p>mp_friendlyfire 1<br />
// 友军伤害<br />
// 0=关闭<br />
// 1=开启 (默认)</p>
<p>mp_friendly_grenade_damage 1<br />
// 友军手雷伤害<br />
// 0=关闭<br />
// 1=开启\r</p>
<p>mp_hostagepenalty 0<br />
// 惩罚人质杀手\r<br />
// 0=不惩罚 (默认)<br />
// 1~N=人质被杀数量，超过则踢出该玩家\r</p>
<p>mp_limitteams 10<br />
// 两队人数差异上限<br />
// 超过此上限，新玩家只能当观察员\r<br />
// 比赛默认=10</p>
<p>sv_logbans 1<br />
// 服务器日志里记录Ban掉玩家的内容<br />
// 0=不记录\r<br />
// 1=记录</p>
<p>mp_logecho 1<br />
// 将服务器日志反馈到控制台<br />
// 0=关闭<br />
// 1=开启\r</p>
<p>mp_logdetail 3<br />
// 服务器日志里记录攻击信息<br />
// 0=不记录任何信息\r<br />
// 1=记录敌人攻击<br />
// 2=记录队友攻击<br />
// 3=记录所有攻击\r</p>
<p>mp_logfile 1<br />
// 服务器记录日志为文件<br />
// 0=不记录\r<br />
// 1=记录</p>
<p>mp_logmessages 1<br />
// 服务器日志里记录谈话内容<br />
// 0=不记录\r<br />
// 1=记录</p>
<p>mp_maxrounds 0<br />
// 回合上限，达到此上限，自动重新载入新地图<br />
// 0=无回合上限 (默认)</p>
<p>mp_playerid 0<br />
// 当准星指向敌人或队友时，显示他们的名字\r<br />
// 0=关闭 (比赛默认)<br />
// 1=开启\r</p>
<p>mp_roundtime 1.75<br />
// 每回合时限单位分钟\r</p>
<p>mp_timelimit 0<br />
// 地图最大时限，达此时限，自动重新载入新地图<br />
// 0=无时限\r</p>
<p>mp_tkpunish 0<br />
// 惩罚队友杀手\r<br />
// 0=关闭 (默认)<br />
// 1=开启\r</p>
<p>mp_startmoney 800<br />
// 第一回合开始金钱(800~16000)<br />
// 加时赛=10000</p>
<p>mp_winlimit 0<br />
// 一方最大胜利回合数，达到此数量，自动重新载入新地图<br />
// 0=无限制 (默认)</p>
<p>sv_aim 0<br />
// 自动瞄准<br />
// 0=关闭 (默认)<br />
// 1=开启\r</p>
<p>sv_airaccelerate 10<br />
// 玩家在空中移动的速度<br />
// 默认=10</p>
<p>sv_airmove 1<br />
// 在空中移动&#038;转向<br />
// 0=禁止<br />
// 1=允许(默认)</p>
<p>sv_allowdownload 1<br />
// 客户端下载服务器资源<br />
// 0=禁止<br />
// 1=允许 (默认)</p>
<p>sv_allowupload 1<br />
// 客户端上传自己的喷图<br />
// 0=禁止<br />
// 1=允许 (默认)</p>
<p>sv_alltalk 0<br />
// 警匪通话<br />
// 0=禁止 (默认)<br />
// 1=允许</p>
<p>sv_proxies 1<br />
// HLTV代理<br />
// 0=禁止<br />
// 1=允许 (默认)</p>
<p>sv_cheats 0<br />
// 作弊模式<br />
// 0=关闭 (默认)<br />
// 1=开启\r</p>
<p>sv_clienttrace 1.0<br />
// 客户端模型的范围框的尺寸<br />
// 默认 1.0</p>
<p>sv_clipmode 0<br />
// 锁定客户端快速模式\r<br />
// 0=关闭(默认)<br />
// 1=开启\r</p>
<p>sv_contact boezombie@gmail.com<br />
// 服务器构建者的联系邮箱</p>
<p>sv_friction 4<br />
// 地面摩擦力默认 4<br />
// 数值越低，摩擦越小</p>
<p>sv_gravity 800<br />
// 重力默认 800</p>
<p>sv_maxrate 25000<br />
// 服务器最大传输速率 <0-25000><br />
// (服务器上传带宽 x 125) /服务器设定的最大人数 = 要设的值\r<br />
// 0=无限制\r<br />
// 局域=25000</p>
<p>sv_maxspeed 320<br />
// 客户端最大移动速度</p>
<p>sv_minrate 0<br />
// 服务器最小传输速率 <0-25000><br />
// sv_maxrate / 300 = 要设的值\r<br />
// 0=无限制\r</p>
<p>sv_restartround 0<br />
// 重新开始第一回合在n秒后</p>
<p>sv_restart 0<br />
// 重新开始游戏在n秒后<br />
// 作用等同于sv_restartround</p>
<p>sv_send_logos 1<br />
// 客户端相互之间传送喷图\r<br />
// 0=禁止<br />
// 1=允许(同时确保sv_allowdownloads键值为1)</p>
<p>sv_sendvelocity 0<br />
// 服务器混合物理运算，适用于较好配置的服务器\r<br />
// 0=关闭<br />
// 1=开启\r</p>
<p>sv_send_resources 1<br />
// 自动向客户端传送地图关联的 &#038; .res文件里包括的资源文件<br />
// 0=关闭<br />
// 1=开启(同时确保sv_allowdownload为1)<br />

<!-- 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 -->
<br />
sv_stepsize 18<br />
// 玩家的步伐距离\r<br />
// 默认 18</p>
<p>sv_stopspeed 75<br />
// 玩家停止移动时的速度默认 75</p>
<p>sv_timeout 65<br />
// 客户端连接服务器超时的时限，达到时限则断开连接</p>
<p>sv_voicecodec voice_speex<br />
// 语音通话解码<br />
// voice_miles是HL引擎长期以来用的语音解码(默认)，占用带宽较大，为32kbps<br />
// voice_speex是Valve新加入的解码，优于voice_miles，占用带宽较少，为2.4kbps至15.2kbps </p>
<p>sv_voicequality 5<br />
// 客户端语音通话质量(确保sv_voicecodec voice_speex)<br />
// 1=非常差………..占用带宽 2.4 kbps<br />
// 2=差……………占用带宽 6.0 kbps<br />
// 3=中等………….占用带宽 8.0 kbps<br />
// 4=好……………占用带宽 11.2 kbps<br />
// 5=非常清晰………占用带宽 15.2 kbps</p>
<p>allow_spectators 1<br />
// 观察员模式\r<br />
// 0=禁止<br />
// 1=允许</p>
<p>decalfrequency 60<br />
// 玩家喷图的时间间隔单位秒</p>
<p>edgefriction 2<br />
// 玩家与玩家、墙壁、物体之间的摩擦<br />
// 默认 2</p>
<p>host_framerate 0<br />
// 与Demo录制有关<br />
// 0 // n=0 为正常(默认)<br />
// n>1 为快录\r</p>
<p>log on<br />
// 开始记录日至\r</p>
<p>pausable 1<br />
// 客户端暂停游戏\r<br />
// 0=禁止<br />
// 1=允许</p>
<p>mapcyclefile mapcycle.txt<br />
// 地图循环列表所在的.txt文件<br />
// *.txt = cstrike\*.txt文件</p>
]]></content:encoded>
			<wfw:commentRss>http://www.evanjiang.net.cn/archives/875.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>OpenBSD firewall using pf</title>
		<link>http://www.evanjiang.net.cn/archives/851.html</link>
		<comments>http://www.evanjiang.net.cn/archives/851.html#comments</comments>
		<pubDate>Mon, 23 Mar 2009 14:38:52 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[It Tips]]></category>
		<category><![CDATA[openbsd unix]]></category>
		<category><![CDATA[OpenBSD firewall using pf]]></category>

		<guid isPermaLink="false">http://www.evanjiang.net.cn/?p=851</guid>
		<description><![CDATA[<p>It is really easy to configure an OpenBSD gateway for a private network. Here are the following steps:</p>
<p>Lock down the box
Install second ethernet card in the OpenBSD box
Customize the kernel
Enable packet forwarding, dhcp, firewall and network address translation
Configure machines behind NAT
Familiarize with pf
Quality of Service (QoS)
References
Lock down the box
The first step to lock down the [...]]]></description>
			<content:encoded><![CDATA[<p>It is really easy to configure an OpenBSD gateway for a private network. Here are the following steps:</p>
<p>Lock down the box<br />
Install second ethernet card in the OpenBSD box<br />
Customize the kernel<br />
Enable packet forwarding, dhcp, firewall and network address translation<br />
Configure machines behind NAT<br />
Familiarize with pf<br />
Quality of Service (QoS)<br />
References<br />
Lock down the box<br />
The first step to lock down the firewall box is to disable all unnecessary running services. Luckily, OpenBSD out of the box is really secure even with ident, comsat, daytime, time, rstatd and rusersd enabled in /etc/inetd.conf. Comment out mentioned services in /etc/inetd.conf and edit /etc/rc.conf and make sure portmap, sendmail and ntpd daemons are disabled as well. Don&#8217;t disable inetd as you will need it later for ftp-proxy.<br />
check_quotas=NO<br />
ntpd=NO<br />
sendmail_flags=NO</p>
<p>sshd is enabled out of the box. If you don&#8217;t plan to use it, disable it with sshd_flags=NO<br />
Once you disabled unnecessary services, go to unixcircle to remotely port scan your own box from the outside. Be careful when you do this behind a firewall box as the port scan script will scan the firewall instead. If you have another box, use nmap to scan the box from the inside.</p>
<p>Get the latest OpenBSD security patches and manually apply or download all the patches in one file or use AnonCVS to synchronize to stable release and build from source.</p>
<p>Make sure you check out the 3.2 stable branch with -rOPENBSD_3_2. Otherwise, you&#8217;re checking out the &#8220;current&#8221; branch instead.</p>
<p>Finally, readup on SANS&#8217;s The Twenty Most Critical Internet Security Vulnerabilities (Updated)</p>
<p><span id="more-851"></span><br />
Install second Ethernet card in the OpenBSD box<br />
Use any supported ethernet card for the second NIC in the OpenBSD machine. One card will be given a public IP address (assigned by your ISP or obtained dynamically, e.g., with DHCP) and the other will be given an IP address in a non-routable network. Your choices for private network addresses must come from one of these ranges (see RFC 1918):<br />
10.0.0.1 &#8211; 10.255.255.254      netmask 255.0.0.0<br />
172.16.0.1 &#8211; 172.31.255.254    netmask 255.240.0.0<br />
192.168.0.1 &#8211; 192.168.255.254  netmask 255.255.0.0</p>
<p>Assume the first card is &#8220;ep&#8221;, create /etc/hostname.ep0 with the following x.x.x.x netmask x.x.x.x where x.x.x.x is what you choose above.<br />
# First NIC &#8211; private<br />
192.168.1.1 netmask 255.255.255.0 media 10baseT</p>
<p>And if you have a static IP address for the second NIC, you naturally need to have it configured as /etc/hostname.ep1 as well.<br />
# Second NIC with public IP address<br />
123.221.8.1 netmask 255.190.280.0 media 10baseT</p>
<p>Be sure to indicate a correct IP address and netmask for both interfaces. Once you have chosen a private network address range for your inside machines, stay with that same range.<br />
Whatever address you choose for the first interface in the OpenBSD gateway becomes the default gateway IP address for all machines on the inside private network.</p>
<p>Customize the kernel<br />
Compile the new kernel and remove any unwanted devices from the kernel.<br />
Retrieve the kernel source and unpack it as:</p>
<p># tar xzvf srcsys.tar.gz -C /usr<br />
( kernel source unpacking output&#8230; )<br />
&#8230;</p>
<p>Or use AnonCVS to get just the kernel source it:<br />
# setenv CVSROOT anoncvs@anoncvs.ca.openbsd.org:/cvs<br />
# cd /usr<br />
# cvs -q get -rOPENBSD_3_2 -P src/sys<br />
( checking out files output&#8230; )<br />
&#8230;<br />
# cd /sys/arch/i386/conf</p>
<p>I usually name the kernel to the machine hostname, but you can give it any name. Edit the kernel config file:<br />
Remove any hardware related options that are not relevant to your machine. One way to find out what to keep is to consult the dmesg output and remove all the rest. For all available kernel options, refer to GENERIC in the same directory as your kernel file and /sys/conf/GENERIC or man options(4).</p>
<p>Save the kernel config file and then compile and install it:</p>
<p># config firewall<br />
# cd ../compile/firewall<br />
# make depend; make<br />
( kernel building output&#8230; )<br />
&#8230;<br />
# cp /bsd /bsd.old<br />
# cp bsd /bsd<br />
# reboot</p>
<p>This will retain the old kernel as /bsd.old just in case something has gone awry with the new one and the box doesn&#8217;t boot. If that happens you can type &#8216;bsd.old&#8217; at the boot: prompt to boot the old kernel.<br />
Enable packet forwarding, dhcp, firewall and network address translation<br />
To enable packet forwarding uncomment the following line in /etc/sysctl.conf and for extra protection, enable encryption on swap pages:<br />
net.inet.ip.forwarding=1        # 1=Permit forwarding (routing) of packets<br />
vm.swapencrypt.enable=1         # 1=Encrypt pages that go to swap</p>
<p>To enable high performance data transfers on hosts according to Enabling High Performance Data Transfers on Hosts, add the following to /etc/sysctl.conf:<br />
# 1. Path MTU discovery: enabled by default<br />
# 2. TCP Extension (RFC1323): enabled by default<br />
# 3. Increase TCP Window size for increase in network performance<br />
net.inet.tcp.recvspace=65535<br />
net.inet.tcp.sendspace=65535<br />
# 4. SACK (RFC2018): enabled by default</p>
<p>And if you receive your routable address assignment dynamically through DHCP:<br />
# echo dhcp > /etc/hostname.ep1</p>
<p>The dhcp server will assign the IP, netmask and default gateway for interface &#8220;ep1&#8221;. /etc/resolv.conf will be created with &#8220;search&#8221; and &#8220;nameservers&#8221; statements from the ISP.<br />
Filter rule:</p>
<p>Starting with OpenBSD 3.2, filter and nat rules are combined into /etc/pf.conf. The order of /etc/pf.conf is really important and the format of /etc/pf.conf must follow this order:</p>
<p>1. Options<br />
2. Scrub<br />
3. NAT &#038; RDR<br />
4. Filter</p>
<p>If there are no filter rules, the default action is pass.</p>
<p>Network Address Translation rule:</p>
<p>For clients behind NAT to work, 1 NAT and 1 RDR rule is sufficient:</p>
<p># NAT internal IP addresses of range 192.168.1.0/24 to external routable<br />
# IP on ep1 interface<br />
nat on ep1 from 192.168.1.0/24 to any -> ep1</p>
<p># Translate outgoing ftp control connections to send them to localhost<br />
# for proxying with ftp-proxy(8) running on port 8081<br />
rdr on ep0 proto tcp from any to any port 21 -> 127.0.0.1 port 8081</p>
<p>ftp-proxy runs inside inetd, add the following line to /etc/inetd.conf in order for ftp clients behind NAT to work by going through ftp-proxy daemon:<br />
127.0.0.1:8081  stream tcp nowait root /usr/libexec/ftp-proxy ftp-proxy</p>
<p>As a result, ftp port and port 8081 will be opened. ftp-proxy supports -w option which will use tcp_wrappers to control source ftp client as well as destination ftp server access control based on /etc/hosts.allow and /etc/hosts.deny. Assume source ftp client IP 192.168.1.2 doesn&#8217;t have permission to use ftp, a similar log entry in /var/log/messages when attempted to reach ftp.netbsd.org<br />
Sep 14 15:55:38 firewall ftp-proxy[20970]: tcpwrappers rejected: 192.168.1.2 -> ftp.netbsd.org</p>
<p>An example of a working /etc/pf.conf</p>
<p>Transparent proxy:</p>
<p>If there&#8217;s a mail server as 192.168.1.2 and a DNS server as 192.168.1.3 inside the private network, use &#8220;rdr&#8221; to transparent proxying. Since NAT happens before &#8220;rdr&#8221;, a &#8220;pass in&#8221; is required in /etc/pf.conf for the translated packets to flow into the mail server and DNS server.</p>
<p>/etc/pf.conf:</p>
<p># Redirect incoming smtp traffic to mail server behind NAT<br />
rdr on ep1 proto tcp from any to 157.161.48.183/32 port 25 -> 192.168.1.2 port 25</p>
<p># Redirect incoming domain traffic to DNS server behind NAT<br />
rdr on ep1 proto { tcp,udp } from any to 157.161.48.183/32 port 53 -> 192.168.1.3 port 53</p>
<p>Finally, enable pf in /etc/rc.conf:<br />
pf=YES                   # Packet filter / NAT / logging using pflogd</p>
<p>Configure machines behind NAT<br />
All the machines on the private network should be configured to use the address of the private interface of the OpenBSD box as the default gateway. To set the internal boxes to the default OpenBSD gateway on various operating systems with IP address: 192.168.1.1<br />
AIX: edit /etc/rc.net and add /usr/sbin/route add 192.168.1.1 gateway >> $LOGFILE 2>&#038;1</p>
<p>FreeBSD: edit /etc/rc.conf and add defaultrouter=&#8221;192.168.1.1&#8243;<br />
HP-UX: edit /etc/rc.config.d/netconf and add ROUTE_GATEWAY[0]=&#8221;192.168.1.1&#8243;<br />
Linux Redhat: edit /etc/sysconfig/network and add GATEWAY=192.168.1.1<br />
NetBSD:  echo &#8220;192.168.1.1&#8243; > /etc/mygate<br />
OpenBSD: echo &#8220;192.168.1.1&#8243; > /etc/mygate</p>
<p>Solaris: echo &#8220;192.168.1.1&#8243; > /etc/defaultrouter<br />
Win2k: Start-Settings->Control Panel->Network and Dial-up Connections->Local Area Network-><br />
       Properties->Internet Protocol (TCP/IP)->Default Gateway->192.168.1.1</p>
<p>If you don&#8217;t want to reboot to pick up the IP address for the default gateway, use &#8220;route&#8221; to manually add the default route.<br />
AIX: route add 0 192.168.1.1</p>
<p>HP-UX: route add 192.168.1.1</p>
<p>FreeBSD,NetBSD,OpenBSD,Solaris: route add default 192.168.1.1</p>
<p>Linux Redhat: route add default gw 192.168.1.1</p>
<p>Familiarize with pf<br />
Once your firewall is online, you should start reading pf.conf(5), nat.conf(5), ftp-proxy(8), pfctl(8), pf(4) and The OpenBSD Packet Filter HOWTO. Also consult IPFILTER-HOWTO since both pf and IP Filter have 90% identical syntax. One noticable difference is OpenBSD pf doesn&#8217;t support IP Filter &#8220;keep frags&#8221; syntax. The alternative is to use &#8220;scrub&#8221; statement.<br />
Each time /etc/pf.conf or /etc/nat.conf are modified, you have to reload them using pfctl. Reloading these rules will flush all current active connections. Unlike IPFilter, pf needs to enable nat and pf rules manually.</p>
<p>Flush current nat rules &#038; reload:</p>
<p># /sbin/pfctl -F nat &#038;&#038; /sbin/pfctl -N /etc/pf.conf</p>
<p>Flush current filter rules &#038; reload:<br />
# /sbin/pfctl -F rules &#038;&#038; /sbin/pfctl -R /etc/pf.conf</p>
<p>Show filter information (statistics and counters):<br />
# pfctl -s info</p>
<p>To display the current list of active MAP/Redirect filters and active sessions:<br />
# /sbin/pfctl -s state</p>
<p>To find out the &#8220;hit&#8221; statistic for each individual rule in /etc/pf.conf:<br />
# /sbin/pfctl -s rules -v</p>
<p>Watch port scans going by on the screen:<br />
/var/log/pflog is a binary file generated by pflogd so you can&#8217;t just view it. Use tcpdump instead:</p>
<p># tcpdump -i pflog0</p>
<p>Read the log for pf activities:</p>
<p># tcpdump -n -e -ttt -r /var/log/pflog</p>
<p>Quality of Service (QoS)<br />
Bandwidth limiting:<br />
OpenBSD 3.2 has ALTQ integrated in the base system. The kernel generic kernel is also compiled with options ALTQ so you&#8217;re ready to use. Otherwise, download the latest KAME snap kit which has ALTQ bundle from: http://www.kame.net/retrieve.html</p>
<p>Now, to configure a token bucket regulator (tbrconfig) for the interface ep1 to rate limit the pipe from 100Mbps to 10Mbps for outgoing connection:</p>
<p># tbrconfig ep1 10M auto<br />
ep1: tokenrate 10.00M(bps)  bucketsize 12.21K(bytes)<br />
#</p>
<p>To remove the installed token bucket regulator on ep1:<br />
# tbrconfig -d ep1<br />
deleted token bucket regulator on ep1<br />
#</p>
<p>Class-based queuing (CBQ):<br />
From man options(4) description of CBQ:</p>
<p>CBQ achieves both partitioning and sharing of link bandwidth by hierarchically structured classes. Each class has its own queue and is assigned its share of bandwidth. A child class can borrow bandwidth from its parent class as long as excess bandwidth is available.</p>
<p>Here is an example of a working /etc/altq.conf. /etc/altq.conf is read by altqd so to enable it on startup, edit /etc/rc.conf and change altqd_flags=NO to altqd_flags=&#8221;". Or just manually start altqd. altqd won&#8217;t start if there are errors in /etc/altq.conf. Watch /var/log/messages for any information.</p>
<p>Here&#8217;s the class hierarchy: cbq.txt</p>
<p>#<br />
# ep1: Interface to a 10M link<br />
#<br />
#<br />
interface ep1 bandwidth 10M cbq<br />
class cbq ep1 root NULL pbandwidth 100<br />
#<br />
# meta classes<br />
#<br />
class cbq ep1 ctl_class root pbandwidth 4 control<br />
class cbq ep1 def_class root borrow pbandwidth 95 default<br />
#<br />
# Allocate bandwidth for:<br />
# firstclass: 70%<br />
# businessclass: 15%<br />
# generalclass: 5%<br />
#<br />
class cbq ep1 firstclass def_class borrow pbandwidth 70<br />
class cbq ep1 businessclass def_class borrow pbandwidth 15<br />
class cbq ep1 generalclass def_class borrow pbandwidth 5<br />
#<br />
# Allocate bandwidth for firstclass (tcp) data classes:<br />
# tcp: 28%<br />
# smtp: 10%<br />
# http: 30%<br />
# dns: 2%<br />
#<br />
class cbq ep1 tcp firstclass borrow pbandwidth 28 red<br />
    filter ep1 tcp 0 0 0 0 6    # other tcp<br />
class cbq ep1 smtp firstclass borrow pbandwidth 10 red<br />
    filter ep1 smtp 0 0 0 25 6  # smtp<br />
    filter ep1 smtp 0 25 0 0 6  # smtp<br />
class cbq ep1 http firstclass borrow pbandwidth 30 red<br />
    filter ep1 http 0 0 0 80 6  # http<br />
    filter ep1 http 0 80 0 0 6  # http<br />
class cbq ep1 dns firstclass borrow pbandwidth 2 red<br />
    filter ep1 dns 0 0 0 53 6   # dns<br />
    filter ep1 dns 0 53 0 0 6   # dns</p>
<p>#<br />
# Allocate bandwidth for businessclass (udp) classes:<br />
# udp: 10%<br />
# dns: 5%<br />
#<br />
class cbq ep1 udp businessclass borrow pbandwidth 10 red<br />
    filter ep1 udp 0 0 0 0 17   # udp<br />
class cbq ep1 dns businessclass borrow pbandwidth 5 red<br />
    filter ep1 dns 0 0 0 53 17  # dns<br />
    filter ep1 dns 0 53 0 0 17  # dns<br />
#<br />
# Allocate bandwidth for generalclass (icmp) classe:<br />
# icmp: 5%<br />
#<br />
class cbq ep1 icmp generalclass borrow pbandwidth 5 red<br />
    filter ep1 icmp 0 0 0 0 1   # icmp</p>
<p>Now, run altqstat and monitor the bandwidth. You should see something similar here: cbq stat<br />
Weighted Fair Queueing (WFQ):</p>
<p>To use weighted fair queueing, add the following to kernel file.</p>
<p>option          ALTQ_WFQ</p>
<p>By default, WFQ allocates 256 queues and packets are mapped into one of the queues by hashing the destination address. So, packets for the same host will be put in the same queue.<br />
To enable WFQ on interface &#8220;ep0&#8243; and &#8220;ep1&#8243;, add the following lines to your altq.conf(5) and start altqd.</p>
<p>interface ep0 bandwidth 10M wfq<br />
interface ep1 bandwidth 10M wfq</p>
<p>The following command can be used to monitor the wfq statistics.<br />
altqstat -i ep1</p>
<p>You should see something similar:<br />
% altqstat<br />
altqstat: wfq on interface ep1<br />
wfq on ep1: 256 queues are used</p>
<p>[QID] WEIGHT QSIZE(KB) SENT(pkts)     (KB)       DROP(pkts)     (KB)     bps<br />
[ 141]  100    0         14              1          0              0     0.09K<br />
[ 103]  100    0          2              0          0              0     0.09K<br />
[ 131]  100    0         11              1          0              0         0<br />
[ 155]  100    0         10              0          0              0         0<br />
[ 124]  100    0          9              0          0              0         0<br />
[ 184]  100    0          5              0          0              0         0<br />
[  12]  100    0          2              0          0              0         0<br />
[   0]  100    0          0              0          0              0         0<br />
[   1]  100    0          0              0          0              0         0<br />
[   2]  100    0          0              0          0              0         0</p>
<p>First-In First-Out Queueing (FIFOQ):<br />
To use first-in first-out queueing, add the following to kernel file.</p>
<p>option          ALTQ_FIFOQ</p>
<p>To enable FIFOQ on interface ep1, add the following line to your altq.conf(5) and start altqd.<br />
interface ep1 bandwidth 10M fifoq</p>
<p>Run altqstat and you should see something similar:<br />
% altqstat<br />
altqstat: fifoq on interface ep1<br />
 q_len:0 q_limit:50 period:2<br />
 xmit:2 pkts (108 bytes) drop:0 pkts (0 bytes)<br />
 throughput: 0.17Kbps<br />
 q_len:0 q_limit:50 period:2<br />
 xmit:2 pkts (108 bytes) drop:0 pkts (0 bytes)<br />
 throughput: 0bps<br />
&#8230;</p>
<p>Random Early Detection (RED):<br />
Since RED is part of ALTQ, no kernel option is required.</p>
<p>To enable random early detection on interface ep1, add the following line to your altq.conf(5) and start altqd.</p>
<p>interface ep1 bandwidth 10M red</p>
<p>Run altqstat and you should see something similar:<br />
% altqstat<br />
altqstat: red on interface ep1<br />
 weight:512 inv_pmax:10 qthresh:(5,15)<br />
 q_len:0 (avg: 0.00), q_limit:60<br />
 xmit:1 pkts, drop:0 pkts (forced: 0, early: 0)<br />
 throughput: 0.09Kbps</p>
<p> weight:512 inv_pmax:10 qthresh:(5,15)<br />
 q_len:0 (avg: 0.00), q_limit:60<br />
 xmit:1 pkts, drop:0 pkts (forced: 0, early: 0)<br />
 throughput: 0bps<br />
&#8230;</p>
<p>Diffserfv traffic conditioner (CDNR):<br />
>From man options(4):</p>
<p>Traffic conditioners are components to meter, mark, or drop incoming packets according to some rules. As opposed to queueing disciplines, traffic conditioners handle incoming packets at an input interface.</p>
<p>To use conditioner to drop incoming packets from a particular IP address, add the following to kernel file.</p>
<p>option          ALTQ_CDNR</p>
<p>To enable conditioner on interface ep1, add the following line to your altq.conf(5) and start altqd.<br />
#<br />
interface ep1<br />
#<br />
# Drop all packets coming in from 255.255.255.255 (ficticious)<br />
#<br />
conditioner ep1 dropper <drop><br />
     filter ep1 dropper 0 0 255.255.255.255 0 0</p>
<p>Run altqstat to monitor the drop packets:<br />
% altqstat<br />
altqstat: cdnr on interface _fxp0<br />
actions:<br />
  pass:471 drop:3 mark:0 next:0 return:0 none:0</p>
<p>actions:<br />
  pass:501 drop:3 mark:0 next:0 return:0 none:0<br />
&#8230;</p>
<p>Priority Queueing (PRIQ):<br />
>From man options(4):</p>
<p>PRIQ implements a simple priority-based queueing. A higher priority class is always served first.</p>
<p>High number has higher priority. Maximum value is 15 and minimum value is 0. Default is 0. A higher priority class is always served first in PRIQ. Priority must be unique for the interface.</p>
<p>To use priority queueing to prioritize based on type of packet, add the following to kernel file.</p>
<p>option          ALTQ_PRIQ</p>
<p>To enable priority queueing on interface ep1, add the following line to your altq.conf(5) and start altqd.<br />
#<br />
# Prioritize based on protocol:<br />
#<br />
# tcp: high priority<br />
# udp:  medium priority<br />
# icmp: low priority<br />
# others: bottom priority<br />
#<br />
interface ep1 bandwidth 10M priq<br />
#<br />
class priq ep1 highest_class NULL priority 3<br />
     filter ep1 highest_class 0 0 0 0 6<br />
class priq ep1 medium_class NULL priority 2<br />
     filter ep1 medium_class 0 0 0 0 17<br />
class priq ep1 lowest_class NULL priority 1<br />
     filter ep1 lowest_class 0 0 0 0 1<br />
class priq ep1 bottom_class NULL priority 0 default</p>
<p>% altqstat<br />
altqstat: priq on interface ep1</p>
<p>ep1:<br />
[highest_class] handle:0xe09fd0c0 pri:3<br />
  measured: 0.34Kbps qlen: 0 period:180<br />
     packets:180 (25637 bytes) drops:0<br />
[medium_class] handle:0xe09f1d40 pri:2<br />
  measured: 0bps qlen: 0 period:25<br />
     packets:25 (1997 bytes) drops:0<br />
[lowest_class] handle:0xe09fdcc0 pri:1<br />
  measured: 0bps qlen: 0 period:19<br />
     packets:19 (1862 bytes) drops:0<br />
[bottom_class] handle:0xe09a4680 pri:0<br />
  measured: 0bps qlen: 0 period:0<br />
     packets:0 (0 bytes) drops:0<br />
&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.evanjiang.net.cn/archives/851.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Introduction to OpenBSD  Firewall/Gateway  Unix Workstation</title>
		<link>http://www.evanjiang.net.cn/archives/849.html</link>
		<comments>http://www.evanjiang.net.cn/archives/849.html#comments</comments>
		<pubDate>Mon, 23 Mar 2009 14:34:10 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[It Tips]]></category>
		<category><![CDATA[cvs]]></category>
		<category><![CDATA[dns]]></category>
		<category><![CDATA[ftp]]></category>
		<category><![CDATA[openbsd unix]]></category>
		<category><![CDATA[pf]]></category>
		<category><![CDATA[samba]]></category>
		<category><![CDATA[www]]></category>
		<category><![CDATA[Introduction to OpenBSD  Firewall/Gateway  Unix Workstation]]></category>

		<guid isPermaLink="false">http://www.evanjiang.net.cn/?p=849</guid>
		<description><![CDATA[<p>Abstract
This is a quick tutorial on how to set up an OpenBSD 3.1 system. The first part covers setting up a firewall, NAT proxy, time and DHCP server on a system connected to the Internet via broadband like DSL or cable. The second part covers things that would be installed on a desktop machine: graphical [...]]]></description>
			<content:encoded><![CDATA[<p>Abstract<br />
This is a quick tutorial on how to set up an OpenBSD 3.1 system. The first part covers setting up a firewall, NAT proxy, time and DHCP server on a system connected to the Internet via broadband like DSL or cable. The second part covers things that would be installed on a desktop machine: graphical window managers etc. </p>
<p>The reader is not expected to be a Unix expert (why would a Unix expert need this how-to?) &#8212; if you don&#8217;t understand something, or something looks intimidating, read on and come back to it. If something still doesn&#8217;t make sense, let me know. </p>
<p>I don&#8217;t cover what I consider &#8220;advanced&#8221; usage such as tracking -CURRENT or CVS snapshots. If you want to do that, I assume you know which FAQs to read! </p>
<p>This document may be freely reproduced and redistributed under the terms of the GNU Free Documentation License Version 1.1; with the invariant section being this entire document, with no Front-Cover Texts and no Back-Cover Texts. </p>
<p>In other words, if you want to copy this document in its entirety, feel free to do so; if you wish to modify it (as in providing a translation, or taking sections to include in other documents) please send me email. Needless to say, documents that this document links to will have their own copyrights. </p>
<p>New!<br />
I have a shell script that sets up everything mentioned here. This is still experimental but if you try it, please let me know how it goes. Save this file to disk and run it by typing &#8220;sh config31-fw.sh&#8221;. (Doesn&#8217;t handle PPPoE [the beast].) </p>
<p>There is a new section called Tips and Stuff where I put things I&#8217;ve found or written that are useful sysadmin tools. </p>
<p>Introduction<br />
Why OpenBSD? It&#8217;s simple and secure. Your firewall machine should not have lots of things installed on it; therefore no exotic hardware, graphical desktops, X11 servers etc. &#8212; put those on your desktop machine. A simpler system is more robust and more secure; this machine only offers SMTP (email), ssh, ping/traceroute and optionally HTTP (web) to the outside world. And since it&#8217;s running Unix, you can log in to it &#8212; securely &#8212; using ssh from anywhere on the Internet and make any changes you need to. (N.B.: never use telnet to connect to a machine over the Internet! Anyone can eavesdrop and grab important information like passwords. Only use ssh, which encrypts all communication so that eavesdroppers don&#8217;t get any information. And verify those key fingerprints or you leave yourself open to a man-in-the-middle attack. For information do a web search for public key cryptosystems; a good place to start is OpenSSH.) </p>
<p>The utility and security of having this kind of machine: a firewall protects your data and systems from the Big, Bad Internet. When the bad guys are out to vandalise machines on the Internet, MS-Windows machines of various kinds are prime targets because they suck. Er, I mean, Windows is really hard to secure. (Not that an incompetently run Unix machine is any better, of course.) When you dialled in on the phone, your machine was on the &#8216;net for brief periods; with DSL or cable it&#8217;s vulnerable all the time. </p>
<p>This document also describes how to set up an OpenBSD system as a Unix workstation. We will go over setting up X11 (the window system) etc. I assume that you will be using a different machine as your workstation. Important: Unix systems can be set up in various ways; I do things a certain way and that&#8217;s what this document will cover. Other people (wizards and newbies alike) may do things differently. In case it matters, I&#8217;ve been using Unix since 1982, have been a sysadmin on-and-off since 1986 (VAX/BSD, SunOS 4.x, Solaris 2.x, HP/UX, AT&#038;T 3B5 SVR6 etc.) I&#8217;ve been a C programmer since the early 80s. Today I design and implement back-end network servers on Solaris. </p>
<p>This tutorial assumes that you have some familiarity with using Unix: what filenames look like, how to copy and edit files etc. There&#8217;s a decent Unix tutorial on the web. The most important command to remember is man (short for &#8220;manual&#8221;) &#8212; if I say something like &#8220;read the documentation for foobar it means you should type man foobar. One other piece of Unix argot: if you hear someone write select(2) it indicates that the manual for select is in section 2, i.e. you would read the manpage by typing man 2 select. You should also read the OpenBSD documentation: particularly the OpenBSD FAQ. Bookmark that link right now.<br />
<span id="more-849"></span><br />
NAT (Network Address Translation) allows you to connect lots of PCs up to one network connection. When any of the machines inside the firewall wants to make a connection to some server out there on the internet, the firewall/NAT box intercepts that request, and sends the request off as though it came from the firewall/NAT machine. When the reply arrives, it is sent off to the machine that made the connection. Neither the server nor the machines on the inside know that all this is going on. </p>
<p>Aside: NAT is also called PAT, for &#8220;Port Address Translation.&#8221; Also, read this interesting article by HRH Prince Philip, Duke of Edinburgh, on setting up PAT and DHCP on Cisco routers. The whole routergod.com site features many celebrities offering helpful tips on various network issues. </p>
<p>Even if you don&#8217;t want plan on having more than one PC at home, NAT is useful, because it allows the machine running your firewall to be different from your main workstation. You probably want to install fancy hardware and software on your machine; but every additional package installed on a firewall makes it more vulnerable. </p>
<p>Network Address Translation (NAT)</p>
<p>Note: if you only have one machine on the &#8220;inside&#8221;, you don&#8217;t need an ethernet hub; use a crossover cable to connect the two machines directly. This also has the advantage that you can get a full-duplex connection between the machines (a hub only allows a half-duplex connection). </p>
<p>Note: you can buy little NAT/DHCP boxes from various manufacturers for about $150, but where&#8217;s the fun in that? Besides, who knows how strong the security is on those things. With OpenBSD you know you&#8217;re getting the best. </p>
<p>Building the machine<br />
The machine itself: I prefer to build these machines up from individual components rather than buying a pre-made box. That way I can get name-brand supported components, and it works out slightly cheaper since I don&#8217;t have to get exotic video cards, sound cards, CD-ROM drives etc. (Not to mention a Fisher-Price operating system that you will be required to pay for.) </p>
<p>Can you build a PC? Well, no one showed me how, but I&#8217;ve managed to put together about 10 or so systems, so it can&#8217;t be that hard. If you&#8217;ve assembed anything with screwdrivers etc. you&#8217;ll be fine. There are numerous sites on the web that walk you through building a PC. Go do a Google search and read those. I especially like the one at Acme Labs by Jef Poskanzer. There&#8217;s also an excellent motherboard finder at Acme. </p>
<p>Caveat: specific recommendations will be outdated as soon as I write them! I like to use AMD CPUs because I believe Intel is evil and as far as possible I&#8217;d like to not buy their products. I&#8217;d get the current not-top-of-the-line CPU i.e. the one that costs about $50 and a compatible motherboard that costs in the range of $70. I stay away from integrated components because they&#8217;re usually garbage. (For a server that I don&#8217;t use directly I might get integrated video.) Spend about $30-50 on RAM, $30 on ethernet, $60 on an IDE disk, $30 for a case (with power supply). I usually find the best prices on components at Directron and CompuVest (warning: uses Java). These have both been non-sleazy (everything was as described in their catalog and shipping was prompt) in all my dealings with them &#8212; but let me know if you find any evidence of sleaziness. </p>
<p>All these components add up to around $300 &#8212; and that&#8217;s brand-new stuff. If you have any old components lying around, they will be fine. You don&#8217;t need a keyboard, mouse or monitor when the system is up and running &#8212; all maintenance on it can be done over the network. (While you&#8217;re installing the OS on the machine you will need to hook up a keyboard, monitor and CD-ROM drive to it, of course.) </p>
<p>While installing the system, I plug in a spare CD-ROM drive, keyboard and monitor. Change the BIOS settings so that the machine will boot without a keyboard etc. Boot off the OpenBSD 3.1 CD and install the system. All the hardware should be recognised without any problems. (The installation guide booklet that comes with the CDs is excellent.) </p>
<p>The easiest way to install OpenBSD is to buy the distribution on CDs. Although you can install it via the network, buying the CD will help make sure that the OpenBSD project will continue to improve and better the system. If you can afford an outlay of US$40, please buy the CDs from the OpenBSD ordering site. </p>
<p>When you&#8217;re installing OpenBSD, the installer program will ask you for disklabel information (partitions). On a Unix system, a group of files organised together is called a filesystem. The disk is partitioned into various pieces each of which will hold one filesystem. This is the filesystem breakup and partition sizes I&#8217;d use for a 12GB disk (if your disk is bigger, you can just increase the size of /var (for web files) or /home (for your personal files) &#8212; the system will be more than happy with these sizes for /, /tmp and /usr):</p>
<p>/dev/wd0a      100M     /<br />
/dev/wd0d      400M     /tmp<br />
/dev/wd0e      4GB      /var<br />
/dev/wd0g      2GB      /usr<br />
/dev/wd0h      5GB      /home<br />
(The convention is that a is always /, b is swap and c is the whole disk.) Your web files will live in /var, and your other files in /home. </p>
<p>This is all overkill; /usr only needs about 600M or so. Say pad it to 1GB. A 2GB disk would be plenty for the system, but if the cheapest disk you can get is 13GB&#8230;. </p>
<p>Note for Unix newcomers: the disk is named /dev/wd0, and in this case it has 5 partitions with names /dev/wd0a, /dev/wd0d, /dev/wd0e, /dev/wd0g and /dev/wd0h. And the different partitions don&#8217;t get different &#8220;drive letters&#8221; as in some primitive operating systems; once the system is installed, it looks to the user that there is just one bunch of files; Unix will figure out the right thing to do. After the system has been installed and you&#8217;ve booted off the hard disk, log in and (this is important!) type man afterboot; it will remind of some things that you need to do to complete the installation &#8212; pick passwords, create user accounts, check network settings etc. Also, man hier will introduce you to the way the system is organised &#8212; which files live where. In fact, let me say that again: </p>
<p>After the first normal boot of the system, be sure to read these manpages:<br />
$  man afterboot<br />
$  man hier<br />
Also run dmesg(8) to learn more about your hardware and the driver names that OpenBSD uses for them. </p>
<p>Which packages to install? A good starting point would be to accept the defaults. For a desktop system (workstation), you will want all the X11 packages also. I install everything. </p>
<p>There! And make sure you keep reading the manpages &#8212; OpenBSD manpages are a thing of beauty, complete, up-to-date and informative. And also read the OpenBSD FAQ on the web &#8212; much of this information is also found there. </p>
<p>Configuring the network<br />
For my outside connection I have DSL and a static IP number (from Speakeasy &#8212; I recommend them over PacBell etc. &#8212; I&#8217;m so happy I switched). Other DSL options are PPPoE that PacBell likes to set people up with, or DHCP which is what you usually get over cable. A completely bogus DSL installation is the USB device they try to foist on customers with Windows. Danger, Will Robinson! They stink; they&#8217;re unsupported on any free O/S, and even on Windows they work about half the time. </p>
<p>In *BSD the network cards are named according to the driver used. For the Lite-On (DEC Tulip) cards, the driver is called dc, and the Intel EtherExpress Pro is fxp; so my two ethernet cards are dc0 and fxp0. (If you had two cards that both used the dc driver, they would be dc0 and dc1.) For the inside network I use the &#8220;private&#8221; (non-routable) IP numbers 192.168.1.* which will make the inward-facing network card 192.168.1.1. The OpenBSD initialization asks you for IP numbers for the two cards. Enter the appropriate ones &#8211; the IP number your ISP gave you for dc0, and 192.168.1.1 for fxp0. For PPPoE, the outside interface is tun0 and it will figure out its own IP address. If you&#8217;re supposed use DHCP on your DSL or cable connection, type in dhcp. </p>
<p>It is important to remember which network will be the outside and which the inside. If the two cards are identical, the easiest way is to look at the MAC number. Every ethernet card ever made has a unique ID called its MAC number. This will be printed on the card, usually as a sticker. When the kernel boots up, it will print the MAC numbers of each card it finds:</p>
<p>fxp0 at pci0 dev 9 function 0 &#8220;Intel 82557&#8243; rev 0x0c: irq 11, address 00:02:b3:a0:3a:50<br />
dc0 at pci0 dev 10 function 0 &#8220;Lite-On PNIC&#8221; rev 0&#215;20: irq 10 address 00:a0:cc:55:ab:1c<br />
So the card that has a MAC number ending ab1c is dc0; the other is fxp0. (If the two network cards you have are different types, as in this case, there&#8217;s no problem, of course. The kernel bootup messages is still be useful to tell you what names the system is using for them.) </p>
<p>(There&#8217;s some rule about where the cards are plugged in so which one gets number 0 and which no. 1, but I can never remember that.) </p>
<p>PPPoE<br />
The beast! PPPoE is a pain in the ass but ISPs like it because it makes things simpler for them &#8212; they don&#8217;t have to maintain lists of IP numbers. Also, they can run a crappy service and keep dropping the connection and that&#8217;s ok, you&#8217;re expected to reconnect. It&#8217;s the Micros**t philosophy of &#8220;make something really crappy and expect people to just re-start the whole system a couple of times a day.&#8221; It&#8217;s a pain in the ass for us because its MTU is 1492 instead of 1500 which used to require changes on every machine inside the network &#8212; but now thanks to the &#8220;mssfixup&#8221; flag we don&#8217;t have to any more. </p>
<p>The files you will need to change for PPPoE all live in /etc/ppp/. </p>
<p>Configure system files<br />
To set up the system, the files you will be editing are:/etc/rc.conf, /etc/myname, /etc/mygate, /etc/pf.conf, /etc/nat.conf, /etc/*.conf, /etc/hostname.interface, /var/named/*. </p>
<p>Edit /etc/rc.conf. On my servers I run SMTP, Apache, and ssh. In other words, from the outside it handles email, web acess and secure shell for remote logins. For convenience, on the inside I have a private name server (DNS) and NTP server for accurate time. To get sendmail, NTP, httpd, and NAT to work, these are the lines to change: </p>
<p>sendmail_flags=&#8221;-bd -q30m&#8221;      # for normal use: &#8220;-bd -q30m&#8221;<br />
named_flags=&#8221;"                  # for normal use: &#8220;&#8221;<br />
ntpdate_flags=&#8221;put.server.here&#8221; # for normal use: NTP server; run before ntpd starts<br />
httpd_flags=&#8221;"                  # for normal use: &#8220;&#8221; (or &#8220;-DSSL&#8221; after reading ssl(8))<br />
dhcpd_flags=-q                  # for normal use: &#8220;-q&#8221;<br />
pf=YES                          # Packet filter / NAT<br />
ntpd=YES                        # run ntpd if it exists<br />
pf_rules=/etc/pf.conf           # Packet filter rules file<br />
nat_rules=/etc/nat.conf         # NAT rules file<br />
Make sure that /etc/sysctl.conf has this line in it:</p>
<p>net.inet.ip.forwarding=1        # 1=Permit forwarding (routing) of packets<br />
Get the names of NTP servers close to where you are and put that name in the ntpdate value. Here&#8217;s a list of public NTP servers. </p>
<p>Update ssh<br />
Warning: ssh in OpenBSD 3.1 has a bug!<br />
Upgrading openssh to 3.4 is strongly recommended. See the OpenSSH for OpenBSD page for details. In brief, you will download ftp://ftp.openbsd.org/pub/OpenBSD/OpenSSH/openssh-3.4.tgz and execute the following steps (as root): </p>
<p># cd /usr/src/usr.bin<br />
# tar xvfz &#8230;/openssh-3.4.tgz<br />
# cd ssh<br />
# make obj<br />
# make cleandir<br />
# make depend<br />
# make<br />
# make install<br />
# cp ssh_config sshd_config /etc/ssh<br />
# mkdir /var/empty<br />
Using vipw(8) you will add this line to your password file: </p>
<p>sshd:*:27:27::0:0:sshd privsep:/var/empty:/sbin/nologin<br />
Then add this line to /etc/group: </p>
<p>sshd:*:27:<br />
NAT and firewall rules<br />
OpenBSD 3.1 has a new packet filter &#8212; 2.9 used ipf but 3.x has a re-written from scratch one called pf. The details are not important; pf config files are much simpler. I decided that my outside interface would be dc0, and the inside one fxp0. (If you&#8217;re using PPPoE, the outside interface will be tun0.) Firewall rules (they tell the gateway what kind of network traffic should be allowed into the internal network) live in /etc/pf.conf; NAT configuration is in /etc/nat.conf. </p>
<p>Here&#8217;s a sample /etc/pf.conf &#8212; very little is accessible from the outside, but machines on the inside can go out with no restrictions. In your files you&#8217;d replace dc0 and fxp0 with the names of your outward- and inward-facing ethernet cards, respectively.</p>
<p>#####################################################################<br />
#<br />
# IP packet filtering rules (firewall)<br />
# Shamim Mohamed 3/2002</p>
<p># See pf.conf(5) for syntax and examples</p>
<p># If you change this file, run<br />
#    pfctl -R /etc/pf.conf<br />
# to update kernel tables (also run &#8220;pfctl -e&#8221; if pf was not running)</p>
<p># Network interfaces<br />
internal = &#8220;fxp0&#8243;<br />
external = &#8220;dc0&#8243;</p>
<p># Services visible from the outside &#8212; remove any you&#8217;re not using<br />
services = &#8220;{ ssh, http, https, smtp }&#8221;</p>
<p># You shouldn&#8217;t need to change anything below this line<br />
#####################################################################</p>
<p># Non-routable IP numbers<br />
nonroutable = &#8220;{ 192.168.0.0/16, 127.0.0.0/8, 172.16.0.0/12, 10.0.0.0/8,<br />
    0.0.0.0/8, 169.254.0.0/16, 192.0.2.0/24, 204.152.64.0/23, 224.0.0.0/3,<br />
    255.255.255.255/32 }&#8221;</p>
<p># All rules are &#8220;quick&#8221; so go strictly top to bottom</p>
<p># Fix fragmented packets<br />
scrub in all</p>
<p># Don&#8217;t bug loopback<br />
#<br />
pass out quick on lo0 from any to any<br />
pass in quick on lo0 from any to any</p>
<p># Don&#8217;t bother the inside interface either<br />
#<br />
pass out quick on $internal from any to any<br />
pass in quick on $internal from any to any</p>
<p>#####################################################################<br />
#<br />
# First, we deal with bogus packets.<br />
#</p>
<p># Block any inherently bad packets coming in from the outside world.<br />
# These include ICMP redirect packets and IP fragments so short the<br />
# filtering rules won&#8217;t be able to examine the whole UDP/TCP header.<br />
#<br />
block in log quick on $external inet proto icmp from any to any icmp-type redir</p>
<p># Block any IP spoofing atempts.  (Packets &#8220;from&#8221; non-routable<br />
# addresses shouldn&#8217;t be coming in from the outside).<br />
#<br />
block in quick on $external from $nonroutable to any</p>
<p># Don&#8217;t allow non-routable packets to leave our network<br />
#<br />
block out quick on $external from any to $nonroutable</p>
<p>#<br />
#####################################################################</p>
<p>#####################################################################<br />
#<br />
# Now the normal filtering rules<br />
#</p>
<p># ICMP: allow incoming ping and traceroute only<br />
#<br />
pass in quick on $external inet proto icmp from any to any icmp-type { \<br />
    echorep, echoreq, timex, unreach }<br />
block in log quick on $external inet proto icmp from any to any</p>
<p># TCP: Allow ssh, smtp, http and https incoming. Only match<br />
# SYN packets, and allow the state table to handle the rest of the<br />
# connection.<br />
#<br />
pass in quick on $external inet proto tcp from any to any port $services flags S/SA keep state</p>
<p># Of course we need to allow packets coming in as replies to our<br />
# connections so we keep state. Strictly speaking, with packets<br />
# coming from our network we don&#8217;t have to only match SYN, but<br />
# what the hell.<br />
#<br />
pass out quick on $external inet proto tcp  from any to any flags S/SA keep state<br />
pass out quick on $external inet proto udp  all keep state<br />
pass out quick on $external inet proto icmp from any to any keep state</p>
<p># End of rules. Block everything to all ports, all protocols and return<br />
# RST (TCP) or ICMP/port-unreachable (UDP).<br />
#<br />
block return-rst in log quick on $external inet proto tcp from any to any<br />
block return-icmp in log quick on $external inet proto udp from any to any<br />
block in quick on $external all</p>
<p>#<br />
# End of file<br />
#<br />
#####################################################################<br />
Read the pf documentation and understand these rules. </p>
<p>This is the NAT config /etc/nat.conf &#8212; this allows machines on the inside network to transparently make connections to the outside world:</p>
<p>#####################################################################<br />
#<br />
# NAT rules<br />
# Shamim Mohamed 3/2002</p>
<p># See nat.conf(5) for syntax and examples</p>
<p># replace dc0 with external interface name, 192.168.1.0/24 with internal<br />
# network (if different)</p>
<p># nat: packets going out through dc0 with source address 192.168.1.0/24 will<br />
# get translated as coming from 12.34.56.78 (or whatever the external IP no.<br />
# is). State is created for such packets, and incoming packets will be<br />
# redirected to the internal address.</p>
<p>nat on dc0 from 192.168.1.0/24 to any -> dc0</p>
<p># End of file<br />
#####################################################################<br />
The system should already have setup /etc/hostname.dc0 and /etc/hostname.fxp0 (or whatever your network device names are) for you. Each file will have the IP number and netmask. This is what these files would look like:</p>
<p>$ cat /etc/hostname.fxp0<br />
inet 192.168.1.1 255.255.255.0 NONE<br />
$ cat /etc/hostname.dc0<br />
inet 123.45.67.89 255.255.255.0 NONE<br />
(The $ is the prompt; cat types a file out to the output.) If you&#8217;re using DHCP, the outside interface&#8217;s hostname file will say dhcp. </p>
<p>Other important files are /etc/myname &#8212; your hostname &#8212; and /etc/mygate &#8212; your default gateway to the outside world (your ISP told you what this should be &#8212; it&#8217;s usually the same as your IP number except that the last number is replaced with a 1 or 254.) </p>
<p>PPPoe<br />
If you have PPPoE (you unfortunate soul!) things are different. You shouldn&#8217;t have /etc/mygate; and the file describing the outside interface, /etc/hostname.dc0 in my example, will only have one word in it: up. This tells the system to bring up the interface at boot time, but to do nothing else &#8212; pppoe will do the rest. </p>
<p>The main file is /etc/ppp/ppp.conf and this is what it should look like:</p>
<p>default:<br />
 set log Phase Chat LCP 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 dc0&#8243;<br />
 disable acfcomp protocomp<br />
 deny acfcomp<br />
 set mtu 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 login<br />
 set authkey password<br />
 enable dns<br />
 enable mssfixup<br />
Use your login name and password where indicated. The &#8220;set device&#8221; line tells ppp which physical device to use to talk to the outside world. You also have to tell the system to start PPPoE at boot time. That can be done with this little snippet of shell script: </p>
<p>echo -n &#8220;Trying to establish PPPoE DSL&#8221;; ppp -ddial pppoe<br />
for i in 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0; do<br />
    sleep 5<br />
    echo -n.$i&#8221;<br />
    if /usr/local/sbin/adsl-status>/dev/null; then<br />
        break<br />
    fi<br />
done<br />
echo<br />
/usr/local/sbin/adsl-status<br />
Where adsl-status is a little shell-script that tests to see whether the PPP link has come up properly: </p>
<p>#!/bin/sh</p>
<p>IP=$(/sbin/ifconfig tun0 | awk &#8216;/netmask/{print $2}&#8217;)</p>
<p>if [ -z "$IP" ]; then<br />
   echo &#8220;ADSL link is down.&#8221;<br />
   exit 1<br />
else<br />
   echo &#8220;ADSL is up, IP address $IP&#8221;<br />
   exit 0<br />
fi<br />
Now the question is: where should we put the little loop that tries to get ppp going? The right place to put all these is in /etc/rc.local. However this has the drawback that the outside network hasn&#8217;t been initialised while the rest of the system is coming up, which causes some scary-looking error messages from NAT to be printed at boot time. So I do something a little un-kosher: I put the ppp initialisation in /etc/netstart right at the end: </p>
<p>&#8230;<br />
echo -n &#8216; ADSL&#8230; &#8216;; ; ppp -ddial pppoe<br />
for i in 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0; do<br />
    sleep 5<br />
    echo -n.$i&#8221;<br />
    if /usr/local/sbin/adsl-status>/dev/null; then<br />
        break<br />
    fi<br />
done<br />
echo<br />
/usr/local/sbin/adsl-status<br />
Now remember that each time the PPP link goes up or down, the IPF and NAT rules must be re-done. The files /etc/ppp/ppp.linkup and /etc/ppp/linkdown are scripts that get run by ppp. Here&#8217;s /etc/ppp/ppp.linkup: </p>
<p>MYADDR:<br />
 ! sh -c &#8220;/sbin/route del default&#8221;<br />
 ! sh -c &#8220;/sbin/route add default HISADDR -mtu 1492&#8243;<br />
 ! sh -c &#8220;/sbin/pfctl -F all -R /etc/pf.conf -N /etc/nat.conf -e&#8221;<br />
 ! sh -c &#8220;/usr/local/sbin/ntpd -p /var/run/ntpd.pid&#8221;<br />
And this is /etc/ppp/linkdown: </p>
<p>MYADDR:<br />
 ! sh -c &#8220;/sbin/pfctl -F all -d&#8221;<br />
Configuring email<br />
Sendmail should have been setup automatically since you edited /etc/rc.conf but I&#8217;ve occasionally had to make one change in /etc/mail/sendmail.cf: </p>
<p>Djmy-domain-name.com<br />
(If you don&#8217;t own a domain, or plan on having it point to your DSL machine, you don&#8217;t need sendmail.) </p>
<p>You should have a normal user account that you&#8217;re going to use (never log in as root! Always use su or sudo). Administrative email should be forwarded to you; if your normal username is zippy edit /etc/mail/aliases and make sure you make the appropriate lines look like this:</p>
<p># Well-known aliases &#8212; these should be filled in!<br />
root: zippy<br />
manager: zippy<br />
dumper: zippy<br />
One thing you should consider is being an email handler for friends. My DSL service goes down too often &#8212; every few months. This is too unreliable for my tastes. What I do is collaborate with friends to accept and queue email for them, and they do the same for me. Example: for my domain foo.com the primary mail exchanger is gateway.foo.com, the OpenBSD firewall/gateway. A friend of mine has bar.com, and his email gateway is gateway.bar.com. I set up a secondary mail exchanger in my domain records as gateway.bar.com. If my DSL line gateway.foo.com goes down and someone out there wants to send email to me at foo.com, her machine will use gateway.bar.com instead and email will wait on that machine until my machine is back on the network. I want to perform the same service for my friend &#8212; if gateway.bar.com is down, I want people to be able to send my machine the email destined for bar.com and fubar.org (another friend&#8217;s domain). This goes in the file /etc/mail/relay-domains on my gateway box: </p>
<p>bar.com<br />
fubar.org<br />
Now the machine will accept email for my friends&#8217; domains bar.com and fubar.org as well as for itself and forward their messages on. If the machine it&#8217;s trying to forward to is down, it will put them in the queue and keep re-trying for a while. (My friend at bar.com does similar things to his /etc/mail/relay-domains.) </p>
<p>Setting up DNS<br />
You probably shouldn&#8217;t be running the primary DNS server for your domain on your DSL box; DSL may not be reliable enough for that. Get someone else to do it for you for free, like http://www.zoneedit.com/. </p>
<p>However, it is nice to have a local private DNS because lots of daemons (services that run in the background, like the web server) like to do reverse lookups of IP numbers, so we should have a DNS server for the private network. Also, this installation will give you a caching nameserver which should improve your browsing speed. </p>
<p>The files live in /var/named. Assuming your domain is called fake-domain.org, edit named.boot and add these lines:</p>
<p>primary fake-domain.org                 fake-domain.db<br />
primary 1.168.192.in-addr.arpa          fake-domain.rev</p>
<p>; your static IP number, reversed<br />
primary 89.67.45.123.in-addr.arpa      dsl.rev</p>
<p>; remember to add your ISP&#8217;s nameservers here!<br />
forwarders			1.2.3.4 5.4.3.2<br />
(Anything starting with a semicolon is a comment.) Here fakedomain.org can be a real domain you have or a fake; and instead of 89.67.45.123 use your static IP but reversed i.e. you would use that line if your IP number were 123.45.67.89. And change the IP numbers on the forwarders line to the nameservers your ISP told you to use. </p>
<p>There are three files you need to create. The first is /var/named/namedb/fake-domain.db:</p>
<p>@       IN      SOA     gateway.fake-domain.org.     root.fake-domain.org.<br />
(<br />
                                14      ; Serial<br />
                                10800   ; Refresh<br />
                                3600    ; Retry<br />
                                604800  ; Expire<br />
                                86400 ) ; Minimum</p>
<p>        IN      NS      gateway.fake-domain.org.</p>
<p>gateway IN      A       192.168.1.1<br />
libelle IN      A       192.168.1.2<br />
discus  IN      A       192.168.1.4<br />
ventus  IN      A       192.168.1.3<br />
wander  IN      A       192.168.1.5<br />
brad    IN      A       192.168.1.12<br />
jack    IN      A       192.168.1.13</p>
<p>; your static IP number<br />
dsl     IN      A       123.45.67.89</p>
<p>www     IN      CNAME   dsl<br />
mail    IN      CNAME   dsl<br />
In this network, there are six machines on the inside and those are their names and IP Number assignments. The OpenBSD gateway machine is named &#8220;gateway&#8221;. Change these entries to names of the machines on your private network. You can give them any IP number that starts with 192.168.1. Of course if you have three machines on your network, there will only by three entries.) </p>
<p>This is the second file you need to create, /var/named/fake-domain.rev:</p>
<p>@       IN      SOA     gateway.fake-domain.org.     root.fake-domain.org.<br />
(<br />
                                14      ; Serial<br />
                                10800   ; Refresh<br />
                                3600    ; Retry<br />
                                604800  ; Expire<br />
                                86400 ) ; Minimum</p>
<p>        IN      NS      gateway.fake-domain.org.</p>
<p>1       IN      PTR     gateway.fake-domain.org.<br />
2       IN      PTR     libelle.fake-domain.org<br />
3       IN      PTR     ventus.fake-domain.org<br />
4       IN      PTR     discus.fake-domain.org.<br />
5       IN      PTR     wander.fake-domain.org.<br />
12      IN      PTR     brad.fake-domain.org.<br />
13      IN      PTR     jack.fake-domain.org.<br />
(Those trailing dots are important.) And here&#8217;s the third, /var/named/namedb/dsl.rev:</p>
<p>@       IN      SOA     gateway.fake-domain.org.     root.fake-domain.org.<br />
(<br />
                                14      ; Serial<br />
                                10800   ; Refresh<br />
                                3600    ; Retry<br />
                                604800  ; Expire<br />
                                86400 ) ; Minimum</p>
<p>        IN      NS      gateway.fake-domain.org.</p>
<p>        IN      PTR     dsl.fake-domain.org.<br />
PPPoE<br />
Yes, again more stupid special cases for PPPoE. For one thing, your IP address from the outside keeps changing so all the stuff about dsl.rev doesn&#8217;t apply. However, more important: you don&#8217;t know what your ISP&#8217;s DNS servers are! And they could change which machines you&#8217;re supposed to use each time you connect! What you have to do is: connect &#8220;by hand&#8221; one time, and see which DNS servers you got. After ppp.conf has been written, you can run ppp -ddial pppoe and pray. If all goes well, ifconfig tun0 should show you two lines: </p>
<p>$  /sbin/ifconfig tun0<br />
tun0: flags=11<UP,POINTOPOINT> mtu 1492<br />
        inet 63.201.32.40 &#8211;> 63.201.39.254 netmask 0xff000000<br />
That means everything worked. Now look at /etc/resolv.conf &#8212; there should be one or more lines in there that say which nameservers should be used. Put these IP numbers in the forwarders line in /var/named/named.boot. </p>
<p>One other wrinkle: the /etc/resolv.conf that ppp makes for you doesn&#8217;t know about your domain, or that you&#8217;re running a nameserver on your machine. To get around these problems, I created another file /etc/resolv.conf-working: </p>
<p>nameserver 192.168.1.1<br />
lookup file bind<br />
search fake-domain.org<br />
In /etc/ppp/ppp.linkup I tell it to overwrite the created resolv.conf with this one: </p>
<p> ! sh -c &#8220;cp /etc/resolv.conf-working /etc/resolv.conf&#8221;<br />
(Add that to the end of the file that you&#8217;ve already created.) This allows all programs running on the machine to be able to use all the good things about a local caching nameserver &#8212; things like being able to refer to internal hosts by short name etc. </p>
<p>Other machines on the internal network<br />
Go to the other machines on your network (the ones inside your firewall) and set them up with the static IP numbers you assigned above, e.g. the machine wander gets an IP number of 192.168.1.5. All the machines should use 192.168.1.1 for the gateway and use 192.168.1.1 for the DNS server. For more details on DNS, read the excellent O&#8217;Reilly book &#8220;DNS and BIND&#8221;; for more on setting up slightly more complex DNS servers than the one described here, go to the OpenBSD &#8212; DNS site maintained by Samiuela LV Taufa. </p>
<p>Setting up DHCP<br />
Above in the DNS setup all internal machines are assigned their own IP numbers. Running DHCP allows guest machines to hook up to the network without fuss. Depending on your comfort level with setting up your other machines, you might also prefer to use DHCP over assigning static IPs.This is what /etc/dhcpd.conf should look like:</p>
<p>#       $OpenBSD: dhcpd.conf,v 1.1 1998/08/19 04:25:45 form Exp $<br />
#<br />
# DHCP server options.<br />
# See dhcpd.conf(5) and dhcpd(8) for more information.<br />
#</p>
<p># Network:              192.168.1.0/255.255.255.0<br />
# Domain name:          my.domain<br />
# Name servers:         192.168.1.3 and 192.168.1.5<br />
# Default router:       192.168.1.1<br />
# Addresses:            192.168.1.32 &#8212; 192.168.1.127<br />
#<br />
shared-network LOCAL-NET {<br />
        option  domain-name &#8220;fake-domain.org&#8221;;<br />
        option  domain-name-servers 192.168.1.1;</p>
<p>        subnet 192.168.1.0 netmask 255.255.255.0 {<br />
                option routers 192.168.1.1;</p>
<p>                range 192.168.1.32 192.168.1.127;<br />
        }<br />
}<br />
This will allow up to 96 machines on your internal network, which should be more than sufficient. Create an empty temporary file for dhcpd to use:<br />
# touch /var/db/dhcpd.leases<br />
If you make any changes to this file, run dhcpd fxp0 (or whatever your inside network is). (Or you can reboot the machine &#8212; but that&#8217;s the Windows way, in the Unix world we prefer to never reboot any machines.)<br />
Install &#8220;ports&#8221;<br />
&#8220;Ports&#8221; is a *BSD term for a tree of Makefiles for all the software out there that&#8217;s not part of the standard install. I recommend this highly. It is on CD No. 3 of the OpenBSD 3.1 CD-ROM set as ports.tar.gz. Please read the Ports and Packages page on the OpenBSD web site. You install it by typing (as root) </p>
<p># mount /dev/cd0a /mnt<br />
# cd /usr<br />
# tar xzf /mnt/ports.tar.gz<br />
Once you&#8217;ve done this, if you want to install a package, you cd to the appropriate directory and simply type make all install &#8212; it will ftp the source from the appopriate site, handle all dependencies, apply any required patches, configure, build and install the tool. </p>
<p>How do you find the appropriate directory to go to? You can guess at where it might be (look around in /usr/ports to get an idea for the layout etc.). But remember: locate(1) is your friend. </p>
<p>If you have the disk space (about 500 MB), I strongly recommend that you install the source code to the system also. (The source is also on CD No. 3.) </p>
<p># mount /dev/cd0a /mnt<br />
# cd /usr/src<br />
# tar xzf /mnt/src.tar.gz<br />
Getting time from the Internet<br />
Set up NTP so that your machine will always have accurate time. Pick two servers from the public NTP server list and make sure /etc/ntp.conf looks like this: </p>
<p>server ntp.server.first<br />
server ntp.server.second<br />
Since xntpd is not part of the standard install, you have to compile xntpd from source. </p>
<p># cd /usr/ports/sysutils/xntpd<br />
# make all install<br />
The tools will be installed into /usr/local/sbin/ntpd. </p>
<p>Run ntpdate -b server where you pick a server from the list &#8212; this will perform a coarse adjustment of the system clock. The next time the machine reboots, it will sync your clock and record how much your clock drifts. </p>
<p>Setting up other hosts with NTP<br />
On Unix hosts, use the appropriate NTP client; on Linux, it&#8217;s xntpd. Set them up to use 192.168.1.1 as the NTP server. On Windows, use AboutTime &#8212; a free NTP client. In its configuration make sure it uses only SNTP as the protocol, with 192.168.1.1 as the server. Put AboutTime in the Startup folder so it&#8217;s started automatically. </p>
<p>For more details, go to Robert Mooney&#8217;s OpenBSD NTP site. </p>
<p>Tips and Stuff<br />
I have a useful shell script called pkg_install that&#8217;s a front-end to pkg_add &#8212; here&#8217;s an example of it being used:<br />
# pkg_install tex<br />
These files match:<br />
gettext-0.10.40.tgz<br />
jadetex-3.11.tgz<br />
latex2html-97.1.tgz<br />
php4-4.0.6p1-gettext-imap-mhash-no_x11-mcrypt-mysql.tgz<br />
php4-4.0.6p1-gettext-imap-mhash-no_x11-mcrypt-postgresql.tgz<br />
php4-4.0.6p1-gettext.tgz<br />
teTeX_texmf-1.0.2.tgz<br />
texi2html-1.64.tgz<br />
textutils-2.0.tgz<br />
# pkg_install -n 4 texi<br />
Using ftp5.usa.openbsd.org/pub/OpenBSD<br />
+ pkg_add -v ftp://ftp5.usa.openbsd.org/pub/OpenBSD/3.1/packages/i386//texi2html-1.64.tgz<br />
Trying to fetch ftp://ftp5.usa.openbsd.org/pub/OpenBSD/3.1/packages/i386//texi2html-1.64.tgz.<br />
Extracting from FTP connection into /var/tmp/instmp.BVMJM29414<br />
>>> ftp -o &#8212; ftp://ftp5.usa.openbsd.org/pub/OpenBSD/3.1/packages/i386//texi2html-1.64.tgz<br />
&#8230;<br />
It has a list of all the pre-compiled packages that are available. You type in a string and it installs the package. If more than one name matches, it shows you their names. (It uses egrep(1) so you can use regular expressions.) Save it to /usr/local/bin. It handles dependencies by recursively installing them also. </p>
<p>New in this version is in -n flag. The script has a list of mirrors, and this option picks one of the mirrors. (Currently in progress: it needs bash, and it needs some error checking but it works.) Don&#8217;t forget to edit the file &#8212; read http://www.openbsd.org/ftp.html and choosea list of mirrors closest to you. </p>
<p>Setting up a CVS server<br />
(This section is probably not of interest to most people; you only need this if you want to set up a cvs server so you can put files you&#8217;re working on under source control. So it&#8217;s a little terse too.) </p>
<p>The changes I made: added a user and group named cvs. All users of CVS should be in the cvs group. Create a directory for the repository: I put it in /var/cvsroot, you might put it in /home or wherever. This directory should be group writable (group cvs). Add a line to /etc/services: </p>
<p>      cvspserver	2401/tcp		# CVS pserver<br />
Add this line to /etc/inetd.conf:<br />
      cvspserver	stream	tcp	nowait	root	/usr/bin/cvs cvs -f &#8211;allow-root=/var/cvsroot -T /var/tmp pserver<br />
The server uses /var/tmp as its temp directory instead of /tmp since my root partitions are small, but I always make /var large. Now run cvs init in the cvs repository and restart inetd. Voila! Import your directory of files from a client machine, using a pserver CVSROOT and cvs import. </p>
<p>When importing a large set of files, you might want to put a .cvswrappers file in the directory you&#8217;re importing so CVS won&#8217;t try to put RCS ID strings inside your JPEG files etc. The syntax is: </p>
<p>      *.jpg -k &#8216;b&#8217;<br />
      *.png -k &#8216;b&#8217;<br />
      *.tgz -k &#8216;b&#8217;<br />
Coming soon: using ssh for CVS_RSH.<br />
Setting up X11<br />
You did select the packages xbase, xshare, xfont, and xserv when you installed OpenBSD, I hope? If not, never fear; you can install them directly off the CD: </p>
<p># mount /dev/cd0a /mnt<br />
# cd /<br />
# tar xzvpf /mnt/3.1/i386/xbase31.tgz<br />
# tar xzvpf /mnt/3.1/i386/xserv31.tgz<br />
# tar xzvpf /mnt/3.1/i386/xshare31.tgz<br />
# tar xzvpf /mnt/3.1/i386/xfont31.tgz<br />
etc. The X11 package for ix86 systems is called XFree86; visit their website for more information. Now run xf86cfg. (If the command is not found, you probably don&#8217;t have /usr/X11R6/bin in your PATH environment variable.) Of course this is not something you can do over a network login; you have to be sitting at the machine, with a monitor, keyboard and mouse actually plugged in. You should have your video card and monitor specs available. Follow the instructions to setup XFree86. More information is on the Configuring XFree86 page on the Xfree86 site.<br />
Installing a Desktop<br />
Many people also install a desktop suite such as KDE or Gnome. I prefer KDE of the two. There is nothing special about KDE (or Gnome); it&#8217;s just a set of packages to be installed. There are two versions of KDE available, KDE 2.2 and KDE 3.0. Decide which one you want to run, and install those packages. (KDE2 and KDE3 cannot co-exist on the same system.) </p>
<p>These are the KDE2 packages: </p>
<p>$ pkg_info -a | egrep kde<br />
kdelibs-2.2.2      X11 toolkit, libraries<br />
kdeartwork-2.2.2   X11 toolkit, additional artwork<br />
kdegraphics-2.2.2  X11 toolkit, graphics applications<br />
kdelibs-doc-2.2.2  X11 toolkit, libraries documentation<br />
kdebase-2.2.2      X11 toolkit, basic applications<br />
kdenetwork-2.2.2   X11 toolkit, network applications<br />
kdetoys-2.2.2      some useless kde applications<br />
And for KDE3, the corresponding packages are:<br />
kdeaddons-3.0.tgz<br />
kdeartwork-3.0.tgz<br />
kdebase-3.0.tgz<br />
kdeedu-3.0.tgz<br />
kdegames-3.0.tgz<br />
kdegraphics-3.0.tgz<br />
kdelibs-3.0.tgz<br />
kdenetwork-3.0.tgz<br />
kdetoys-3.0.tgz<br />
kdeutils-3.0.tgz<br />
koffice-1.1.1-kde3.tgz<br />
There are lots of I18N packages also, kde-i18n-*-3.0.tgz.<br />
Display managers xdm and kdm<br />
You may want to run a display manager like xdm or kdm. (A display manager is the program that gives you a graphical login display instead of a plain text message.) The config file for kdm is /usr/local/share/config/kdm/kdmrc; the xdm config file lives in /etc/X11/xdm/xdm-config. Edit /etc/rc.conf and set xdm_flags to an empty string (in quotes) to make xdm run on startup. (If you installed KDE, it will be kdm that&#8217;s started.) If you installed KDE3, add it to the list of available logins in kdmrc: in the [X-*-Greeter] section, look for the SessionTypes line and add &#8220;KDE3&#8243; to the list. </p>
<p>Setting up XDMCP<br />
If you have an X-Terminal (like the Sun Ray, or the ones NCD used to make) or run eXceed on Windows platforms, you may want to allow X11 logins to your OpenBSD machine from eXceed or the X-Terminal. The protocol that allows this is called XDMCP; to enable it: if using xdm, edit /etc/X11/xdm/Xaccess and remove the &#8216;#&#8217; from the first column of this line:</p>
<p>#*                                      #any host can get a login window<br />
Note: we don&#8217;t allow any X11 or XDMCP messages to go across our firewall. Only hosts inside the firewall can get a login screen.<br />
Also edit xdm-config and comment out this line by putting a &#8216;!&#8217; character in the first column:</p>
<p>DisplayManager.requestPort:     0<br />
If using kdm, edit /usr/local/share/config/kdm/kdmrc and look for the [Xdmcp] section. Uncomment lines so it looks like this:<br />
[Xdmcp]<br />
# Whether KDM should listen to XDMCP requests. Default is true.<br />
Enable=true<br />
# The UDP port KDM should listen on for XDMCP requests. Don&#8217;t change the 177.<br />
Port=177<br />
(followed by other stuff.)<br />
Amusements<br />
People like to do things like rip CDs to Ogg Vorbis or MP3 and listen to those files. I use grip as a front-end to rip music to Ogg Vorbis files, and xmms (package name xmms-vorbis) to listen to them. I use Gnu LilyPond and TeX/LaTeX (package teTeX_texmf) to typeset documents and music. The LaTeX files can be converted to HTML with latex2html. You can run Linux programs if you install the redhat_base, redhat_motif, and rpm packages. (The Linux version of Opera, the web browser, runs fine.) </p>
]]></content:encoded>
			<wfw:commentRss>http://www.evanjiang.net.cn/archives/849.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>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 as much data transfers [...]]]></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>基于OpenBSD4.3 i386系统的JAVA编译及OpenFIRE&amp;PostgreSQL应用</title>
		<link>http://www.evanjiang.net.cn/archives/707.html</link>
		<comments>http://www.evanjiang.net.cn/archives/707.html#comments</comments>
		<pubDate>Thu, 05 Mar 2009 05:46:01 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[openbsd unix]]></category>
		<category><![CDATA[postgresql]]></category>
		<category><![CDATA[openbsd java编译 openfire  postgresql 应用]]></category>

		<guid isPermaLink="false">http://www.evanjiang.net.cn/?p=707</guid>
		<description><![CDATA[<p>•	前言
	1 什么是
	2 什么是PostgreSQL
•	一、安装JAVA环境
	1 开启linux支持
	2 增加数据和堆栈限额(官方建议 非必须)
	3 建立/etc/mk.conf
	4 进入jdk目录开始编译安装
	a 编译安装jdk
	b 编译安装jre
	c 下载java编译所需文件
	5 设置JAVA环境
	a 设置系统变量
	b 设置系统变量
	c 测试JAVA环境
•	二、安装PostgreSQL
	1 安装数据库
	2 建立数据库
	a 初始化数据库
	b 运行数据库
	c 建立新用户
	d 建立数据库
	3 设置自动运行和关闭
	a 设置开机自动运行
	b 设置关机自动关闭
	4 PostgreSQL 优化
	a 修改 /etc/sysctl.conf
	b 修改/etc/login.conf
	c 修改postgresql.conf文件
•	三、 安装OpenFIRE
	1 服务器端安装
	a 添加openfire系统用户
	b 解压openfire
	c 修改 openfire权限
	d 运行openfire
	2 openfire服务配置
	3 设置openfire自动运行和关闭
	a 设置开机自动运行
	b 设置关机自动关闭
•	四 设置Spark
•	后记：

前言
1 什么是OpenFire
Openfire 采用Java开发的开源的实时协作（RTC）服务器,基于XMPP（Jabber）协议。
您可以使用它轻易的构建高效率的即时通信服务器.
Openfire安装和使用都非常简单，并利用Web进行管理。单台服务器可支持上万并发用户。
由于是采用开放的XMPP协议，您可以使用各种支持XMPP协议的IM客户端软件登陆服务
简单的说是类似MSN的实时通信系统
2 什么是PostgreSQL
PostgreSQL是以加州大学伯克利分校计算机系开发的 POSTGRES，版本 4.2为基础的对象关系型数据库管</p>
<p>理系统（ORDBMS）。
阅读指南：所有需要手工录入的部分都用加阴影的字符表示，需要特别注意的地方以【】字符加注.
【开始编译以前,请将ports升级到最新】
一、安装JAVA环境
1 开启linux支持
obsd支持【原生】的java运行环境，只在【编译】java的需要打开linux支持
sysctl kern.emul.linux=1
2 增加数据和堆栈限额(官方建议 非必须)
如果编译的时候出现类似于&#8221;Could not reserve enough space [...]]]></description>
			<content:encoded><![CDATA[<p>•	前言<br />
	1 什么是<br />
	2 什么是PostgreSQL<br />
•	一、安装JAVA环境<br />
	1 开启linux支持<br />
	2 增加数据和堆栈限额(官方建议 非必须)<br />
	3 建立/etc/mk.conf<br />
	4 进入jdk目录开始编译安装<br />
	a 编译安装jdk<br />
	b 编译安装jre<br />
	c 下载java编译所需文件<br />
	5 设置JAVA环境<br />
	a 设置系统变量<br />
	b 设置系统变量<br />
	c 测试JAVA环境<br />
•	二、安装PostgreSQL<br />
	1 安装数据库<br />
	2 建立数据库<br />
	a 初始化数据库<br />
	b 运行数据库<br />
	c 建立新用户<br />
	d 建立数据库<br />
	3 设置自动运行和关闭<br />
	a 设置开机自动运行<br />
	b 设置关机自动关闭<br />
	4 PostgreSQL 优化<br />
	a 修改 /etc/sysctl.conf<br />
	b 修改/etc/login.conf<br />
	c 修改postgresql.conf文件<br />
•	三、 安装OpenFIRE<br />
	1 服务器端安装<br />
	a 添加openfire系统用户<br />
	b 解压openfire<br />
	c 修改 openfire权限<br />
	d 运行openfire<br />
	2 openfire服务配置<br />
	3 设置openfire自动运行和关闭<br />
	a 设置开机自动运行<br />
	b 设置关机自动关闭<br />
•	四 设置Spark<br />
•	后记：<br />
<span id="more-707"></span><br />
前言<br />
1 什么是OpenFire<br />
Openfire 采用Java开发的开源的实时协作（RTC）服务器,基于XMPP（Jabber）协议。<br />
您可以使用它轻易的构建高效率的即时通信服务器.<br />
Openfire安装和使用都非常简单，并利用Web进行管理。单台服务器可支持上万并发用户。<br />
由于是采用开放的XMPP协议，您可以使用各种支持XMPP协议的IM客户端软件登陆服务<br />
简单的说是类似MSN的实时通信系统<br />
2 什么是PostgreSQL<br />
PostgreSQL是以加州大学伯克利分校计算机系开发的 POSTGRES，版本 4.2为基础的对象关系型数据库管</p>
<p>理系统（ORDBMS）。<br />
阅读指南：所有需要手工录入的部分都用加阴影的字符表示，需要特别注意的地方以【】字符加注.<br />
【开始编译以前,请将ports升级到最新】<br />
一、安装JAVA环境<br />
1 开启linux支持<br />
obsd支持【原生】的java运行环境，只在【编译】java的需要打开linux支持<br />
sysctl kern.emul.linux=1<br />
2 增加数据和堆栈限额(官方建议 非必须)<br />
如果编译的时候出现类似于&#8221;Could not reserve enough space for object heap&#8221;这类的错误,就应该增</p>
<p>加数据和堆栈的限额 ksh zsh bash环境(OB默认的就是ksh)<br />
ulimit -dS 384*1024<br />
ulimit -sS 8*1024<br />
csh tcsh 环境<br />
limit datasize 384m<br />
limit stacksize 8m<br />
本人在512M内存的电脑中编译的时候,没有做这一步,也很顺利的编译通过<br />
3 建立/etc/mk.conf<br />
java编译的时候需要检测/etc/mk.conf下有没有【ACCEPT_JRL_LICENSE=Yes】这个语句,没有的话会提示</p>
<p>错误,因此应当手工建立该文件<br />
我的mk.conf是<br />
DISTDIR=/files/dist<br />
MASTER_SITE_OVERRIDE=ftp://ftp.freebsdchina.org/pub/OpenBSD/distfiles/${DIST_SUBDIR}/<br />
PACKAGE_REPOSITORY=/files/packages<br />
FETCH_CMD=/usr/local/bin/wget<br />
ACCEPT_JRL_LICENSE=Yes<br />
其中<br />
DISTDIR是我指定的下载文件所在位置<br />
PACKAGE_REPOSITORY是我指定的生成pkg的位置<br />
只有【ACCEPT_JRL_LICENSE=Yes】是必须的<br />
4 进入jdk目录开始编译安装<br />
进入jdk的ports<br />
cd /usr/ports/devel/jdk/1.7<br />
a 编译安装jdk<br />
JDK是java的开发环境<br />
make install<br />
b 编译安装jre<br />
JRE是java的运行环境，如果不做开发，只是运行OpenFIRE的话，jre就足够<br />
env SUBPACKAGE=-jre make install<br />
c 下载java编译所需文件<br />
编译java的所需的文件需要【手动复制】到DISTDIR指定的位置<br />
默认是/usr/ports/distfiles<br />
编译所需文件make运行以前会有提示显示编译所需java文件的位置和名称，按提示下载并复制就可以<br />
如果缺少文件的话会有&#8221;Error code 1&#8243;的错误提示,编译所需下载的文件大概是<br />
bsd-jdk15-patches-8.tar.bz2<br />
bsd-jdk16-patches-3.tar.bz2<br />
bsd-jdk16-patches-4.tar.bz2<br />
javaPathHelper-0.3.tar.gz<br />
jdk-1_5_0_14-fcs-bin-b03-jrl-05_oct_2007.jar<br />
jdk-1_5_0_14-fcs-src-b03-jrl-05_oct_2007.jar<br />
jdk-1_5_0_14-solaris-i586.tar.Z<br />
jdk-6u3-fcs-bin-b05-jrl-24_sep_2007.jar<br />
jdk-6u3-fcs-mozilla_headers-b05-unix-24_sep_2007.jar<br />
jdk-6u3-fcs-src-b05-jrl-24_sep_2007.jar<br />
jdk-7-icedtea-plugs-1.6.tar.gz<br />
openjdk7-b24.tar.bz2<br />
(本人下载这些文件用了半天的时间,确切需下载的文件记不清楚了,哪位朋友有完整的下载文件列表,请</p>
<p>帮忙订正) 编译及安装过程大概需要5个小时<br />
5 设置JAVA环境<br />
JAVA的环境可以通过系统变量和用户变量两种方法来设置<br />
系统变量对整个系统中所有用户起作用,用户变量只对设置的用户起作用<br />
文中以jre1.6为例,具体配置根据读者安装的java环境自行修改<br />
a 设置系统变量<br />
建立/etc/profile文件,加入</p>
<p>PATH=/sbin:/usr/sbin:/bin:/usr/bin:/usr/X11R6/bin:/usr/local/sbin:/usr/local/bin:/usr/local</p>
<p>/jre-1.6.0/bin<br />
export PATH<br />
export JAVA_HOME=/usr/local/jre-1.6.0<br />
export CLASSPATH=:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar<br />
保存退出<br />
b 设置系统变量<br />
修改用户home目录里面的.profile文件,加入【】标示部分<br />
PATH=/sbin:/usr/sbin:/bin:/usr/bin:/usr/X11R6/bin:/usr/local/sbin:/usr/local/bin:</p>
<p>【/usr/local/jre-1.6.0/bin】<br />
export PATH<br />
【export JAVA_HOME=/usr/local/jre-1.6.0】<br />
【export CLASSPATH=:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar】<br />
: ${HOME=&#8217;/root&#8217;}<br />
export HOME<br />
umask 022<br />
if [ -x /usr/bin/tset ]; then<br />
        eval `/usr/bin/tset -sQ \?$TERM`<br />
fi<br />
c 测试JAVA环境<br />
重新登陆系统令设置的环境变量生效,输入<br />
java -version<br />
如果显示的是java相关版本信息,说明java已经生效,可以进行取消linux的支持,并进行下一步的安装<br />
(注:本人编译的时候是按照1.7编译的,环境设置都正确,可是java提示错误,可能是ports的问题)<br />
二、安装PostgreSQL<br />
1 安装数据库<br />
进入ports中postgresql，编译安装<br />
cd /usr/ports/databases/postgresql<br />
make install<br />
提示完毕以后，pgsql的客户端已经安装完毕，pgsql的数据库端，需要手动安装<br />
pkg已经在编译pgsql客户端的时候生成了，位置由mk.conf中PACKAGE_REPOSITORY字段定义<br />
默认位置是/usr/ports/packages/i386/all/<br />
cd /usr/ports/packages/i386/all/<br />
pkg_add postgres*<br />
2 建立数据库<br />
a 初始化数据库<br />
su &#8211; _postgresql<br />
mkdir /var/postgresql/data<br />
initdb -D /var/postgresql/data<br />
b 运行数据库<br />
postgres -D /var/postgresql/data<br />
或者<br />
pg_ctl -D /var/postgresql/data -l logfile start<br />
如果没有提示错误，pgsql就已经运行了<br />
c 建立新用户<br />
建立超级用户<br />
createuser 【-P】<br />
Enter name of role to add: 【输入超级用户名】<br />
Enter password for new role:【输入密码】<br />
Enter it again:【确认密码】<br />
Shall the new role be a superuser? (y/n)【 y】<br />
d 建立数据库<br />
createdb -O 【超级用户名】 -E UNICODE 【数据库名称】<br />
3 设置自动运行和关闭<br />
a 设置开机自动运行<br />
在/etc/rc.local中加入<br />
if [ -x /usr/local/bin/pg_ctl ]; then<br />
        echo -n &#8216; postgresql&#8217;<br />
        su -l _postgresql -c &#8220;nohup /usr/local/bin/pg_ctl start \<br />
            -D /var/postgresql/data -l /var/postgresql/logfile \<br />
            -o &#8216;-D /var/postgresql/data&#8217; >/dev/null&#8221;<br />
fi<br />
b 设置关机自动关闭<br />
在/etc/rc.shutdown中加入<br />
if [ -f /var/postgresql/data/postmaster.pid ]; then<br />
        su -l _postgresql -c &#8220;/usr/local/bin/pg_ctl stop -m fast \<br />
             -D /var/postgresql/data&#8221;<br />
        rm -f /var/postgresql/data/postmaster.pid<br />
fi<br />
4 PostgreSQL 优化<br />
a 修改 /etc/sysctl.conf<br />
编辑 /etc/sysctl.conf,加入以下内容<br />
kern.seminfo.semmni=256<br />
kern.seminfo.semmns=2048<br />
kern.shminfo.shmmax=50331648<br />
b 修改/etc/login.conf<br />
编辑/etc/login.conf,加入以下内容<br />
postgresql:\<br />
         <img src='http://www.evanjiang.net.cn/wp-includes/images/smilies/icon_surprised.gif' alt=':o' class='wp-smiley' /> penfiles-cur=768:\<br />
         :tc=daemon:<br />
保存退出后，输入<br />
cap_mkdb /etc/login.conf<br />
重建login.conf.db文件<br />
然后使用vipw或usermod修改postgresql<br />
usermod -L postgresql 【postgresql系统用户名】<br />
其中 -L 指定的是修改的用户的登陆类<br />
c 修改postgresql.conf文件<br />
切换成postgresql用户<br />
su &#8211; _postgresql<br />
修改/var/postgresql/data/postgresql.conf<br />
将max_connections 修改成你需要的并发链接数值,默认是40<br />
保存退出后,重启数据库,输入<br />
pg_ctl -D /var/postgresql/data -l logfile restart<br />
来重启整个数据库,或者输入<br />
pg_ctl -D /var/postgresql/data -l logfile reload<br />
来重新加载postgresql配置文件<br />
三、 安装OpenFIRE<br />
OpenFIRE服务器端最新版本openfire_3_5_1下载<br />
服务器端插件下载<br />
1 服务器端安装<br />
a 添加openfire系统用户<br />
adduser<br />
Enter username []: 【openfire用户名】<br />
Enter full name []:<br />
Enter shell csh ksh nologin sh [ksh]:【回车】<br />
Uid [1000]:【回车】<br />
Login group _openfire [_openfire]:【回车】<br />
Login group is &#8220;_openfire&#8221;. Invite _openfire into other groups: guest no<br />
[no]:【回车】<br />
Login class authpf daemon default postgresql staff [daemon]:【回车】<br />
Enter password []:【输入密码】<br />
Enter password again []:【确认密码】<br />
OK? (y/n) [y]: 【y】<br />
Add another user? (y/n) [y]: 【n】<br />
b 解压openfire<br />
tar xzvf 你的openfire压缩包位置 -C /var<br />
c 修改 openfire权限<br />
cd /var<br />
chown -R 【openfire用户名】:【openfire组名】 openfire/<br />
d 运行openfire<br />
su &#8211; 【openfire用户名】<br />
/var/openfire/bin/openfire start<br />
如果没有错误提示 top有java的进程,说明openfire启动正常<br />
2 openfire服务配置<br />
在浏览器中输入</p>
<p>http://服务器ip:9090</p>
<p>第一页Choose Language中选中中文(简体)<br />
第二页服务器设置保持默认<br />
第三页数据库设置选择标准数据库连接<br />
第四页数据库设置 &#8211; 标准连接中需要设置以下项目<br />
数据库驱动选项:【PostgreSQL】<br />
JDBC 驱动程序类：【org.postgresql.Driver】<br />
数据库 URL：jdbc:postgresql://【127.0.0.1】:5432/【数据库名称】<br />
用户名：【超级用户名】<br />
密码：【超级用户密码】<br />
第五页特性设置 初使设置<br />
第六页管理员帐户 设置管理员密码管理员账号为admin<br />
安装完成<br />
3 设置openfire自动运行和关闭<br />
a 设置开机自动运行<br />
在/etc/rc.local中启动postgresql字段后面加入<br />
if [ -x /var/openfire/bin/openfire ]; then<br />
   echo -n &#8216; openfire&#8217;<br />
   su -l _openfire -c &#8220;/var/openfire/bin/openfire start >/dev/null&#8221;<br />
fi<br />
b 设置关机自动关闭<br />
在/etc/rc.shutdown中关闭postgresql字段前面加入<br />
if [ -x /var/openfire/bin/openfire ]; then<br />
       su -l _openfire -c &#8220;/var/openfire/bin/openfire stop&#8221;<br />
fi<br />
四 设置Spark<br />
SparkWIN下客户端最新版本 2.5.8下载<br />
程序安装完毕后<br />
点击帐户来申请账号<br />
服务器中填入OpenFIRE服务器所用ip<br />
后记：</p>
<p>Comment by iopenbsd, Jun 22, 2008</p>
<p>http://download.java.net/tiger/</p>
<p>http://www.eyesbeyond.com/freebsddom/java/JDK15JRLConfirm.html|bsd-jdk15-patches-8.tar.bz2</p>
<p>http://www.eyesbeyond.com/freebsddom/java/JDK16JRLConfirm.html|bsd-jdk16-patches-3.tar.bz2</p>
<p>http://www.eyesbeyond.com/freebsddom/java/JDK16JRLConfirm.html|bsd-jdk16-patches-4.tar.bz2</p>
<p>http://www.java.net/download/jdk6/6u3/promoted/b05/jdk-6u3-fcs-bin-b05-jrl-</p>
<p>24_sep_2007.jar|jdk-6u3-fcs-bin-b05-jrl-24_sep_2007.jar </p>
<p>http://www.java.net/download/jdk6/6u3/promoted/b05/jdk-6u3-fcs-mozilla_headers-b05-unix-</p>
<p>24_sep_2007.jar|jdk-6u3-fcs-mozilla_headers-b05-unix-24_sep_2007.jar </p>
<p>http://www.java.net/download/jdk6/6u3/promoted/b05/jdk-6u3-fcs-src-b05-jrl-</p>
<p>24_sep_2007.jar|jdk-6u3-fcs-src-b05-jrl-24_sep_2007.jar </p>
<p>http://www.java.net/download/tiger/tiger_u14/jdk-1_5_0_14-fcs-bin-b03-jrl-</p>
<p>05_oct_2007.jar|jdk-1_5_0_14-fcs-bin-b03-jrl-05_oct_2007.jar </p>
<p>http://download.java.net/tiger/tiger_u14/jdk-1_5_0_14-fcs-src-b03-jrl-05_oct_2007.jar|jdk-</p>
<p>1_5_0_14-fcs-src-b03-jrl-05_oct_2007.jar http://download.java.net/tiger/tiger_u15/jdk-</p>
<p>1_5_0_15-fcs-src-b04-jrl-09_feb_2008.jar|jdk-1_5_0_15-fcs-src-b04-jrl-09_feb_2008.jar </p>
<p>http://java.sun.com/products/archive/j2se/5.0/index.html|jdk-1_5_0_14-solaris-i586.tar.Z</p>
<p>http://ftp.riken.jp/pub/OpenBSD/distfiles/javaPathHelper-0.3.tar.gz|javaPathHelper-</p>
<p>0.3.tar.gz http://ftp.riken.jp/pub/OpenBSD/distfiles/jdk-7-icedtea-plugs-1.6.tar.gz|jdk-7-</p>
<p>icedtea-plugs-1.6.tar.gz http://ftp.riken.jp/pub/OpenBSD/distfiles/openjdk7-</p>
<p>b24.tar.bz2|openjdk7-b24.tar.bz2 http://www.igniterealtime.org/downloads/download-</p>
<p>landing.jsp?file=openfire/openfire_src_3_5_2.tar.gz|openfire_src_3_5_2.tar.gz</p>
]]></content:encoded>
			<wfw:commentRss>http://www.evanjiang.net.cn/archives/707.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>在OpenBSD下，使用ADSL拨号上网和启动PF防火墙</title>
		<link>http://www.evanjiang.net.cn/archives/700.html</link>
		<comments>http://www.evanjiang.net.cn/archives/700.html#comments</comments>
		<pubDate>Thu, 05 Mar 2009 05:24:20 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[openbsd unix]]></category>
		<category><![CDATA[pf]]></category>
		<category><![CDATA[openbsd  adsl拔号上网 启动pf防火墙]]></category>

		<guid isPermaLink="false">http://www.evanjiang.net.cn/?p=700</guid>
		<description><![CDATA[<p>在OpenBSD下，使用ADSL拨号上网和启动PF防火墙
o	目标
o	什么是PF防火墙
o	注意事项
o	编辑配置文件
我拿OpenBSD当桌面系统，平时也不打开任何网络服务，使用ADSL拨号上网，只有一个调制解调器，没有路由器。
加上PF，挡住所有不请自来的流量。
目标
ADSL拨号配置文件，PF配置文件。
什么是PF防火墙
OpenBSD的内置防火墙，功能强大，是OpenBSD系统上进行TCP/IP流量过滤和网络地址转换的软件系统。
配置文件默认的位置在 /etc/pf.conf。
注意事项
内核编译选项必需有:
•	seudo-device pf # packet filter
•	seudo-device pflog # pf log if
•	seudo-device tun # network tunneling over tty
设kern.securelevel最高为1，因为securelevel为2不可以手动刷新过滤规则。
编辑配置文件
vi /etc/ppp/ppp.conf
default:
 set log Phase Chat LCP IPCP CCP tun command
 set redial 15 0
 set reconnect 15 10000

pppoe:
 set device &#8220;!/usr/sbin/pppoe -i re0&#8243;  # re0: 使用的网卡
 disable acfcomp protocomp
 deny acfcomp
 set mtu max 1492
 set mru [...]]]></description>
			<content:encoded><![CDATA[<p>在OpenBSD下，使用ADSL拨号上网和启动PF防火墙<br />
o	目标<br />
o	什么是PF防火墙<br />
o	注意事项<br />
o	编辑配置文件<br />
我拿OpenBSD当桌面系统，平时也不打开任何网络服务，使用ADSL拨号上网，只有一个调制解调器，没有路由器。<br />
加上PF，挡住所有不请自来的流量。<br />
目标<br />
ADSL拨号配置文件，PF配置文件。<br />
什么是PF防火墙<br />
OpenBSD的内置防火墙，功能强大，是OpenBSD系统上进行TCP/IP流量过滤和网络地址转换的软件系统。<br />
配置文件默认的位置在 /etc/pf.conf。<br />
注意事项<br />
内核编译选项必需有:<br />
•	seudo-device pf # packet filter<br />
•	seudo-device pflog # pf log if<br />
•	seudo-device tun # network tunneling over tty<br />
设kern.securelevel最高为1，因为securelevel为2不可以手动刷新过滤规则。<br />
编辑配置文件<br />
vi /etc/ppp/ppp.conf<br />
default:<br />
 set log Phase Chat LCP IPCP CCP tun command<br />
 set redial 15 0<br />
 set reconnect 15 10000<br />
<span id="more-700"></span><br />
pppoe:<br />
 set device &#8220;!/usr/sbin/pppoe -i re0&#8243;  # re0: 使用的网卡<br />
 disable acfcomp protocomp<br />
 deny acfcomp<br />
 set mtu max 1492<br />
 set mru max 1492<br />
 set speed sync<br />
 set crtscts off<br />
 enable lqr<br />
 enable mssfixup<br />
 set lqrperiod 5<br />
 set cd 5<br />
 set dial<br />
 set login<br />
 set timeout 0<br />
 set authname xxxxxx                  # ADSL拨号帐号，xxx@163.gd<br />
 set authkey &#8220;xxxxxx&#8221;                 # ADSL拨号密码<br />
# enable dns                          # 每次都修改/etc/resolv.conf<br />
 add! default HISADDR                 # 成为默认路由<br />
设置开机自动拨号: vi /etc/rc.local:<br />
echo &#8216;/etc/rc.local: connect to ADSL&#8217;<br />
ppp -ddial pppoe                     # 拨号模式，掉线自动重拨<br />
vi /etc/pf.conf<br />
# Define interfaces<br />
int_if = &#8220;re0&#8243;<br />
ext_if = &#8220;tun0&#8243;<br />

<!-- 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 -->
<br />
# RFC1918<br />
priv_nets = &#8220;{ 127.0.0.0/8, 10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16 }&#8221;</p>
<p># Those wonderful scrubbing bubbles<br />
scrub in all</p>
<p># Filtering begins<br />
block log all</p>
<p># Local machine stuff<br />
pass quick on lo0 all<br />
pass in on $int_if from $int_if:network to any<br />
pass out on $int_if from any to $int_if:network<br />
block in  quick on $ext_if from $priv_nets to any<br />
block out quick on $ext_if from any to $priv_nets<br />
antispoof log for { $int_if, $ext_if } </p>
<p># Out to the internet<br />
pass out on $ext_if proto tcp all modulate state flags S/SA<br />
pass out on $ext_if proto { udp, icmp, esp } all keep state<br />
设置拨号时启动PF: vi /etc/ppp/ppp.linkup:<br />
MYADDR:<br />
 ! sh -c &#8220;/sbin/ifconfig pflog0 up&#8221;<br />
 ! sh -c &#8220;/sbin/pflogd&#8221;<br />
 ! sh -c &#8220;/sbin/pfctl -e -F all -f /etc/pf.conf&#8221;<br />
vi /etc/ppp/ppp.linkdown:<br />
MYADDR:<br />
 ! sh -c &#8220;/sbin/pfctl -d -F all&#8221;<br />
 ! sh -c &#8220;kill $(cat /var/run/pflogd.pid)&#8221;<br />
 ! sh -c &#8220;/sbin/ifconfig pflog0 down&#8221;<br />
 ! sh -c &#8220;/sbin/route delete default&#8221;<br />

<!-- 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/700.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>nginx在openBSD下跑反向代理负载均衡</title>
		<link>http://www.evanjiang.net.cn/archives/581.html</link>
		<comments>http://www.evanjiang.net.cn/archives/581.html#comments</comments>
		<pubDate>Wed, 25 Feb 2009 12:47:03 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[nginx]]></category>
		<category><![CDATA[openbsd unix]]></category>
		<category><![CDATA[nginx openbsd 反向代理 负载均衡]]></category>

		<guid isPermaLink="false">http://www.evanjiang.net.cn/?p=581</guid>
		<description><![CDATA[<p>1，本文的实验环境：
        当时做完了OpenBSD+Nginx+php+mysql的实验，直接将该虚拟机克隆两份。如果对下文中的“二号机、三号机”配置有兴趣的可以看看那个帖
        一号机，（192.168.118.135）将旧的和mysql/php有关系的nginx.conf干掉，重写nginx.conf。也就是说不启用php/mysql，只用本机的nginx做反向代理。
        二号机，（192.168.118.136）保持着原有的架构，并在/var/nginx/html下面新建一个index.php页面，页面内容自定啦，但必须和下面的三号机有所区别。
        三号机，（192.168.118.137）保持着原有的架构，并在/var/nginx/html下面新建一个index.php页面，页面内容自定啦，但必须和上面的二号机有所区别。
        四号机，（192.168.118.132）以前做实验用过的一个redhat5的机器，是一个tomcat服务器，只装了jdk和tomcat并设置了环境变量。
        客户机，本机是winxp，也是上面四个试验机的宿主机，改过了本机的hosts文件。C:\WINDOWS\system32\drivers\etc\hosts ，这个文件没后缀名，但可以用写字板或记事本打开。加入如下内容：
      [...]]]></description>
			<content:encoded><![CDATA[<p>1，本文的实验环境：<br />
        当时做完了OpenBSD+Nginx+php+mysql的实验，直接将该虚拟机克隆两份。如果对下文中的“二号机、三号机”配置有兴趣的可以看看那个帖<br />
        一号机，（192.168.118.135）将旧的和mysql/php有关系的nginx.conf干掉，重写nginx.conf。也就是说不启用php/mysql，只用本机的nginx做反向代理。<br />
        二号机，（192.168.118.136）保持着原有的架构，并在/var/nginx/html下面新建一个index.php页面，页面内容自定啦，但必须和下面的三号机有所区别。<br />
        三号机，（192.168.118.137）保持着原有的架构，并在/var/nginx/html下面新建一个index.php页面，页面内容自定啦，但必须和上面的二号机有所区别。<br />
        四号机，（192.168.118.132）以前做实验用过的一个redhat5的机器，是一个tomcat服务器，只装了jdk和tomcat并设置了环境变量。<br />
        客户机，本机是winxp，也是上面四个试验机的宿主机，改过了本机的hosts文件。C:\WINDOWS\system32\drivers\etc\hosts ，这个文件没后缀名，但可以用写字板或记事本打开。加入如下内容：<br />
                192.168.118.135                test1.com<br />
                192.168.118.135                test2.com<br />
                192.168.118.135                test3.com<br />
        也就是说，要把三个域名的IP都指到一号试验机上去。<br />
<span id="more-581"></span></p>
<p>3，首先启动二、三、四号机器，在测试机上打开这三台机器的web页面，确认各自的nginx、php、tomcat工作正常，其中二、三号机器是nginx+php,用的80端口，四号机器一个裸奔的tomcat，用的 8080端口。</p>
<p>4，如下是重写并可应用的一号机的nginx.conf文件。对部分内容我做了特殊标注，大部分配置可以参考本站关于nginx设定的一些文章。<br />
cat  /etc/nginx/nginx.conf<br />
#user nobody;<br />
worker_processes 1;</p>
<p>error_log  /var/log/nginx/error.log  crit;<br />
pid        /var/run/nginx.pid;<br />
#这里的nginx是用OpenBSD自己pkg 包管理系统装上去的，所以log等信息位置和编译安装的不太一样。</p>
<p>worker_rlimit_nofile 51200;<br />
events<br />
{<br />
    use kqueue;<br />
#epoll是linux最优模式，经实验，在openBSD下不可用这种模式。百度之发现有如下模式：<br />
#<br />
#nginx以module的方式提供了select语义的多种实现：poll   devpoll  epoll  eventport  kqueue  rtsig后面4种，都是BSD/Linux为加速IO操作而提供的异步IO模型<br />
#<br />
#<br />
    worker_connections 51200;<br />
}<br />
http<br />
{<br />
    include       mime.types;<br />
    default_type  application/octet-stream;<br />
    #charset  gb2312;</p>
<p>    server_names_hash_bucket_size 128;<br />
    client_header_buffer_size 32k;<br />
    large_client_header_buffers 4 32k;<br />

<!-- 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 -->
<br />
    sendfile on;<br />
    tcp_nopush     on;<br />
    keepalive_timeout 3;<br />
#为了做测试，故意把keepalive改小的，生产环境设置60s吧。<br />
    tcp_nodelay on;<br />
    #gzip on;<br />
    #gzip_min_length  1k;<br />
    #gzip_buffers     4 16k;<br />
    #gzip_http_version 1.0;<br />
    #gzip_comp_level 2;<br />
    #gzip_types       text/plain application/x-javascript text/css application/xml;<br />
    #gzip_vary on;<br />
    upstream  test1.com  {<br />
        server   192.168.118.136:80;<br />
        server   192.168.118.137:80;</p>
<p>    }</p>
<p>    upstream  test2.com  {<br />
        server   192.168.118.136:80 weight=10;<br />
        server   192.168.118.137:80;<br />
  # weight是权重的意思，默认权重是1，</p>
<p>    }</p>
<p>    upstream  test3.com<br />
        {<br />
                server   192.168.118.132:8080;</p>
<p>        }</p>
<p>server {<br />
        listen   80;<br />
        server_name test1.com;<br />
                #这里的test1是监听的客户端访问的域名<br />
        location /{<br />
        proxy_pass              http://test1.com;<br />
                #这里的test1是上文提到的upstream啦，别和客户访问的域名弄混。<br />
        proxy_set_header  X-Real-IP  $remote_addr;<br />
        }<br />
        }</p>
<p>server {<br />
        listen   80;<br />
        server_name test2.com;<br />
        location /{<br />
        proxy_pass              http://test2.com;<br />
        proxy_set_header  X-Real-IP  $remote_addr;<br />
        }<br />
        }</p>
<p>server {<br />
        listen   80;<br />
        server_name test3.com;<br />
        location /{<br />
        proxy_pass              http://test3.com;<br />
        proxy_set_header  X-Real-IP  $remote_addr;<br />
        }<br />
        }<br />
_
<!-- 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 -->
___________________________________________________<br />
5，启动一号机的nginx，测试开始。<br />
在本机访问http://test1.com/ http://test2.com/  http://test3.com/<br />
请注意test1是否在二号、三号机之间不停切换？在上图中写到要让二号三号机上的index.php文件不太一样，就是为了区分两台web服务器的。如果不怎么切换，请考虑你的浏览器的缓存问题。如果还不切换，可以考虑down掉一台机器的nginx，看访问请求是否会转到另一台服务器上。<br />
test2和test1的情况类似，只是test2做了权重设置，所以二号机应用的几率要比三号机大很多，如果总是轮不到三号机接任务，可以考虑更改权重实验一下，也可以考虑把二号机的nginx暂停一下。<br />
test3的要求很简单，能转到四号机的8080端口，把tomcat的那个默认控制界面show出来就可以</p>
]]></content:encoded>
			<wfw:commentRss>http://www.evanjiang.net.cn/archives/581.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>在openBSD中运行外来软件</title>
		<link>http://www.evanjiang.net.cn/archives/442.html</link>
		<comments>http://www.evanjiang.net.cn/archives/442.html#comments</comments>
		<pubDate>Sat, 21 Feb 2009 04:19:48 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[openbsd unix]]></category>
		<category><![CDATA[openbsd 运来外来软件]]></category>

		<guid isPermaLink="false">http://www.evanjiang.net.cn/?p=442</guid>
		<description><![CDATA[<p>在openBSD中运行外来软件</p>
<p>运行外来软件
&#8212;&#8212;&#8212;&#8212;&#8211;</p>
<p>从传统观点来说，操作系统不得不为它们自己开发软件，而且很多的软件只能运行在它们被指定的平台上。许多人为某些平台编制了一些“业务交换软件”，使得一些软件也能在其它操作系统中运行，虽然有些潜在的问题存在。通过使用ABI，openBSD能让为某些操作系统开发的软件在自己的系统中运行。这通常是用来运行为Linux和FreeBSD设计的软件。</p>
<p>ABI（(Application Binary Interface）是核心的一部分，它用于为软件提供服务－－这包括声卡访问、读取文件、屏幕输出的－－这些软件运行所需的一切。对软件来说，ABI就是操作系统。依靠你的系统中对别的系统ABI的支持，你能够使得软件像运行在它本来的系统中一样运行。</p>
<p>openBSD中包括了支持运行Linux、FreeBSD、SVR4、SCO的ABI的模块。当你尝试运行Linux的软件时，核心能识别出它，并把这个软件教给响应的ABI来处理。</p>
<p>ABI的一大限制是：它只能处理与核心特征相关的问题，而不能摆脱硬件的限制。软件只能运行在与编译时所处的体系结构相同的环境中。你在i386版的openBSD中，运行为i368版的Solaris 2.6编译的软件，但是你不能在i386版的openBSD上，运行Sparc版的Solaris中的软件。</p>
<p>当然，软件不止对核心有依赖。软件还需要使用动态链接库。OpenBSD对Linux（/usr/ports/emulators/redhat）还有FreeBSD（/usr/ports/emulators/freebsd_lib）提供了动态链接库。因为BSD/OS、SVR4、还有SCO都是专利操作系统，openBSD不太容易为它们的共享库提供ports。你必须从响应的操作系统上获取链接库。如果你对怎样安装库文件感兴趣，请阅读compat_bsdos(8), compat_svr4(8),
</p>
<p>and compat_ibcs2(8) 以获取细节。</p>
<p>在大多数情况下，Linux和FreeBSD的ABI能“正确的运行”，而且对于依赖它们的ports来说也足够可靠。例如：很少人使用Linux Netscape port，（它也能在openBSD上运行）。如果你正确的安装了共享库（shared libraries），那么使用ABI不需要配置。如果你使用ports安装了软件，你甚至可能已经不知不觉的使用了Linux mode。</p>
<p>依靠openBSD自身的软件和外来ABI的支持，openBSD能够广泛的支持许多软件packages。openBSD也包括了许多基本的UNIX软件，大它们多数都通过/etc中的文件进行配置。下一章将对其进行详细的解说。</p>
<p>







＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝</p>
<p>原文：</p>
<p>Running Foreign Software
Traditionally, operating systems have had to have software written for them, and a piece of software would only run on the platform it was designed for. Many people have built a healthy business changing software for one platform so it will run on [...]]]></description>
			<content:encoded><![CDATA[<p>在openBSD中运行外来软件</p>
<p>运行外来软件<br />
&#8212;&#8212;&#8212;&#8212;&#8211;</p>
<p>从传统观点来说，操作系统不得不为它们自己开发软件，而且很多的软件只能运行在它们被指定的平台上。许多人为某些平台编制了一些“业务交换软件”，使得一些软件也能在其它操作系统中运行，虽然有些潜在的问题存在。通过使用ABI，openBSD能让为某些操作系统开发的软件在自己的系统中运行。这通常是用来运行为Linux和FreeBSD设计的软件。</p>
<p>ABI（(Application Binary Interface）是核心的一部分，它用于为软件提供服务－－这包括声卡访问、读取文件、屏幕输出的－－这些软件运行所需的一切。对软件来说，ABI就是操作系统。依靠你的系统中对别的系统ABI的支持，你能够使得软件像运行在它本来的系统中一样运行。</p>
<p>openBSD中包括了支持运行Linux、FreeBSD、SVR4、SCO的ABI的模块。当你尝试运行Linux的软件时，核心能识别出它，并把这个软件教给响应的ABI来处理。</p>
<p>ABI的一大限制是：它只能处理与核心特征相关的问题，而不能摆脱硬件的限制。软件只能运行在与编译时所处的体系结构相同的环境中。你在i386版的openBSD中，运行为i368版的Solaris 2.6编译的软件，但是你不能在i386版的openBSD上，运行Sparc版的Solaris中的软件。</p>
<p>当然，软件不止对核心有依赖。软件还需要使用动态链接库。OpenBSD对Linux（/usr/ports/emulators/redhat）还有FreeBSD（/usr/ports/emulators/freebsd_lib）提供了动态链接库。因为BSD/OS、SVR4、还有SCO都是专利操作系统，openBSD不太容易为它们的共享库提供ports。你必须从响应的操作系统上获取链接库。如果你对怎样安装库文件感兴趣，请阅读compat_bsdos(8), compat_svr4(8),<br />
<span id="more-442"></span></p>
<p>and compat_ibcs2(8) 以获取细节。</p>
<p>在大多数情况下，Linux和FreeBSD的ABI能“正确的运行”，而且对于依赖它们的ports来说也足够可靠。例如：很少人使用Linux Netscape port，（它也能在openBSD上运行）。如果你正确的安装了共享库（shared libraries），那么使用ABI不需要配置。如果你使用ports安装了软件，你甚至可能已经不知不觉的使用了Linux mode。</p>
<p>依靠openBSD自身的软件和外来ABI的支持，openBSD能够广泛的支持许多软件packages。openBSD也包括了许多基本的UNIX软件，大它们多数都通过/etc中的文件进行配置。下一章将对其进行详细的解说。</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 -->
<br />
＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝</p>
<p>原文：</p>
<p>Running Foreign Software<br />
Traditionally, operating systems have had to have software written for them, and a piece of software would only run on the platform it was designed for. Many people have built a healthy business changing software for one platform so it will run on another operating system, a task filled with many potential problems. OpenBSD has the ability to run binaries built for certain other operating systems, however, through a process called ABI implementation. This is most commonly used for running software native to Linux and FreeBSD.</p>
<p>The ABI (Application Binary Interface) is the part of the kernel that provides services to programs, including everything from sound-card access to reading files to printing on the screen — all the things a program needs to run. As far as programs are concerned, the ABI is the operating system. By completely implementing the ABI from a different operating system on your native operating system, you can run non-native programs as if they were on their native platform.</p>
<p>The OpenBSD kernel includes modules that implement ABIs for Linux, FreeBSD, SVR4, SCO, and BSD/OS. When you attempt to run a Linux program, for example, the kernel picks out that the program is actually a Linux binary and directs it at the proper ABI.</p>
<p>One large limitation of ABI implementations is that they can only handle the kernel features, not the underlying hardware. A program only works if the binary is built for the same architecture that it is being run on. You can run a Solaris 2.6 binary built for an i386 system on OpenBSD running on i386, but you cannot run a Solaris Sparc binary on an i386 system.</p>
<p>Of course, programs require a little more than just a kernel to run on. They also require the dynamic libraries that they link against, if nothing else. OpenBSD provides these shared libraries for Linux (/usr/ports/emulators/ redhat) and FreeBSD (/usr/ports/emulators/freebsd_lib). Because BSD/OS, SVR4, and SCO are proprietary operating systems, the OpenBSD project cannot easily provide easy-to-install ports for their shared libraries. You must have access to the proper operating system to grab the libraries. If you&#8217;re interested in how to install these libraries see compat_bsdos(8), compat_svr4(8), and compat_ibcs2(8) for details.</p>
<p>In most cases, however, the Linux and FreeBSD ABIs &#8220;just work&#8221; and are reliable enough that many ports depend on them. Quite a few people use the Linux Netscape port, for example. Using an ABI implementation requires no configuration, once you have the shared libraries installed. If you install software from ports, you may be using Linux mode without even realizing it!<br />

<!-- 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 -->
<br />
Between add-on native software and foreign ABI implementations, OpenBSD can support a wide variety of software packages. OpenBSD also includes a variety of basic UNIX software, most of it configured through files in /etc. We&#8217;ll look there in the next chapter.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.evanjiang.net.cn/archives/442.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to patch your OpenBSD</title>
		<link>http://www.evanjiang.net.cn/archives/352.html</link>
		<comments>http://www.evanjiang.net.cn/archives/352.html#comments</comments>
		<pubDate>Thu, 05 Feb 2009 13:51:50 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[openbsd unix]]></category>
		<category><![CDATA[OpenBSD   打补丁]]></category>

		<guid isPermaLink="false">http://www.evanjiang.net.cn/?p=352</guid>
		<description><![CDATA[<p>Every OS needs to be patched, even for OpenBSD, either for security reasons, reliability ones, bug fixes or new functions.</p>
<p>To patch OpenBSD, you need first to know whether there are any patches released/applicable for your version of release. For OpenBSd, there are two ways you can check if there are any patches available. First, and [...]]]></description>
			<content:encoded><![CDATA[<p>Every OS needs to be patched, even for OpenBSD, either for security reasons, reliability ones, bug fixes or new functions.</p>
<p>To patch OpenBSD, you need first to know whether there are any patches released/applicable for your version of release. For OpenBSd, there are two ways you can check if there are any patches available. First, and recommended, is to check the errata (http://www.openbsd.org/errata.html) page. Second is to subscribe to &#8220;announce &#8221; and &#8220;security-announce&#8221; mailing lists. for more details on how, check OpenBSD web page or send a mail to majordomo@openbsd.org with subject &#8220;help&#8221;.</p>
<p><span id="more-352"></span><br />
In OpenBSD, there are 3 ways to patch your system with all the patches.<br />
1. upgrade your system to -current branch, since all patches and fixes are incorporated into -current.</p>
<p>This is not suitable for most users because of the ever-changing code for -current.</p>
<p>2. upgrade your system to -stable branch of your your release.</p>
<p>By doing this, you&#8217;ll need to fetch or update your source tree using the appropriate -stable branch, and recompile the kernel and userland files. While this is the easiest way and is OK for most users, it take quite a while to download source files and recompile the system, especially for these who has limited bandwidth to Internet.</p>
<p>3. Patch, compile and install individual impacted files.</p>
<p>This is what we will use for our example below. While this requires less bandwidth and typically less time than an entire cvs(1) checkout/update and source code compilation, this is sometimes the most difficult option, as there is no one universal set of instructions to follow. Sometimes you must patch, recompile and install one application, other times, you might have to recompile entire sections of the tree if the problem is in a library file.<br />

<!-- 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 -->
<br />
Once you&#8217;ve identified the patch you need to apply to your system, here are the steps to follow: </p>
<p>++++++++++++++++++Following lines are from www.openbsd.org/faq/faq10.html:</p>
<p>Applying patches.</p>
<p>Patches for the OpenBSD Operating System are distributed as &#8220;Unified diffs&#8221;, which are text files that hold differences to the original source code. They are NOT distributed in binary form. This means that to patch your system you must have the source code from the RELEASE version of OpenBSD readily available. In general, you should have the entire source tree available. If you are running a release from official CDROM, the source trees are available on disk 3, they are also available as files from the FTP servers. We will assume you have the entire tree checked out.</p>
<p>For our example here, we will look at patch 001 for OpenBSD 3.6 dealing with the st(4) driver, which handles tape drives. Without this patch, recovering data from backups is quite difficult. People using a tape drive need this patch, however those without a tape drive may have no particular need to install it. Let&#8217;s look at the patch:</p>
<p># more 001_st.patch<br />
Apply by doing:<br />
cd /usr/src<br />
patch -p0 < 001_st.patch</p>
<p>Rebuild your kernel.</p>
<p>Index: sys/scsi/st.c<br />
===================================================================<br />
RCS file: /cvs/src/sys/scsi/st.c,v<br />
retrieving revision 1.41<br />
retrieving revision 1.41.2.1<br />
diff -u -p -r1.41 -r1.41.2.1<br />
--- sys/scsi/st.c 1 Aug 2004 23:01:06 -0000 1.41<br />
+++ sys/scsi/st.c 2 Nov 2004 01:05:50 -0000 1.41.2.1<br />
@@ -1815,7 +1815,7 @@ st_interpret_sense(xs)<br />
u_int8_t skey = sense->flags &#038; SSD_KEY;<br />
int32_t info;</p>
<p>- if (((sense->flags &#038; SDEV_OPEN) == 0) ||<br />
+ if (((sc_link->flags &#038; SDEV_OPEN) == 0) ||<br />
(serr != 0&#215;70 &#038;&#038; serr != 0&#215;71))<br />
return (EJUSTRETURN); /* let the generic code handle it */</p>
<p>As you will note, the top of the patch includes brief instructions on applying it. We will assume you have put this patch into the /usr/src directory, in which case, the following steps are used:</p>
<p># cd /usr/src<br />
# patch -p0 < 001_st.patch<br />
Hmm... Looks like a unified diff to me...<br />
The text leading up to this was:<br />
--------------------------<br />
|Apply by doing:<br />
| cd /usr/src<br />
| patch -p0 < 001_st.patch<br />
|<br />
|Rebuild your kernel.<br />
|<br />
|Index: sys/scsi/st.c<br />
|===================================================================<br />
|RCS file: /cvs/src/sys/scsi/st.c,v<br />
|retrieving revision 1.41<br />
|retrieving revision 1.41.2.1<br />
|diff -u -p -r1.41 -r1.41.2.1<br />
|--- sys/scsi/st.c 1 Aug 2004 23:01:06 -0000 1.41<br />
|+++ sys/scsi/st.c 2 Nov 2004 01:05:50 -0000 1.41.2.1<br />
--------------------------<br />
Patching file sys/scsi/st.c using Plan A...<br />
Hunk #1 succeeded at 1815. <-- Look for this message!<br />
done<br />

<!-- 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 -->
<br />
Note the &#8220;Hunk #1 succeeded&#8221; message above. This indicates the patch was applied successfully. Many patches are more complex than this one, and will involve multiple hunks and multiple files, in which case, you should verify that all hunks succeeded on all files. If they did not, it normally means your source tree is not right, you didn&#8217;t follow instructions carefully, or your patch was mangled. Patches are very sensitive to &#8220;white space&#8221; &#8212; copying and pasting from your browser will often change tab characters into spaces or otherwise alter the white space of a file, making it not apply.</p>
<p>At this point, you can build the kernel as normal, install it and reboot the system.</p>
<p>Not all patches are for the kernel. In some cases, you will have to rebuild individual utilities. At other times, will require recompiling all utilities statically linked to a patched library. Follow the guidance in the header of the patch, and if uncertain, rebuild the entire system.</p>
<p>Patches that are irrelevant to your particular system need not be applied &#8212; usually.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.evanjiang.net.cn/archives/352.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>OpenBSD内核编译和优化</title>
		<link>http://www.evanjiang.net.cn/archives/141.html</link>
		<comments>http://www.evanjiang.net.cn/archives/141.html#comments</comments>
		<pubDate>Sat, 27 Dec 2008 05:27:01 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[openbsd unix]]></category>
		<category><![CDATA[openbsd 内核 编译 优化]]></category>

		<guid isPermaLink="false">http://www.hunttech.com.cn/wpblog/?p=141</guid>
		<description><![CDATA[<p> 
要编译内核，需要一套完整的syssrc包，这套东东可以通过CVS或FTP方式获得。</p>
<p>要通过CVS方式下载，在SHELL上打：</p>
<p>export CVS_RSH=&#8221;/usr/bin/ssh&#8221;
export CVSROOT=anoncvs@anoncvs1.usa.openbsd.org:/cvs
想用其它地方的服务器，请看完整的CVS服务器列表。</p>
<p>cd /usr &#38;&#38; cvs checkout -z9 src/sys
要用FTP方式下载，请到：ftp://ftp.openbsd.org/pub/OpenBSD/2.7/srcsys.tar.gz</p>
<p>下载完后就可以把它放到/usr/src目录里，并解开：</p>
<p>cp srcsys.tar.gz /usr/src ; tar -xzvf /usr/src/srcsys.tar.gz
<p>
搞定了源代码，接下来就可以配置并编译内核了。OpenBSD的内核配置文件因为支持多平台，所以相应平台的配置
文件就存放在/usr/src/sys/arch/$ARCH/conf/里，这里的$ARCH就是你所用的平台名称。我们以i386为例介绍
对内核有优化作用的选项。</p>
<p>O 处理器及I/O部分有：</p>
<p>option I686_CPU
这个很简单，与FreeBSD一样
#option GPL_MATH_EMULATE
别把它打开除非你的机器老得连FPU都没有
option DUMMY_NOPS
把开机延迟关掉
option UVM
高级虚拟内存系统，在系统进行交换时提供速度所用
option MFS
这个也与FreeBSD含义一样，用于建立内存盘以提升数据访问速度
O 网络部分有：








option NMBCLUSTERS="8192"
与FreeBSD含义一样，提升高流量时的网络操作速度并提高内核稳定性。如流量低可用1024或2048
另外，把不需要的网卡设备都注释掉，这样可以减小内核容量提升启动速度。</p>
<p>O 磁盘设备部分有：</p>
<p>option BUFCACHEPERCENT=45
保留45%的系统内存作为文件系统的缓存，顾名思义，根据实际系统内存数来取值，推荐取低一些的值
另外，与网络部分一样，把不需要的磁盘设备(scsi、ide)都注释掉。</p>
<p>配完了内核，依次打：</p>
<p>cd /usr/src/sys/arch/$ARCH/conf ; config yourkernel
cd ../compile/yourkernel ; make depend &#38;&#38; make
cp /bsd /bsd-old ; cp bsd /bsd
重启后就可以直接用刚才编译好的新内核了，如果它有任何问题，可以重启后在boot&#62;的提示符上输入刚才换名的
旧内核，命令格式为：








boot&#62; boot device:/kernelold
把device换成你存放旧内核的盘设备即可。顺便提一下，你可以在上述命令后加上一个-c选项进入User Kernel
Config界面，它提供与FreeBSD下一样的配置功能。
]]></description>
			<content:encoded><![CDATA[<p> <br />
要编译内核，需要一套完整的syssrc包，这套东东可以通过CVS或FTP方式获得。</p>
<p>要通过CVS方式下载，在SHELL上打：</p>
<p>export CVS_RSH=&#8221;/usr/bin/ssh&#8221;<br />
export CVSROOT=anoncvs@anoncvs1.usa.openbsd.org:/cvs<br />
想用其它地方的服务器，请看完整的CVS服务器列表。</p>
<p>cd /usr &amp;&amp; cvs checkout -z9 src/sys<br />
要用FTP方式下载，请到：ftp://ftp.openbsd.org/pub/OpenBSD/2.7/srcsys.tar.gz</p>
<p>下载完后就可以把它放到/usr/src目录里，并解开：</p>
<p>cp srcsys.tar.gz /usr/src ; tar -xzvf /usr/src/srcsys.tar.gz</pre>
<p><span id="more-141"></span><br />
搞定了源代码，接下来就可以配置并编译内核了。OpenBSD的内核配置文件因为支持多平台，所以相应平台的配置<br />
文件就存放在/usr/src/sys/arch/$ARCH/conf/里，这里的$ARCH就是你所用的平台名称。我们以i386为例介绍<br />
对内核有优化作用的选项。</p>
<p>O 处理器及I/O部分有：</p>
<p>option I686_CPU<br />
这个很简单，与FreeBSD一样<br />
#option GPL_MATH_EMULATE<br />
别把它打开除非你的机器老得连FPU都没有<br />
option DUMMY_NOPS<br />
把开机延迟关掉<br />
option UVM<br />
高级虚拟内存系统，在系统进行交换时提供速度所用<br />
option MFS<br />
这个也与FreeBSD含义一样，用于建立内存盘以提升数据访问速度<br />
O 网络部分有：<br />

<!-- 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 -->
<br />
option NMBCLUSTERS="8192"<br />
与FreeBSD含义一样，提升高流量时的网络操作速度并提高内核稳定性。如流量低可用1024或2048<br />
另外，把不需要的网卡设备都注释掉，这样可以减小内核容量提升启动速度。</p>
<p>O 磁盘设备部分有：</p>
<p>option BUFCACHEPERCENT=45<br />
保留45%的系统内存作为文件系统的缓存，顾名思义，根据实际系统内存数来取值，推荐取低一些的值<br />
另外，与网络部分一样，把不需要的磁盘设备(scsi、ide)都注释掉。</p>
<p>配完了内核，依次打：</p>
<p>cd /usr/src/sys/arch/$ARCH/conf ; config yourkernel<br />
cd ../compile/yourkernel ; make depend &amp;&amp; make<br />
cp /bsd /bsd-old ; cp bsd /bsd<br />
重启后就可以直接用刚才编译好的新内核了，如果它有任何问题，可以重启后在boot&gt;的提示符上输入刚才换名的<br />
旧内核，命令格式为：<br />

<!-- 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 -->
<br />
boot&gt; boot device:/kernelold<br />
把device换成你存放旧内核的盘设备即可。顺便提一下，你可以在上述命令后加上一个-c选项进入User Kernel<br />
Config界面，它提供与FreeBSD下一样的配置功能。</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.evanjiang.net.cn/archives/141.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>在OpenBSD 4.3环境下安装Ningx</title>
		<link>http://www.evanjiang.net.cn/archives/51.html</link>
		<comments>http://www.evanjiang.net.cn/archives/51.html#comments</comments>
		<pubDate>Wed, 17 Dec 2008 03:32:28 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[openbsd unix]]></category>
		<category><![CDATA[Openbsd ningx]]></category>

		<guid isPermaLink="false">http://www.hunttech.com.cn/wpblog/?p=51</guid>
		<description><![CDATA[<p> </p>
<p class="MsoNormal" align="left">sudo pkg_add pcre</p>
<p class="MsoNormal" align="left"> </p>
<p class="MsoNormal" align="left">wget http://sysoev.ru/nginx/nginx-0.7.17.tar.gz</p>
<p class="MsoNormal" align="left"> </p>
<p class="MsoNormal" align="left">tar xzvf nginx-0.7.17.tar.gz</p>
<p class="MsoNormal" align="left"> </p>
<p class="MsoNormal" align="left">cd nginx-0.7.17.tar.gz</p>
<p class="MsoNormal" align="left"> </p>
<p class="MsoNormal" align="left">./configure</p>
<p class="MsoNormal" align="left">这步可以加入很多配置选项,详细的可以输入./configure &#8211;help查看,自行修改和设定.</p>
<p class="MsoNormal" align="left"> 
</p>
<p class="MsoNormal" align="left">下面这步比较关键:</p>
<p class="MsoNormal" align="left"> </p>
<p class="MsoNormal" align="left">vi +74 src/os/unix/ngx_posix_config.h</p>
<p class="MsoNormal" align="left"> </p>
<p class="MsoNormal" align="left">将这行中的malloc.h替换成stdlib.h</p>
<p class="MsoNormal" align="left"> </p>
<p class="MsoNormal" align="left">保存退出,执行:</p>
<p class="MsoNormal" align="left"> </p>
<p class="MsoNormal" align="left">make &#38;&#38; make install</p>
<p class="MsoNormal" align="left"> </p>
<p class="MsoNormal" align="left">OK!</p>
<p [...]]]></description>
			<content:encoded><![CDATA[<p> </p>
<p class="MsoNormal" align="left"><span lang="EN-US">sudo pkg_add pcre</span></p>
<p class="MsoNormal" align="left"><span lang="EN-US"> </span></p>
<p class="MsoNormal" align="left"><span lang="EN-US">wget</span><span lang="EN-US"> </span><span lang="EN-US"><a href="http://sysoev.ru/nginx/nginx-0.7.17.tar.gz"><span>http://sysoev.ru/nginx/nginx-0.7.17.tar.gz</span></a></span></p>
<p class="MsoNormal" align="left"><span lang="EN-US"> </span></p>
<p class="MsoNormal" align="left"><span lang="EN-US">tar xzvf nginx-0.7.17.tar.gz</span></p>
<p class="MsoNormal" align="left"><span lang="EN-US"> </span></p>
<p class="MsoNormal" align="left"><span lang="EN-US">cd nginx-0.7.17.tar.gz</span></p>
<p class="MsoNormal" align="left"><span lang="EN-US"> </span></p>
<p class="MsoNormal" align="left"><span lang="EN-US">./configure</span></p>
<p class="MsoNormal" align="left"><span>这步可以加入很多配置选项</span><span lang="EN-US">,</span><span>详细的可以输入</span><span lang="EN-US">./configure &#8211;help</span><span>查看</span><span lang="EN-US">,</span><span>自行修改和设定</span><span lang="EN-US">.</span></p>
<p class="MsoNormal" align="left"><span lang="EN-US"> <span id="more-51"></span><br />
</span></p>
<p class="MsoNormal" align="left"><span>下面这步比较关键</span><span lang="EN-US">:</span></p>
<p class="MsoNormal" align="left"><span lang="EN-US"> </span></p>
<p class="MsoNormal" align="left"><span lang="EN-US">vi +74 src/os/unix/ngx_posix_config.h</span></p>
<p class="MsoNormal" align="left"><span lang="EN-US"> </span></p>
<p class="MsoNormal" align="left"><span>将这行中的</span><span lang="EN-US">malloc.h</span><span>替换成</span><span lang="EN-US">stdlib.h</span></p>
<p class="MsoNormal" align="left"><span lang="EN-US"> </span></p>
<p class="MsoNormal" align="left"><span>保存退出</span><span lang="EN-US">,</span><span>执行</span><span lang="EN-US">:</span></p>
<p class="MsoNormal" align="left"><span lang="EN-US"> </span></p>
<p class="MsoNormal" align="left"><span lang="EN-US">make &amp;&amp; make install</span></p>
<p class="MsoNormal" align="left"><span lang="EN-US"> </span></p>
<p class="MsoNormal" align="left"><span lang="EN-US">OK!</span></p>
<p class="MsoNormal" align="left"><span lang="EN-US"> </span></p>
<p class="MsoNormal" align="left"><span lang="EN-US">Nginx is on your OpenBSD server!!!!!!</span></p>
<p class="MsoNormal" align="left"><span lang="EN-US"> </span></p>
<p class="MsoNormal" align="left"><span>如果按上面的步骤</span><span lang="EN-US">,</span><span>安装后的</span><span lang="EN-US">nginx</span><span>执行文件在</span><span lang="EN-US">/usr/local/nginx/sbin</span><span>目录</span><span lang="EN-US">,</span><span>配置文件在</span><span lang="EN-US">/usr/local/nginx/conf</span><span>目录</span><span lang="EN-US">,</span><span>自己根据需要去修改吧</span><span lang="EN-US">.</span></p>
]]></content:encoded>
			<wfw:commentRss>http://www.evanjiang.net.cn/archives/51.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>在 OpenBSD 4.4 上搭建中文语言环境</title>
		<link>http://www.evanjiang.net.cn/archives/48.html</link>
		<comments>http://www.evanjiang.net.cn/archives/48.html#comments</comments>
		<pubDate>Wed, 17 Dec 2008 03:18:34 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[openbsd unix]]></category>
		<category><![CDATA[openbsd 中文]]></category>

		<guid isPermaLink="false">http://www.hunttech.com.cn/wpblog/?p=48</guid>
		<description><![CDATA[<p>• Scim 输入法
• gVim
• 在 ~/.xinitrc 文件中设置启动 GNOME
Scim
目前已经测试可以输入的程序有：
• gVim
• gEdit
• Pidgin
• Firefox 3
• Thunderbird 2
Scim 可以到它的官方网站下载。我个人使用拼音输入法，所以只需要安装两个文件： scim-1.4.x：核心程序；</p>
<p>scim-pinyin：输入法模块
输入法模块可以根据自己的需要进行安装。五笔输入法在 scim-tables 这个包里。
编译参数没有什么特别的，scim, scim-pinyin 都可以这样搞定：</p>
<p>
# ./configure &#8211;prefix=/usr/local
# gmake install
这里必须用 gmake 来编译，依赖的包有： gmake libtool gettext libiconv gtk+2
编译安装好 scim, scim-pinyin 之后还需要让 GTK 程序能够找到这个输入法，需要执行以下命令：
# gtk-query-immodules-2.0 &#62;/var/db/gtk-2.0/gtk.immodules
关于输入法方面的设置：
# File: ~/.xinitrc
export LC_CTYPE=zh_CN.GB18030</p>
<p># 注意大小写
export XMODIFIERS=&#8221;@im=SCIM&#8221;
export XIM=scim
export XIM_PROGRAM=scim
export GTK_IM_MODULE=scim
export QT_IM_MODULE=scim</p>
<p>exec gnome-session # 启动 GNOME
#wmaker                    # 启动 WindowMaker
#fvwm                        # 启动 FVWM
#cwm                         # 启动 cwm。OpenBSD 4.2 自带的非常简单的 [...]]]></description>
			<content:encoded><![CDATA[<p>• Scim 输入法<br />
• gVim<br />
• 在 ~/.xinitrc 文件中设置启动 GNOME<br />
Scim<br />
目前已经测试可以输入的程序有：<br />
• gVim<br />
• gEdit<br />
• Pidgin<br />
• Firefox 3<br />
• Thunderbird 2<br />
Scim 可以到它的官方网站下载。我个人使用拼音输入法，所以只需要安装两个文件： scim-1.4.x：核心程序；</p>
<p>scim-pinyin：输入法模块<br />
输入法模块可以根据自己的需要进行安装。五笔输入法在 scim-tables 这个包里。<br />
编译参数没有什么特别的，scim, scim-pinyin 都可以这样搞定：</p>
<p><span id="more-48"></span><br />
# ./configure &#8211;prefix=/usr/local<br />
# gmake install<br />
这里必须用 gmake 来编译，依赖的包有： gmake libtool gettext libiconv gtk+2<br />
编译安装好 scim, scim-pinyin 之后还需要让 GTK 程序能够找到这个输入法，需要执行以下命令：<br />
# gtk-query-immodules-2.0 &gt;/var/db/gtk-2.0/gtk.immodules<br />
关于输入法方面的设置：<br />
# File: ~/.xinitrc<br />
export LC_CTYPE=zh_CN.GB18030</p>
<p># 注意大小写<br />
export XMODIFIERS=&#8221;@im=SCIM&#8221;<br />
export XIM=scim<br />
export XIM_PROGRAM=scim<br />
export GTK_IM_MODULE=scim<br />
export QT_IM_MODULE=scim</p>
<p>exec gnome-session # 启动 GNOME<br />
#wmaker                    # 启动 WindowMaker<br />
#fvwm                        # 启动 FVWM<br />
#cwm                         # 启动 cwm。OpenBSD 4.2 自带的非常简单的 Window Manager<br />
#startkde                   # 启动 KDE<br />
#startxfce4                 # 启动 XFce4<br />
很奇怪，Scim 不需要在 .xinitrc 里指定启动的程序，它会自动被调用。<br />
gVim<br />
gvim 必须将字符集设置为 utf-8 或 cp936（简体中文）才能使用 scim 正常输入中文，否则乱码：<br />
#<br />
# File: ~/.vimrc<br />
#<br />
#set encoding=cp936<br />
set encoding=utf-8<br />
set fileencoding=utf-8<br />
set fileencodings=utf-8<br />
Start GNOME<br />
在 ~/.xinitrc 中必须这样写才能用 startx 命令启动，否则会报错（Failed to get dbus-daemon&#8217;s pid）：<br />
exec dbus-launch gnome-session</p>
<p>Comment by No.0023, Yesterday (24 hours ago)<br />
if [ -x /usr/local/bin/dbus-daemon ]; then<br />
mkdir -p /var/run/dbus chmod 0755 /var/run/dbus chown dbus:dbus /var/run/dbus<br />
/usr/local/bin/dbus-daemon &#8211;system<br />
fi<br />
俺是加了这段在/etc/rc.local里。 ～/.xinitrc 就gnome-session</p>
]]></content:encoded>
			<wfw:commentRss>http://www.evanjiang.net.cn/archives/48.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
