|
OpenBSD – 局域网篇
在上个月, <<OpenBSD – 中文环境篇>>中我介绍了如何在OpenBSD 3.5, 3.6中使用中文, 另外在OpenBSD – Tech mail list中 Kevin开发了一个locale patch, 打上这个patch后系统支持locale, 我试过后可以在系统中使用locale, 它支持zh_CN.GB2312, zh_CB.ecuCN. 不过各种应用程序可能需要重新编译才能使用locale, 希望在下一版的OpenBSD中能支持locale.
如果大家对locale patch有兴趣,可以看下面这个链接:
http://marc.theaimsgroup.com/?l= ... 34548813907&w=2
在这篇文章中我将对前段时间使用OpenBSD3.6 组网的过程做一个简单的整理。
一, 介绍:
我使用OpenBSD3.6建立一个小型的家庭或办公室局域网。一台机装双网卡, 使用OpenBSD做网关防火墙,一网卡直接连到internet, 另一网卡连接私网中的集线器(hub), 当然也可以是交换机。 通常交换机的性能比集线器好多了!然后从集线器/交换机分出各网线连接到私网中的各台机器, 依集线器/交换机的接口可以接多台机器。 外网卡有一个公共IP地址, 然后我打开OpenBSD的dhcpd, 用它来分配内网私有IP, 当以后局域网中增加地器时直接从集线品接网线到新机器就可以使用了!最后打开OpenBSD的PF, 用它来过渡网络中的数据包。
下面是网络结构图:

OpenBSD机器配置:
300MHz intel processor, 128M RAM, 4GB hard drive, 2 NICs
二, 操作步骤:
1, 安装OpenBSD3.6, 设置使用环境, 具体操作可参考我以前在论坛上写的一些贴子。
2, 网络设置:
这台机使用的是双网卡, 所以需要设置两个网卡地址, 一个是公用IP, 另一个是自定义的私有IP地址:
Gate-OpenBSD# cat hostname.dc0
inet 192.168.1.1 255.255.255.0 NONE
Gate-OpenBSD# cat hostname.ne3
inet 202.116.92.235 255.255.254.0 NONE
ne3接口连接internet, dc0连接lan. dc0的IP地址可以依自己想法设置如192.168.0.1。
3, 网桥设置:
创建/etcbridgename.bridge0
其内容为: add ne3 add dc0 up
也可以使用brconfig命令设置, 如果有不明白的地方可以查看 man pages。
重启, 使用ifconfig –a命令查看网桥是否成功:
bridge0: flags=41<UP,RUNNING> mtu 1500
有上面这一行则代表成功了。
4, 配置DHCPD
1, 编辑/etc/rc.conf, 将dhcpd=NO改为:
dhcpd_flags="" # for normal use: ""
2, 配置/etc/dhcpd.interfaces, dhcpd的监听端口:]
Gate-OpenBSD# cat /etc/dhcpd.interfaces
# $OpenBSD: dhcpd.interfaces,v 1.1 1998/08/19 04:25:45 form Exp $
#
# List of network interfaces served by dhcpd(8).
#
# ep0
# ed0 le0
# de1
dc0
3, 配置/etc/dhcpd.conf文件, 网上有很多配置案例, 自己可以查找看看:
Gate-OpenBSD# cat dhcpd.conf
# $OpenBSD: dhcpd.conf,v 1.1 1998/08/19 04:25:45 form Exp $
#
# DHCP server options.
# See dhcpd.conf(5) and dhcpd(8) for more information.
#
# Network: 192.168.1.0/255.255.255.0
# Domain name: my.domain
# Name servers: 192.168.1.3 and 192.168.1.5
# Default router: 192.168.1.1
# Addresses: 192.168.1.32 - 192.168.1.127
#
#shared-network LOCAL-NET {
# option domain-name "my.domain";
# option domain-name-servers 192.168.1.3, 192.168.1.5;
#
# subnet 192.168.1.0 netmask 255.255.255.0 {
# option routers 192.168.1.1;
#
# range 192.168.1.32 192.168.1.127;
# }
#}
subnet 192.168.1.0 netmask 255.255.255.0 {
option routers 192.168.1.1;
option subnet-mask 255.255.255.0;
option domain-name "lingnanlib.org";
option domain-name-servers 202.116.64.1, 202.116.64.2;
# option time-offset -18000;
range 192.168.1.2 192.168.1.20;
default-lease-time 21600;
max-lease-time 43200;
host Gate-OpenBSD {
next-server Gate-OpenBSD.test.com;
hardware ethernet 00:d0:f8:00:01:f7;
fixed-address 192.168.1.1;
}
}
subnet 202.116.92.235 netmask 255.255.255.255 {
}
重点:
subnet 192.168.1.0 netmask 255.255.255.0 这个是设置私网中IP地址;
option domain-name "lingnanlib.org";
option domain-name-servers 202.116.64.1, 202.116.64.2;
我在开始配置时对这个有点不了解, 后来明白, domain-name这个可以随便设置一个域名, 当然如果自己有国际域名那最好了, domain-name-servers这个设置如果自己不知道, 可以将一台windows机的IP地址设置为自动获取, 然后使用ipconfig /all查看DNS信息就知道了!
5, PF
1, 打开转发功能, 编辑/etc/sysctl.conf, 将net.inet.ip.forwarding=1前面的注释符号 # 去掉。
2, 编辑/etc/rc.conf, 打开PF, pf=YES。
3, 编辑/etc/pf.conf, 设置规则链。我的pf.conf规则链还没设置好, 这里就先贴我现在写的pf.conf, 私网中的机器已可以上网了。
Gate-OpenBSD# cat pf.conf
# $OpenBSD: pf.conf,v 1.28 2004/04/29 21:03:09 frantzen Exp $
#
# See pf.conf(5) and /usr/share/pf for syntax and examples.
# Remember to set net.inet.ip.forwarding=1 and/or net.inet6.ip6.forwarding=1
# in /etc/sysctl.conf if packets are to be forwarded between interfaces.
ext_if="ne3"
int_if="dc0"
tcp_services="{21, 22, 53, 67, 68, 80, 113, 443}"
udp_services="{22, 53, 68}"
icmp_types="echoreq"
lan_net="192.168.1.0/24"
scrub in all
nat on $ext_if from !($ext_if) to any -> ($ext_if:0)
block log all
pass quick on lo0 all
antispoof for { lo $int_if $ext_if } inet
pass in on $ext_if inet proto tcp from any to $ext_if port ssh flags S/SA keep state
pass in on $int_if inet proto tcp from $lan_net to $int_if port ssh flags S/SA keep state
pass in on $int_if from $lan_net to any
pass out on $int_if from any to $lan_net
pass out on $ext_if proto tcp from any to any port $tcp_services keep state
pass out on $ext_if proto udp from any to any port $udp_services keep state
pass in on $int_if proto tcp from any to any port $tcp_services keep state
pass in on $int_if proto udp from any to any port $udp_services keep state
pass in inet proto icmp all icmp-type $icmp_types keep state
pass out inet proto icmp all icmp-type $icmp_types keep state
最后, 这篇过程完了,我还有一些概念不了解, 在看资料中。 如果你觉得有不对的地方, 请指出来, 我需要大家指出错误来, 我就能学习错误, 从错误中进步!
在此提前祝大家元旦快乐! |
|