Linux下DHCP服务器基本配置

我的RHEL5.5是默认,然后选中所有软件安装的,这样当再安装软件时就不会报软件依赖性错误了。当然这样也有一个好处,就是dhcp默认安装了。现在就来配置一下默认安装的dhcp服务器。

首先,我们第一步还是来搜索下系统是否安装了dhcp:

rpm -qa | grep dhcp

显示结果:

[root@localhost ~]# rpm -qa | grep dhcp
dhcp-3.0.5-23.el5
sblim-cmpi-dhcp-devel-1.0-40.el5
dhcpv6-client-1.0.10-18.el5
dhcpv6-1.0.10-18.el5
sblim-cmpi-dhcp-1.0-40.el5

显然dhcp已经安装成功了,版本是dhcp-3.0.5-23.el5

第二步,查看一下dhcp相关文件都保存在文件系统的哪个位置:

rpm -ql dhcp

显示结果:

[root@localhost ~]# rpm -ql dhcp
/etc/dhcpd.conf
/etc/rc.d/init.d/dhcpd
/etc/rc.d/init.d/dhcrelay
/etc/sysconfig/dhcpd
/etc/sysconfig/dhcrelay
/usr/bin/omshell
/usr/sbin/dhcpd
/usr/sbin/dhcrelay
/usr/share/doc/dhcp-3.0.5
/usr/share/doc/dhcp-3.0.5/IANA-arp-parameters
/usr/share/doc/dhcp-3.0.5/README
/usr/share/doc/dhcp-3.0.5/RELNOTES
/usr/share/doc/dhcp-3.0.5/api+protocol
/usr/share/doc/dhcp-3.0.5/dhcpd.conf.sample
/usr/share/doc/dhcp-3.0.5/draft-ietf-dhc-authentication-14.txt
/usr/share/doc/dhcp-3.0.5/draft-ietf-dhc-dhcp-dns-12.txt
/usr/share/doc/dhcp-3.0.5/draft-ietf-dhc-failover-07.txt
/usr/share/doc/dhcp-3.0.5/ja_JP.eucJP
/usr/share/doc/dhcp-3.0.5/ja_JP.eucJP/dhclient-script.8
/usr/share/doc/dhcp-3.0.5/ja_JP.eucJP/dhclient.8
/usr/share/doc/dhcp-3.0.5/ja_JP.eucJP/dhclient.conf.5
/usr/share/doc/dhcp-3.0.5/ja_JP.eucJP/dhclient.leases.5
/usr/share/doc/dhcp-3.0.5/ja_JP.eucJP/dhcp-eval.5
/usr/share/doc/dhcp-3.0.5/ja_JP.eucJP/dhcp-options.5
/usr/share/doc/dhcp-3.0.5/rfc1542.txt
/usr/share/doc/dhcp-3.0.5/rfc2131.txt
/usr/share/doc/dhcp-3.0.5/rfc2132.txt
/usr/share/doc/dhcp-3.0.5/rfc2485.txt
/usr/share/doc/dhcp-3.0.5/rfc2489.txt
/usr/share/doc/dhcp-3.0.5/rfc951.txt
/usr/share/man/man1/omshell.1.gz
/usr/share/man/man5/dhcp-eval.5.gz
/usr/share/man/man5/dhcp-options.5.gz
/usr/share/man/man5/dhcpd-eval.5.gz
/usr/share/man/man5/dhcpd-options.5.gz
/usr/share/man/man5/dhcpd.conf.5.gz
/usr/share/man/man5/dhcpd.leases.5.gz
/usr/share/man/man8/dhcpd.8.gz
/usr/share/man/man8/dhcrelay.8.gz
/var/lib/dhcpd
/var/lib/dhcpd/dhcpd.leases

结果中用红线标出的是比较重要的文件路径。

默认情况下,dhcp服务器是无法启动成功的。

[root@localhost ~]# /etc/rc.d/init.d/dhcpd start
启动 dhcpd:[失败]

原因有两个,第一个是dhcp安装完成时,/etc/dhcpd.conf这个文件是空的,没有内容的。解决办法是把/usr/share/doc/dhcp-3.0.5/dhcpd.conf.sample拷贝覆盖/etc/dhcpd.conf。
[root@localhost ~]# cp /usr/share/doc/dhcp-3.0.5/dhcpd.conf.sample /etc/dhcpd.conf
cp:是否覆盖“/etc/dhcpd.conf”? y

另外一个原因是需要修改拷贝过来的/etc/dhcpd.conf文件。

源文件内容为:

[root@localhost ~]# vi /etc/dhcpd.conf

ddns-update-style interim;
ignore client-updates;

subnet 192.168.0.0 netmask 255.255.255.0 {

# --- default gateway
        option routers                  192.168.0.1;
        option subnet-mask              255.255.255.0;

        option nis-domain               "domain.org";
        option domain-name              "domain.org";
        option domain-name-servers      192.168.1.1;

        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;

        range dynamic-bootp 192.168.0.128 192.168.0.254;
        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;
"/etc/dhcpd.conf" 31L, 852C
ddns-update-style interim;
ignore client-updates;

subnet 192.168.0.0 netmask 255.255.255.0 {

# --- default gateway
        option routers                  192.168.0.1;
        option subnet-mask              255.255.255.0;

        option nis-domain               "domain.org";
        option domain-name              "domain.org";
        option domain-name-servers      192.168.1.1;

        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;

        range dynamic-bootp 192.168.0.128 192.168.0.254;
        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@localhost ~]# vi /etc/dhcpd.conf

ddns-update-style interim;
ignore client-updates;

subnet 192.168.1.0 netmask 255.255.255.0 {

# --- default gateway
        option routers                  192.168.1.1;
        option subnet-mask              255.255.255.0;

        option nis-domain               "domain.org";
        option domain-name              "domain.org";
        option domain-name-servers      192.168.1.1;

        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;

        range dynamic-bootp 192.168.1.128 192.168.1.254;
        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 00:0c:29:13:9e:21;
                fixed-address 192.168.1.200;
        }
}

修改时,主要注意这样几点:

我的RHEL5.5的eth0的IP地址配置是这样的:

[root@localhost ~]# ifconfig eth0
eth0      Link encap:Ethernet  HWaddr 00:0C:29:13:9E:21  
          inet addr:192.168.1.200  Bcast:192.168.1.255  Mask:255.255.255.0
          inet6 addr: fe80::20c:29ff:fe13:9e21/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:2386 errors:0 dropped:0 overruns:0 frame:0
          TX packets:350 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:170085 (166.0 KiB)  TX bytes:46118 (45.0 KiB)

然后就可以正常启动DHCP服务了。

[root@localhost ~]# /etc/rc.d/init.d/dhcpd restart
启动 dhcpd:[确定]

你可能感兴趣的:(linux,职场,DHCP,休闲,RHEL5.5)