DHCP 动态分配 IP 服务

参考资讯

  • pinfo dhcpd.conf
  • Red Hat Linux 网路及系统管理指南 2nd Edition (学贯, 986-7693-68-X)

所需套件

  • dhcp-3.0pl2-6.14 (Redhat Enterprise Linux 3 ES)

动态分配 IP 可以让管理者集中控管 IP 的使用状况和发布的范围,而在 Client 端也不用记住自己的 IP 位址,对於一般操作者来说选是一件不错的服务。

静态设定 IP 和动态取得在於前者需要了解当地的网路资讯而设定,这些资讯如:IP、Gateway、DNS、Netmask ... 等等资讯,而若是不知道的话就会无法和网路连结;后者在於使用者的电脑会直接去跟 DHCP Servre 取得网路资讯,这些资讯也包含了网域的设定,而 DHCP Server 收到 Client 的要求之后就会发布一组未使用的 IP 下去,如此一来就不用每次都很麻烦的设定了。

套件查寻

查看系统是否已安装了 dhcp 套件,如果没有就安装一下。

[root@rhel200 root]# rpm -qa | grep dhcp
dhcp-3.0pl2-6.14
[root@rhel200 root]#

编辑设定档 (/etc/dhcpd.conf)

/etc/dhcpd.conf 其是要靠人工一个字一个 key 出来似乎太强人所难,所幸在安好 dhcp 套件之后会连范例档都一起安装上去,所以我们可以把范例档直接拿来修改既可。

[root@rhel200 root]# cd /etc/
[root@rhel200 etc]# cp /usr/share/doc/dhcp-3.0pl2/dhcpd.conf.sample ./dhcpd.conf

dhcp 的范例档是放在 /usr/share/doc/dhcp-3.0pl2/dhcpd.conf.sample,把他复制到 /etc 下并更名为 dhcpd.conf 就可以了,接下来就来开始编辑了。

[root@rhel200 etc]# vi /etc/dhcpd.conf
__________________________________________________________ ddns-update-style interim; ignore client-updates; # 以下 subnet 先指定是那一个区段 subnet 192.168.1.0 netmask 255.255.255.0 { # --- 预设闸道 (gateway) option routers 192.168.1.1; option subnet-mask 255.255.255.0; # --- 设定 nis domain, 用不到所以注解 # option nis-domain "abc.com.tw"; # --- 设定 domain option domain-name "abc.com.tw"; # --- 设定 DNS Server option domain-name-servers 192.168.2.69; option time-offset -18000; # Eastern Standard Time # option ntp-servers 192.168.1.1; # option netbios-name-servers 192.168.1.1; # --- Selects point-to-point node (default is hybrid). Don't change this unless # -- you understand Netbios very well # option netbios-node-type 2; # --- 设定 DHCP 分发的 IP 范围 range dynamic-bootp 192.168.1.100 192.168.1.200; default-lease-time 21600; max-lease-time 43200; # we want the nameserver to appear at a fixed address # host ns { # next-server marvin.redhat.com; # hardware ethernet 12:34:56:78:AB:CD; # fixed-address 207.175.42.254; # } }
__________________________________________________________
[root@rhel200 etc]#

设定好之后就可以启动 DHCP 的服务了。

[root@rhel200 etc]# service dhcpd start
Starting dhcpd: [ OK ]
[root@rhel200 etc]#

Client 设定

  • Windows 设定:开启网路卡的 TCP/IP 内容,设定为自动取得 IP 既可。

  • Linux 设定:使用 netconfig 来设定为 dhcp,再重新启动网路服务既可。
[root@mirror root]# netconfig
[root@mirror root]#

设定完成之后再重新启动网路服务。

[root@mirror root]# service network restart
Shutting down interface eth0: [ OK ]
Shutting down loopback interface: [ OK ]
Setting network parameters: [ OK ]
Bringing up loopback interface: [ OK ]
Bringing up interface eth0: [ OK ]
[root@mirror root]#

02/28/2005

Index