1、安裝配置dhcp服務器vim
一、首先設置服務器網卡ip地址服務器
修改配置文件vim /etc/sysconfig/network-scripts/ifcfg-eth0網絡
更改以下三項便可:dom
IPADDR=172.17.17.2ide
NETMASK=255.255.255.0rest
GATEWAY=172.17.17.1router
重啓網絡服務server
service network restartdns
二、查看服務器是否安裝dhcp服務ip
rpm -qa|grep dhcp
若是未安裝,則掛載系統光盤,安裝dhcp軟件包
rpm -ivh dhcp-3*
rpm -ivh dchp-devel*
yum配置好的話,能夠直接使用yum安裝,
yum install dhcp
三、修改dhcp主配置文件
dhcp主配置文件默認是空的,須要根據模板修改
cp /usr/share/doc/dhcp-3.0.5/dhcpd.conf.sample /etc/dhcpd.conf
修改內容以下:
dns-update-style none;
ignore client-updates;
#log-faulity local4;
subnet 172.17.17.0 netmask 255.255.255.0 {
option routers 172.172.17.1;
option subnet-mask 255.255.255.0;
option nis-domain "domain.org";
option domain-name "domain.org";
option domain-name-servers 202.106.0.20;
option time-offset -18000; # Eastern Standard Time
range dynamic-bootp 172.17.17.100 172.17.17.254;
default-lease-time 21600;
max-lease-time 43200;
# host ns {
# next-server marvin.redhat.com;
# hardware ethernet 12:34:56:78:AB:CD;
# fixed-address 192.168.1.22;
# }
}
subnet 192.168.1.0 netmask 255.255.255.0 {
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 202.106.0.20;
option time-offset -18000; # Eastern Standard Time
range dynamic-bootp 192.168.1.100 192.168.1.254;
default-lease-time 21600;
max-lease-time 43200;
}
subnet 192.168.2.0 netmask 255.255.255.0 {
option routers 192.168.2.1;
option subnet-mask 255.255.255.0;
option nis-domain "domain.org";
option domain-name "domain.org";
option domain-name-servers 202.106.0.20;
option time-offset -18000; # Eastern Standard Time
range dynamic-bootp 192.168.2.100 192.168.2.254;
default-lease-time 21600;
max-lease-time 43200;
}
重啓dhcp服務
service dhcpd restart
chkconfig dhcpd on
2、配置dhcp中繼
首先配置服務器IP地址
eth0:172.17.17.1/24
eth1:192.168.1.1/24
eth2:192.168.2.1/24
安裝dhcp軟件包,同dhcp服務器配置
修改中繼配置文件
/etc/sysconfig/dhcrelay
INTERFACES="eth0 eth1 eth2"
DHCPSERVERS="172.17.17.2"
開啓ip轉發功能
vim /etc/sysctl.conf
更改第一行的配置 net.ipv4.ip_forward = 1
重啓DHCP中繼服務
/etc/init.d/dhcrelay restart
chkconfig dhcrelay on
3、配置dhcp客戶端
使用setup命令
設置網卡eth0獲取IP方式爲dhcp
dhclient eth0
或者service network restat
查看網卡得到的IP地址
ifconfig eth0
eth0 Link encap:Ethernet HWaddr 00:0C:29:69:15:FE
inet addr:192.168.1.254 Bcast:192.168.1.255 Mask:255.255.255.0
inet6 addr: fe80::20c:29ff:fe69:15fe/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:9919 errors:0 dropped:0 overruns:0 frame:0
TX packets:189 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:919624 (898.0 KiB) TX bytes:22094 (21.5 KiB)
Interrupt:169 Base address:0x2000
實驗條件
dhcp 服務器使用的虛擬機的vm1網絡
中繼服務器使用的是虛擬機的vm1 vm2 和vm8網絡
dhcp客戶端使用的是虛擬機的vm2網絡
默認狀況下0表明橋接
vm1表明nat
vm8表明host-only