DHCP

所需軟件:
dhcp-3.0.5-******

DHCP需要給予的是:IP 掩碼 網關 DNS
配置文件是 /etc/dhcpd.conf
軟件裝好後,這個配置文件是空的,但是系統有個參照文件在
/usr/share/doc/dhcp-3.0.5/dhcpd.conf.sample中,直接把這個文件複製爲/etc/dhcpd.conf就行老,直接更改這個文件就非常和諧老

ddns-update-style interim; none      
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;

       
        #下面是靜態IP的設置
        # 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; none

定義所支持的DNS動態更新類型,none表示不支持)
這個參數是必須的,而且必須放在第一行

ignore client-updates
忽略客戶端更新

subnet 192.168.0.0 netmask 255.255.255.0
聲明分配那個網段和掩碼

option routers
設置客戶端網關的

option subnet-mask
設置客戶端子網掩碼

option domain-name-servers
設置客戶端的DNS,多個DNS需要以,(逗號)分隔

range dynamic-bootp
設置聲明網段中具體那個範圍分配給客戶端

default-lease-time
設置IP租約時間,單位是 “妙“

max-lease-time
設置IP租約最大值
hardware ethernet
設置客戶端網卡MAC

fixed-address 207.175.42.254
這個客戶端MAC需要邦定的IP

每個設置值後面都要跟分號 “;”
當DHCP啓動起來後,在
租約數據庫文件 /var/lib/dhcpd/dhcpd.leases
裏面就會有記錄,最開始是沒有記錄的

例 1:綁定多個靜態IP
聲明網段192.168.0.0
路由網關爲 0.1 
DNS   0.5
www   0.4
郵件  0.3
子網掩碼爲255.255.255.0
 
DHCP地址池爲
0.1000.200

ddns-update-style interim;none;
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.0.5;

        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.100 192.168.0.200;
        default-lease-time 21600;
        max-lease-time 43200;

        # we want the nameserver to appear at a fixed address
        host DNS {
                hardware ethernet 00:12:56:78:AB:CD;
                fixed-address 192.168.0.5;
        }

       
        host www {

                hardware ethernet 00:45:56:AD:22:33;
                fixed-address 192.168.0.4;
        }


        host mail {
                hardware ethernet 00:CA:56:AD:27:89;
                fixed-address 192.168.0.3;
        }


}

如果只想分配IP和掩碼,那就把其他的選項註釋掉就可以老
例 2:設置多個網段分配
比如現在主機是400臺,但是在192.168.1.0這個網段只能分配254個IP,那麼就要增加網段,就是多作用域

拓撲圖:


用DHCP服務器的兩張網卡連接兩個網段,並且配置好DHCP兩張網卡自己相應的IP地址,在配置文件中設置兩個聲明就行了
ddns-update-style interim;none;
ignore client-updates;

subnet 192.168.0.0 netmask 255.255.255.0 {

        option routers                  192.168.0.1;
        option subnet-mask              255.255.255.0;
        option domain-name-servers      192.168.0.5;

        range dynamic-bootp 192.168.0.100 192.168.0.200;
        default-lease-time 21600;
        max-lease-time 43200;

}

subnet 192.168.1.0 netmask 255.255.255.0 {

        option routers                  192.168.1.1;
        option subnet-mask              255.255.255.0;
        option domain-name-servers      192.168.1.5;

        range dynamic-bootp 192.168.1.100 192.168.1.200;
        default-lease-time 21600;
        max-lease-time 43200;

}


圖1


圖2



如圖1和圖2所示,
    在客戶端設備和DHCP服務器不再同一廣播域內的時候,中間設備即路有器(路有功能的設備,比如路由和三層交換機)必須要能夠轉發這種廣播包,具體到cisco的設備上,則啓用ip helper-address命令,來實現這種中繼功能
ip helper-address的具體介紹看
(http://www.net130.com/CMS/Pub/special/special_dhcp/special_dhcp_cisco/2006_12_26_71053.htm)


ip helper-address
是把本網段的UDP廣播轉到另一個網段的指定的機器上,而且轉發到另一個網端是以 unicast(單播)的方式進行的








發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章