Chinaunix首页 | 论坛 | 博客
  • 博客访问: 4022881
  • 博文数量: 272
  • 博客积分: 7846
  • 博客等级: 少将
  • 技术积分: 6476
  • 用 户 组: 普通用户
  • 注册时间: 2009-08-25 16:27
文章分类

全部博文(272)

分类: LINUX

2009-09-22 10:32:21

安装dhcp,yum install dhcp rpm -qa | grep dhcp dhcp-3.0.5-18-el5 默认下,/etc/dhcpd.conf文档为空,所以刚安装了软件,启动dhcp服务是失败的。把/usr/share/doc/dhcp-3.0.5/dhcp.conf.sample拷贝至/etc,并命名为dhcpd.conf,覆盖掉那个空文件。

 cp /usr/share/doc/dhcp-3.0.5/dhcp.conf.sample /etc/dhcpd.conf yes覆盖

这时如果还是不能启动服务,则考虑您的电脑网卡是否被激活,使用ifconfig查看,如果只有lo则需要,ifup eth0激活网卡。 使用service dhcpd start,就【确定】或【OK】了。

接着,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;
                fixed-address 207.175.42.254;
        }
}

 

现在来修改配置文件,以满足我们自己的需要:

前提:

ddns-update-style interim;

ignore client-updates;

第一句是指定DHCP服务器支持DNS动态更新的方式为interim,第二句指定客户机不能更新DNS记录,这是对所有子网有效的参数,所以我们把它们放在最开始。

 1、设置IP地址范围 subnet语句用于声明IP地址范围。它的格式如下:

subnet 子网 IP network 子网掩码

{

range 起始IP 结束IP;

IP 参数;

}

我们的网络是个机房里的局域网,网关是192.168.0.254,子网掩码是255.255.255.0,DNS服务器是210.47.176.1,机房里设想的30台电脑的IP范围从192.168.0.200到192.168.0.230。现在就在Linux中这样设置:

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

subnet 192.168.0.0 netmask 255.255.255.0 {


        option routers                  192.168.0.254;
        option subnet-mask              255.255.255.0;


        option domain-name              "linux";
        option domain-name-servers      210.47.176.1;

        range 192.168.0.200 192.168.0.230;
}
然后service dhcpd restart。设置别的电脑为自动获得IP地址和DNS服务器地址,重启网卡,用ifconfig(linux)或ipconfig /all(windows)查看即可。

现在网络中有台电脑,需要设置固定IP为192.168.0.100,其他都是自动获得,我们就需要在配置文件中给这台电脑加入规则。
首先,查看这台电脑网卡的物理地址即MAC地址,再在dhcpd.conf中加入一段话:

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

subnet 192.168.0.0 netmask 255.255.255.0 {


        option routers                  192.168.0.254;
        option subnet-mask              255.255.255.0;


        option domain-name              "linux";
        option domain-name-servers      210.47.176.1;

        range 192.168.0.200 192.168.0.230;

        host jsj{

        hardware ethernet 00:1C:25:3B:35:57;

        fix-address 192.168.0.100;

        }
}

保存文件,重启服务,再重启那台电脑,即可发现其IP地址变为192.168.0.100了,当然host jsj中的jsj是那台电脑的名字,和MAC地址一样得自己查。

阅读(5609) | 评论(3) | 转发(0) |
给主人留下些什么吧!~~

chinaunix网友2009-12-07 06:09:58

恩,我想是不是并不重要。重要的是你能把它写好。哈哈。

五岳之巅2009-10-18 20:42:54

你不是我班上的吧?

chinaunix网友2009-10-15 16:47:20

你好,我也是学这个的。 你写得很好,但是我还是希望你能再写的详细一些. 谢谢了.