Basic NetBSD Networking
netbsd安装进程已经包含网络的基本配置(其实当前系统已经又sushi这个系统管理工具,很好用:译者),这个配置可以延伸到更多高级的网络特性.
网络配置文件:
全是一些text文件:
/etc/rc.conf:系统服务,包含网络服务,被系统初始时自动执行.
/etc/hosts:基本的主机名/ip 映射
/etc/myname:主机名全称(除非在rc.conf以hostname=设定了)
/etc/mygate:默认网关.最好在rc.conf中以defaultroute=定义,或者使用route add default x.x.x.x
/etc/ifconfig.IF:网卡IF设定(比如IF是fxp),被/etc/rc.d/network使用(当系统初始化时),参考 ifconfig.if的manpage,另外的选择是在rc.conf中以ifconfig_IF=设定.
/etc/ifaliases:绑定多个ip到单一网卡,也被/etc/rc.d/network使用.
/etc/resolv.conf:域名解析.通常是:
search subdomain.yourdomain.tld yourdomain.tld
nameserver 192.168.253.10
nameserver 192.168.253.11
使用dhcp时被dhclient覆盖
参考hostname的manpage
网络配置程序
2个特重要,被/etc/rc.d/network使用,也可以用来手动配置一个网络
ifconfig:查看,更改网络接口
route:处理网络路由表
参考domainname,hostname的manpage
为网络添加一个新主机
假设你的网络使用dhcp,你所要做的就只是在/etc/rc.conf中加入dhclient=YES,dhcp客户程序将为你自动配置 ip,hostname,router,nameserver,domainname.参考dhcp的页面.
如果没有使用dhcp,那么至少你得为你的网络接口配置ip,如果在安装netbsd的时候你已经配置了这些,那么现在你可以立即使用本地网络了.
下面是一个简单的手动步骤:(假设你的网络接口是ex)
ifconfig lo0 127.0.0.1
ifconfig ex0 192.168.253.2 netmask 255.255.255.0
route add default 192.168.253.1
为新主机命名
为了以hostname访问(类似ip访问),新主机的名字和ip得加入到网络的配置文件中,有几个步骤可以实现:
1,/etc/hosts:针对只有一些主机的小网络,hostname/ip映射,可以手动配置:
etc/hosts:
192.168.1.2 host2.mydomain.org.au host2
2,nis
3,dns
连接网络(以太)
连接你的网络(通常就一台)到另外的网络需要在两个网络间有网关.网络由2个接口,每个网络一个.
为第二个以太接口创建一个接口配置文件/etc/ifconfig.interface
/etc/ifconfig.wel
192.168.2.30 netmask 0xffffff00 media 10base2/BNC
或者在rc.conf中加入:
ifconfig_we1="192.168.2.30 netmask 0xffffff00 media 10base2/BNC"
重新启动机器以便激活接口
如果有必要,激活ip包转发功能.也可以编译kernele时使用options GATEWAY ,或者使用
sysctl -w net.inet.ip.forwarding=1(每当你系统启动后),或者将它加入到/etc/sysctl.conf中(偷懒拉)
请参考ipnat,ipf.conf,sysctl,sysctl.conf的manpage
通过ppp连接网络
在使用ppp的串口(不管有没有modem连接到此)建立一个特定网络接口.
1,建立peer options文件
/etc/ppp/peers/myisp
# Example pppd options
# Specific for myisp
/dev/tty01
local_IP_address:remote_IP_address
connect '/usr/sbin/chat -v -f /etc/ppp/peers/myisp.chat'
defaultroute
persist
ipparam myisp
asyncmap 0
noauth
2,建立device options文件
etc/ppp/options.{ttyname}
# Example pppd options
# Specific for ttyname
lock
crtscts
57600
modem
3,建立chat文件
#
/etc/ppp/peers/myisp.chat
# Example chat file
# Specific for myisp
ABORT BUSY ABORT 'NO CARRIER' ""
\da\ptz0 OK
\da\ptdt8887776655 CONNECT
4,建立连接
pppd call myisp
5,设定参数
在/etc/rc.conf中加入ppp-peers='myisp',这样系统启动时将自动连接
没有必要象以太网卡一样建立ifconfig.interface文件
如果你使用按需拨号,不希望一些网络传输拨号,你可以加入active-filter到ppd.conf中:
active-filter 'not udp port ntp'
请参考chat的manpage
为使用租用线路配置pppd
租用线路是灵活的p-to-p连接.netbsd中设定轻而易举..在服务器端建立/etc/ppp/options:(类似下面)
/dev/tty00
57600
noauth
crtscts
passive
<local_IP_address>:<remote_IP_address>
debug
netmask 255.255.255.255
proxyarp
你得根据你的网络情况改变localip和remoteip,localip可以和你的以太网ip一样,remoteip也得是你的以太网内的一个ip
而在客户端:/etc/ppp/options:(类似下面)
/dev/tty00
57600
noauth
crtscts
defaultroute
debug
注意服务器和客户端的dev/tty00是你的串行端口的名字
怎样使用isdn modem(terminal adapter,TA)
在netbsd中TA看起来和普通modem差不多.根据你的isp,你可以从下面的模式中选择其一:
sync-to-async-HDLC conversion: Translates synchronous HDLC frames into async-HDLC frames. Use this if your provider offers "real" PPP over HDLC on the B-Channel directly, which is the standard nowadays.
X75: X.25 over ISDN B-channel
V120: which is intended to simulate lower bandwidth modems to slow computer terminal lines; unfortunately this wastes some of the bandwidth of your ISDN line, though
V110: which is an old version of V120
......
一个nat(ip masquerading)简单配置列子:
你的私有网络想通过一个netbsd机器(作为router)上网,那么可以通过nat实现:
1,客户端,/etc/rc.conf中为defaultrouter=x.x.x.x(作为nat的netbsd机器的地址,x.x.x.x是私有ip)
2,在 nat机器上,首先确认kernel配置有ipfilter(默认kernel已经有)
options PFIL_HOOKS # pfil(9) packet filter hooks
pseudo-device ipfilter # IP filter (firewall) and NAT
3,编辑ipf.conf
pass in from any to any
pass out from any to any
4,编辑/etc/ipnat.conf
map ppp0 10.0.0.0/24 -> 0/32 proxy port ftp ftp/tcp
map ppp0 10.0.0.0/24 -> 0/32 portmap tcp/udp 40000:60000
map ppp0 10.0.0.0/24 -> 0/32
5,激活一些服务/etc/rc.conf
ipfilter=YES
ipnat=YES
6,激活ip包转发/etc/sysctl.conf
net.inet.ip.forwarding=1
7,重起
8,使用ping,tcpdump,ipfstat,ipnat调试
(译者:dsl/pppoe的配置我单独译为一节)
维护工具:
ifconfig/route/ping/tarceroute/tcddump/netstat/systat
参考mrtg
安全:
/etc/hosts.[allow,deny]:inetd中使用的tcp wrapper.
使用ipfilter,参考ipf,ipfs,ipfstat
下面的有省略