關於dhcp的安裝此處就略過(不會安裝的直接百度下就歐克了!),直接講述dhcp基於不同網段的簡單配置。
1.安裝后切換到/etc/dhcp目錄下,然后Vim dhcp.conf 可以看到這個里面沒有dhcp的配置文件,按照里面的說明到/usr/share/doc 目錄下找到dhcp-4.1.1(版本不同版dhcp-****這個也就不同)進入這個目錄里面可以看到有很多的文件,找到dhcpd.conf.sample這個文件,然后cp dhcpd.conf.sample /etc/dhcp
2.cd /etc/dhcp 切換到dhcp目錄下,ls后看dhcp的配置文件 vim dhcpd.conf 可以看到如下東東:
# dhcpd.conf # # Sample configuration file for ISC dhcpd #
# option definitions common to all supported networks...
option domain-name "example.org";
option domain-name-servers ns1.example.org, ns2.example.org;
default-lease-time 600;
max-lease-time 7200;
# Use this to enble / disable dynamic dns updates globally. #ddns-update-style none;
# If this DHCP server is the official DHCP server for the local # network, the authoritative directive should be uncommented. #authoritative;
# Use this to send dhcp log messages to a different log file (you also)
我們要用的就是沒有#注釋的語句。
3一個網卡配置多個ip: ifconfig lo:1 10.32.1.3 然后重新啟動下network :/etc/init.d/dhcpd restart
#哈哈,你kendinghui 問為什么要配置這個ip,在這里我就告訴你因為dhcp的原理里面有寫到dhcp是通過客戶端發送廣播數據包給整個物理網絡段內的所有主機,既然是通過廣播哪肯定是在統一網段的,所以它不可以配置不同網段的ip,在這里添加的10.32.1.3這個ip就是為了是使dhcp可以配置不同網段的ip的 #
4.配置dhcp文件
例如要分配10.33和10.32這兩個網段的ip並且綁定MAC。
option domain-name "example.org";
option domain-name-servers 59.69.128.8;
default-lease-time 60000;
max-lease-time 720000;
#ddns-update-style none;
#log-facility local7;
subnet 10.0.0.0 netmask 255.0.0.0 { #此處為ip地址池也即你要分配的網段#
range 10.32.1.30 10.33.44.130;
option routers 10.33.250.250; }
host fantasia{ #此處為MAC地址的綁定#
hardware ethernet 00:0c:29:ea:3e:99;
fixed-address 10.33.44.118;
}
host fantasiaa {
hardware ethernet 00:0c:29:57:68:A6;
fixed-address 10.32.1.31;
}
5.啟動dhcp服務器
(1)/etc/init.d/dhcpd start
(2) service dhcpd start
[root@localhost dhcp]# /etc/init.d/dhcpd restart
Shutting down dhcpd: [ OK ]
Starting dhcpd: [ OK ] #這說明dhcp已經啟動成功了
6.查看dhcp服務器是否工作
[root@localhost dhcp]# ps -aux |grep dhcpd
Warning: bad syntax, perhaps a bogus '-'? See /usr/share/doc/procps-3.2.8/FAQ
dhcpd 2255 0.0 3.1 22164 16200 ? Ss 20:22 0:00 /usr/sbin/dhcpd -user dhcpd -group dhcpd eth0
root 2260 0.0 0.1 4300 620 pts/0 S+ 20:24 0:00 grep dhcpd
備注:這個呢也是我剛開始弄dhcp服務器,如果有什么不對的地方的話可以評論給我。- _ -