
机器前些时候重装了,原来用的FC3,现在改成Debian了,感觉更喜欢Debian,比较简洁稳定。安装的时候把KDE,Gnome都装上了,感觉还是喜欢Gnome!而且Debian的APT用起来比较爽,比yum要强多了!
最近要用DHCP服务给我的目标板,和家里的别一台机器动态分配IP,于是想起了要装一个DHCP SERVER。不过在DEBIAN里的设置与FC3里有不少的不一样的地方。
我的机器现在装了一块网卡,与cable modem连接,也是通过DHCP从MODEM那得到的IP。现在我想再设置我的机器给家里的其它机器提供DHCP服务。这里只说DHCP SERVER的设置,如果其它机器要通过本机来上网的,那还要设置NAT,这里我就不说了,有空时再加上吧。
不过大家可以参考鸟哥的主页(其实我都是从那学来的)。
www.vbird.org
还得再提一下,我机器上有两个网段一个是eth0从 modem那得到的IP,另一个是我自己建的一个虚拟网卡(大概是叫这个概念吧),网段是192.168.200.0。我的DHCP服务就是建立在这块虚拟的网卡之上的。下面就先来讲一下是如何设置的。
在DEBIAN下网卡的配置文件是在/etc/network下面的。
XXX# ls -l /etc/network/
总用量 28
drwxr-xr-x 2 root root 4096 2006-09-16 22:16 if-down.d
drwxr-xr-x 2 root root 4096 2005-05-02 22:09 if-post-down.d
drwxr-xr-x 2 root root 4096 2005-05-02 22:09 if-pre-up.d
drwxr-xr-x 2 root root 4096 2006-09-16 22:16 if-up.d
-rw-r--r-- 1 root root 573 2006-09-20 19:24 interfaces
-rw-r--r-- 1 root root 45 2006-09-01 09:52 options
drwxr-xr-x 2 root root 4096 2006-09-20 19:19 run
其中的interfaces就是我们要设置的文件,先看一下我的设置吧
#more /etc/network/interfaces
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).
# The loopback network interface
auto lo
iface lo inet loopback
# The primary network interface
auto eth0
iface eth0 inet dhcp
name 以太网局域网网卡
iface dsl-provider inet static
provider dsl-provider
# please do not modify the following line
pre-up /sbin/ifconfig eth0 up # line maintained by pppoeconf
auto eth0:1
iface eth0:1 inet static
address 192.168.200.1
netmask 255.255.255.0
name 内部虚拟网卡
下面就说如何安装设置DHCP-SERVER包了。这里我安装的是:DHCP3-SERVER。执行:
#aptitude
搜索一下(在aptitude的介面里按'/',即可打开搜索框),这里就可见apt比 yum方便很多了!找到后选择(按‘+’),下载(‘g'),安装。
安装完成之后会进入设置介面,在设置DHCP所使用的网卡的时候输入 eth0,可不能输入eth0:1我一开始就是犯了这个错,折腾了一个多小时!不然在开始服务的时候会出错,syslog出错信息如下:
dhcpd: No subnet declaration for eth0:1 (0.0.0.0).
dhcpd: ** Ignoring requests on eth0:1. If this is not what
dhcpd: you want, please write a subnet declaration
localhost dhcpd: in your dhcpd.conf file for the network segment
localhost dhcpd: to which interface eth0:1 is attached. **
localhost dhcpd:
安装完成之后,要做的就是设置dhcpd.conf的配置文件,在DEBIAN里它的位置是/etc/dhcp3/dhcpd.conf。安装好之后,默认的在那里的有这个文件,只需打开,在它的基础上改一改就可以了。它里面有很仔细的示例说明,大家仔细看一下,就能明白个大概了。下面是我的设置
ddns-update-style none;
log-facility local7;
subnet 192.168.200.0 netmask 255.255.255.0 {
range 192.168.200.2 192.168.200.100;
option subnet-mask 255.255.255.0;
option domain-name-servers 192.168.0.1;
option domain-name "internal.example.org";
option routers 192.168.200.1;
option broadcast-address 192.168.200.1;
default-lease-time 600;
max-lease-time 7200;
}
设置好之后重启一下DHCP服务:
#/etc/init.d/dhcp3-server restart
至此DHCP服务器就可以用了。