发新话题
打印

DHCP How-To(netbsd)

DHCP How-To(netbsd)

DHCP How-To(netbsd)

Who needs to use DHCP

许多isp服务商使用它为客户动态分配ip,控制其他网络设定.另外的用途是可以连接到多个网络的笔记本电脑.比如,可以连接到offcie和home网络.

DHCP Client Setup

1    客户端设置:
/etc/dhclient.conf请看dhclient.conf,/dhcp-options的manpage.典型的/etc/dhclient.conf:

    Send host-name "myname.my.domain";                 <=== Put your
                                                        hostname here.
    send dhcp-client-identifier "myident";             <=== Put your host
                                                        identifier here.
                            (this is often times
                             the same as myname).
    request subnet-mask, broadcast-address, routers,
        domain-name-servers;

    timeout 30;
    retry 60;
    select-timeout 5;

    script "/sbin/dhclient-script";

    lease {
      interface "sn0";                               <=== put your interface
                                                      device here.
      option host-name "myname.my.domain";           <=== put your
                                                          hostname here
      option subnet-mask 255.255.255.0;
      option domain-name "my.domain";                <=== put your
                                                          domain name here
      option domain-name-servers 127.0.0.1;
      renew 2 2000/1/12 00:00:01;
      rebind 2 2000/1/12 00:00:01;
      expire 2 2000/1/12 00:00:01;
    }
   
    启动dhcp
    编辑/etc/rc.conf
        dhclient=YES
    默认的,dhcp请求将被送到所有网络接口.如果你想指定某个接口,请使用dhclient-flags
    比如:
        dhclient_flags='ae1'
    接着,重起机器,如果不想重新启动就激活配置,请运行sh /etc/rc.d/dhclient start
   
How do I keep dhclient from nuking my /etc/resolv.conf?
    通常,dhclient会用从dhcp接受到的信息重写/etc/resolv.conf,如果不想使用这个特性,你可以这样
    # cat /etc/dhclient-enter-hooks
        make_resolv_conf() {
                echo "doing nothing to resolv.conf"
        }

        See the dhclient-script(8) man page for more information.


2,dhcp服务器配置

    如果你没有需要使用动态ip分配,就没必要看了

    配置文件/etc/dhcpd.conf.典型的配置:下面的列子动态分配192.168.0.2-8.dhcpd服务起将为客户设定ip,子网掩码,路由,域名服务,和域名

        # Setting DHCPD global parameters
        allow unknown-clients;

        # Set parameters for the 192.168.0.0/24 subnet.
        subnet 192.168.0.0 netmask 255.255.255.0 {
        range 192.168.0.2 192.168.0.8;                <=== ip分配范围
                                                   
        default-lease-time 604800;                    <=== 默认分配时间
                                                   
        max-lease-time 604800;                        <=== 最大分配时间
                                                   
        option subnet-mask 255.255.255.0;             <=== 掩码
        option domain-name-servers 1.2.3.4, 1.2.3.5;  <=== dhcp服务地址
        option domain-name "your.domain.name";
        option routers 192.168.0.1;                   <=== 默认路由
        }
   
    激活服务
    编辑/etc/rc.conf,加入


    dhcpd=YES
    如果想绑定服务的地址:
    dhcpd-flags="-q ae1"
   
    创建dhcpd.leases(出租时间)
    /var/db/dhcpd.leases
    如果没有,请
    touch /var/db/dhcpd.leases
------------------
20050122 tsgelib v0.1 (bsd license)

TOP

发新话题