<?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; cvs</title>
	<atom:link href="http://www.evanjiang.net.cn/archives/category/apps/cvs/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>CVS使用经验谈</title>
		<link>http://www.evanjiang.net.cn/archives/857.html</link>
		<comments>http://www.evanjiang.net.cn/archives/857.html#comments</comments>
		<pubDate>Wed, 25 Mar 2009 04:13:47 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[cvs]]></category>
		<category><![CDATA[CVS使用经验]]></category>

		<guid isPermaLink="false">http://www.evanjiang.net.cn/?p=857</guid>
		<description><![CDATA[<p>


 <p>CVS 是 Concurrent Version System（并行版本系统）的缩写，用于版本管理。在多人团队开发中的作用更加明显。CVS 的基本工作思路是这样的：在一台服务器上建立一个仓库，仓库里可以存放许多不同项目的源程序。由仓库管理员统一管理这些源程序。这样，就好象只有一个人在 修改文件一样。避免冲突。每个用户在使用仓库之前，首先要把仓库里的项目文件下载到本地。用户做的任何修改首先都是在本地进行，然后用 cvs 命令进行提交，由 cvs 仓库管理员统一 修改。这样就可以做到跟踪文件变化，冲突控制等等。
　　由于CVS是建立在在原先 Unix 体系里很成熟的 SCCS 和 RCS 的基础上，所以CVS多是Linux（UNIX）系统中所使用，本文中服务器端设置也是以Linux为例。
　　一、CVS服务器的安装
　　首先确认系统中是否安装CVS服务：
　　[root@localhost /]# rpm -qa&#124;grep cvs
cvs-1.11.2-cvshome.7x.1
　　如果命令输出类似于上面的输出则说明系统已经安装有cvs，否则就需要从安装光盘中安装cvs的rpm包，或者到http://www.cvshome.org下载。
　　1、建立 CVSROOT
　　目录，因为这里涉及到用户对CVSROOT里的文件读写的权限问题，所以比较简单的方法是建立一个组，然后再建立一个属于该组的帐户，而且以后有读写权限的用户都要属于该组。假设我们建一个组叫cvs，用户名是cvsroot。建组和用户的命令如下
#groupadd cvs
#adduser cvsroot
　　生成的用户宿主目录在/home/cvsroot（根据自己的系统调整）
　　2、用cvsroot 用户登陆，修改 /home/cvsroot （CVSROOT）的权限，赋与同组人有读写的权限：　
　　$chmod 771 . （或者770应该也可以）
　　注意：这一部分工作是按照文档说明做的，是否一定需要这样没有试验，我会在做试验后在以后版本的教程说得仔细一点。如果您有这方面的经验请提供给我，谢谢。
　　3、建立CVS仓库，（仍然是 cvsroot 用户），用下面命令：
　　$cvs -d /home/cvsroot init
　　4、以root身份登陆，修改 /etc/inetd.conf（使用 xinetd 的系统没有此文件）和 /etc/services
　　如果用的是 inetd 的系统，在 /etc/inetd.conf 里加入：
　　
　　cvsserver　 stream tcp nowait root /usr/bin/cvs cvs -f &#8211;allow-root=/home/cvsroot pserver
　　说明：上面的行是单独一整行，/usr/bin/cvs 应该是你的cvs版本的命令路径，请根据自己的系统调整．/home/cvsroot是你建立的CVSROOT的路径，也请根据上面建立目录的部分的内容做调整。
　　如果是使用 [...]]]></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>CVS 是 Concurrent Version System（并行版本系统）的缩写，用于版本管理。在多人团队开发中的作用更加明显。CVS 的基本工作思路是这样的：在一台服务器上建立一个仓库，仓库里可以存放许多不同项目的源程序。由仓库管理员统一管理这些源程序。这样，就好象只有一个人在 修改文件一样。避免冲突。每个用户在使用仓库之前，首先要把仓库里的项目文件下载到本地。用户做的任何修改首先都是在本地进行，然后用 cvs 命令进行提交，由 cvs 仓库管理员统一 修改。这样就可以做到跟踪文件变化，冲突控制等等。<br />
　　由于CVS是建立在在原先 Unix 体系里很成熟的 SCCS 和 RCS 的基础上，所以CVS多是Linux（UNIX）系统中所使用，本文中服务器端设置也是以Linux为例。<br />
　　一、CVS服务器的安装<br />
　　首先确认系统中是否安装CVS服务：<br />
　　[root@localhost /]# rpm -qa|grep cvs<br />
cvs-1.11.2-cvshome.7x.1<br />
　　如果命令输出类似于上面的输出则说明系统已经安装有cvs，否则就需要从安装光盘中安装cvs的rpm包，或者到http://www.cvshome.org下载。<br />
　　1、建立 CVSROOT<br />
　　目录，因为这里涉及到用户对CVSROOT里的文件读写的权限问题，所以比较简单的方法是建立一个组，然后再建立一个属于该组的帐户，而且以后有读写权限的用户都要属于该组。假设我们建一个组叫cvs，用户名是cvsroot。建组和用户的命令如下<br />
#groupadd cvs<br />
#adduser cvsroot<br />
　　生成的用户宿主目录在/home/cvsroot（根据自己的系统调整）<br />
　　2、用cvsroot 用户登陆，修改 /home/cvsroot （CVSROOT）的权限，赋与同组人有读写的权限：　<br />
　　$chmod 771 . （或者770应该也可以）<br />
　　注意：这一部分工作是按照文档说明做的，是否一定需要这样没有试验，我会在做试验后在以后版本的教程说得仔细一点。如果您有这方面的经验请提供给我，谢谢。<br />
　　3、建立CVS仓库，（仍然是 cvsroot 用户），用下面命令：<br />
　　$cvs -d /home/cvsroot init<br />
　　4、以root身份登陆，修改 /etc/inetd.conf（使用 xinetd 的系统没有此文件）和 /etc/services<br />
　　如果用的是 inetd 的系统，在 /etc/inetd.conf 里加入：<br />
　<span id="more-857"></span>　<br />
　　cvsserver　 stream tcp nowait root /usr/bin/cvs cvs -f &#8211;allow-root=/home/cvsroot pserver<br />
　　说明：上面的行是单独一整行，/usr/bin/cvs 应该是你的cvs版本的命令路径，请根据自己的系统调整．/home/cvsroot是你建立的CVSROOT的路径，也请根据上面建立目录的部分的内容做调整。<br />
　　如果是使用 xinetd 的系统，需要在 /etc/xinetd.d/ 目录下创建文件 cvspserver（此名字可以自己定义），内容如下：<br />
　　# default: on<br />
　　# description: The cvs server sessions;<br />
　　service cvsserver<br />
　　{<br />
　　socket_type = stream<br />
　　wait = no<br />
　　user = root<br />
　　server = /usr/bin/cvs<br />
　　server_args = -f &#8211;allow-root=/cvsroot pserver<br />
　　log_on_failure += USERID<br />
　　only_from = 192.168.0.0/24<br />
　　}<br />
　　其中only_from是用来限制访问的，可以根据实际情况不要或者修改。修改该文件权限：<br />
　　# chmod 644 cvspserver<br />
　　在/etc/services里加入：<br />
　　cvsserver 2401/tcp<br />
　　说明：cvsserver 是任意的名称，但是不能和已有的服务重名，也要和上面修改 /etc/inetd.conf 那行的第一项一致。<br />
　　5、添加可以使用 CVS 服务的用户到 cvs 组：<br />
　　以 root 身份修改 /etc/group，把需要使用 CVS 的用户名加到 cvs 组里，比如我想让用户 laser 和gumpwu 能够使用 CVS 服务，那么修改以后的 /etc/group 应该有下面这样一行：<br />
　　cvs:x:105:laser,gumpwu<br />
　　在你的系统上GID可能不是105，没有关系。主要是要把laser和gumpwu用逗号分隔开写在最后一个冒号后面。当然，象RedHat等分发版有类似linuxconf这样的工具的话，用工具做这件事会更简单些。<br />
　　6、重起inetd使修改生效：<br />
　　#killall -HUP inetd<br />
　　如果使用的是 xinetd 的系统：</p>
<p>　　# /etc/rc.d/init.d/xined restart<br />
然后察看cvs服务器是否已经运行：<br />
[root@localhost /]# netstat -lnp|grep 2401<br />
　　tcp 0 0 0.0.0.0:2401 0.0.0.0:* LISTEN 1041/xinetd<br />
则说明cvs服务器已经运行。</p>
<p>　　二、管理CVS服务器<br />
　　服务器可以用，现在大家最关心的就是如何管理服务器，比如，我想让一些人有读和/或写 CVS 仓库的权限，但是不想给它系统权限怎么办呢？<br />
　　不难，在 cvs 管理员用户（在我这里是 cvsroot 用户）的家目录里有一个 CVSROOT 目录，这个目录里有三个配置文件，passwd, readers, writers，我们可以通过设置这三个文件来配置 CVS 服务器，下面分别介绍这几个文件的作用：<br />
　　passwd：cvs 用户的用户列表文件，它的格式很象 shadow 文件：<br />
　　{cvs 用户名}:[加密的口令]:[等效系统用户名]<br />
　　如果你希望一个用户只是 cvs 用户，而不是系统用户，那么你就要设置这个文件，刚刚安装完之后这个文件可能不存在，你需要以 cvs 管理员用户手工创建，当然要按照上面格式，第二个字段是该用户的加密口令，就是用 crypt (3)加密的，你可以自己写一个程序来做加密，也可以用我介绍的偷懒的方法：先创建一个系统用户，名字和 cvs 用户一样，口令就是准备给它的 cvs 用户口令，创建完之后从 /etc/shadow 把该用户第二个字段拷贝过来，然后再把这个用户删除。这个方法对付数量少的用户比较方便，人一多就不合适，而且还有冲突条件(race condition)的安全隐患，还要 root 权限，实在不怎么样。不过权益之计而已。写一个小程序并不难，可以到 linuxforum 的编程版搜索一下，有个朋友已经写一个贴在上面。<br />
　　第三个字段就是等效系统用户名，实际上就是赋与一个 cvs 用户一个等效的系统用户的权限，看下面的例子你就明白它的功能。<br />
　　readers：有 cvs 读权限的用户列表文件。就是一个一维列表。在这个文件中的用户对 cvs只有读权限。<br />
　　writers：有 cvs 写权限的用户的列表文件。和 readers 一样，是一个一维列表。在这个文件中的用户对 cvs 有写权限。<br />
　　上面三个文件在缺省安装的时候可能都不存在，需要我们自己创建，好吧，现在还是让我们用一个例子来教学吧。假设我们有下面几个用户需要使用 cvs：<br />
　　laser, gumpwu, henry, betty, anonymous。<br />
　　其中 laser 和 gumpwu 是系统用户，而 henry, betty, anonymous 我们都不想给系统用户权限，并且 betty 和 anonymous 都是只读用户，而且 anonymous 更是连口令都没有。那么好，我们先做一些准备工作，先创建一个 cvspub 用户，这个用户的责任是代表所有非系统用户的 cvs 用户读写 cvs 仓库。<br />
　　#adduser<br />
　　&#8230;<br />
　　然后编辑 /etc/group，令 cvspub 用户在 cvs 组里，同时把其它有系统用户权限的用户加到 cvs 组里。（见上文）<br />
　　然后编辑 cvs 管理员家目录里 CVSROOT/passwd 文件，加入下面几行：<br />
　　laser:$xxefajfka;faffa33:cvspub<br />
　　gumpwu:$ajfaal;323r0ofeeanv:cvspub<br />
　　henry:$fajkdpaieje:cvspub<br />
　　betty:fjkal;ffjieinfn/:cvspub<br />
　　anonymous::cvspub<br />
　　注意：上面的第二个字段（分隔符为 :）是密文口令，你要用程序或者用我的土办法生成。<br />
　　编辑 readers 文件，加入下面几行：<br />
　　anonymous<br />
　　betty<br />
　　编辑 writers 文件，加入下面几行：<br />
　　laser<br />
　　gumpwu<br />
　　henry<br />
　　注意：writers中的用户不能在readers中，要不然不能上传更新文件。</p>
<p>　　对于使用CVS的用户要修改它的环境变量，例如laser用户的环境变量，打开/home/laser（laser的宿主目录）下的.bash_profile文件，加入<br />
　　CVSROOT=/home/cvsroot<br />
　　export CVSROOT<br />
　　用laser登陆就可以建立CVS项目，如果要root使用，可以修改/etc/profile文件。</p>
<p>　　现在我们各项都设置好，那么怎么用呢，我在这里写一个最简单的（估计也是最常用的）命令介绍：<br />
　　首先，建立一个新的CVS项目，一般我们都已经有一些项目文件，这样我们可以用下面步骤生成一个新的CVS项目：<br />
　　进入到你的已有项目的目录，比如叫 cvstest：<br />
　　$cd cvstest<br />
　　运行命令：<br />
　　$cvs import -m &#8220;this is a cvstest project&#8221; cvstest v_0_0_1 start<br />
　　说明：import 是cvs的命令之一，表示向cvs仓库输入项目文件。 -m参数后面的字串是描述文本，随便写些有意义的东西，如果不加 -m 参数，那么cvs会自动运行一个编辑器（一般是vi，但是可以通过修改环境变量EDITOR来改成你喜欢用的编辑器。）让你输入信息，cvstest 是项目名称（实际上是仓库名，在CVS服务器上会存储在以这个名字命名的仓库里。）<br />
v_0_0_1是这个分支的总标记。没啥用（或曰不常用。）<br />
start 是每次 import 标识文件的输入层次的标记，没啥用。<br />
这样我们就建立一个CVS仓库。<br />
　　建立CVS仓库的文件夹应该是“干净”的文件夹，即只包括源码文件和描述的文件加，而不应该包括编译过的文件代码等！<br />
　　三、使用CVS<br />
　　winCVS是一个很好的CVS客户端软件，在http://cnpack.cosoft.org.cn/down/wincvsdailyguide.pdf可以下载到这个软件的使用手册。这里不在赘述。<br />
　　四、用CVS管理项目<br />
　　本人正在一加公司从事该公司ERP项目的开发，在没有使用CVS的时候，多次出现由于不同的开发人员修改同一程序，而导致程序错误，解决版本控制问题迫在眉睫。<br />
　　由于这个项目采用Linux平台下JAVA开发，使用的开发工具Jbulider是支持CVS进行项目管理的，作为主程序员，我决定采用CVS进行版本控制，首先参照上文在Linux服务器上建立CVS服务，然后我把我本地的工程文件传至服务器。<br />
　　例如：我的工程文件在F:\ERP下，我把ERP下的erp.jpx文件、defaultroot文件夹和src文件夹上传至服务器/usr/local/erp下，然后登陆Linux服务器，登陆的用户是CVS的用户，其环境变量要正确（我的用户名为admin）<br />
　　#cd /usr/local/erp<br />
　　#cvs import -m &#8220;this is a ERP project&#8221; erp v_0_0_1 start<br />
　　这样名为erp的CVS仓库就建立。<br />
　　之后开发小组的成员可以用winCVS把该项目下载到本地：<br />
　　打开winCVS<br />
　　点击工具栏Create -> Create a new repository&#8230; 弹出窗口<br />
　　在Grenral中<br />
　　Enter the CVSROOT填写admin@192.168.1.9:/home/cvsroot 其中admin是cvs的用户，在本例中admin也是linux的系统用户，192.168.1.9是服务器的地址，/home/cvsroot是 CVS的主目录，参考上文。<br />
　　Authentication中选择&#8221;passwd file on the cvs server&#8221;<br />
　　Use version中选择cvs 1.10 (Standard)<br />
　　其它项默认即可。<br />
　　确认后，点工具栏Admin &#8211;> Login&#8230; 会提示输入密码，输入密码后，看看winCvs的状态栏。如果提示<br />
　　*****CVS exited normally with code 0*****<br />
　　表示登录正常。<br />
　　点击工具栏Create &#8211;> Checkout module&#8230;弹出对话框，其中的Checkout settings项中<br />
　　Enter the module name and path on the server 填写erp，即我们建立的名为erp的CVS仓库<br />
　　Local folder to checkout to 选择要下载到本地的目录，我选F:\myerp<br />
　　其它项目可以默认，确定后就可以下载到本地，在F:\myerp\下会有一个erp文件夹，其文件结构和F:\erp下的文件结构是一样的。<br />
　　用Jbulider打开F:\myerp\erp\下的erp.jpx文件，这个工程文件就可以使用。<br />
　　在Jbuilder的工具栏Team &#8211;> Select Project VCS 弹出对话框，选择CVS<br />
　　对于你要进行修改的文件，在Project View中点中该文件，然后点右键，探出快捷菜单，选择CVS &#8211;> CVS Edit &#8220;xxxx.java（文件名）&#8221;<br />
　　第一次使用可能会提示CVS服务器的密码。<br />
　　在修改之前还要选择CVS &#8211;> Update &#8220;xxxx.java（文件名）&#8221;<br />
　　修改之后选择CVS &#8211;> Commit &#8220;xxxx.java（文件名）&#8221;<br />
　　这样，修改的文件就保存到CVS服务器，Update的目的是下载、比较文件。每次在修改之前都Update，保持最新版本。<br />
　　CVS在项目管理使用中确实起到良好的效果，仔细研究CVS的命令，可以更好的发挥CVS在版本控制上的能力。</p>
]]></content:encoded>
			<wfw:commentRss>http://www.evanjiang.net.cn/archives/857.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 style="float: right;margin: 4px;">


</p> <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 [...]]]></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>
	</channel>
</rss>
