Linux运维 第三阶段 (二) DHCP服务
dhcp(dynamic host configuration protocol)
前期bootp(无盘工作站)-->dhcp(引入租约lease)
续租:例如一次租期2H,当到达一半时就开始续租(2H-->1H),若服务器响应则继续续租(2H-->1H-->2H-->1H-->2H);若服务器无响应(2H-->1H-->0.5-->0.25-->0.125),共请求四次,若一直无响应,则释放地址。
若同一区域中有多个DHCP服务器,哪个服务器响应速度快客户端就用哪个DHCP服务器(广播);linux的DHCP-server分配地址是从大到小,而winodws的DHCP-server是从小到大分配地址的。
client-->DHCPDISCOVER
DHCPOFFER<--server
client-->DHCPREQUEST
DHCPACK<--server
注:以上广播进行,udp,广播包不能跨路由,不能跨网络
client-->DHCPREQUEST
DHCPACK<--server
注:以上续租,通过单播进行
upd/67port(server);udp/68port(client)
DHCP-Relay
#yum -y install dhcp
#rpm -ql dhcp
/usr/sbin/{dhcpd,dhcrelay}
/etc/rc.d/init.d/{dhcpd,dhcrelay}
/etc/dhcpd.conf(主配置文件)
/var/lib/dhcpd/dhcpd.leases(租约文件)
/usr/share/doc/dhcp-3.0.5/dhcpd.conf.sample(模板配置文件)
#cp /usr/share/doc/dhcp-3.0.5/dhcpd.conf.sample /etc/dhcpd.conf
#vim /etc/dhcpd.conf
ddns-update-style interim;
ignore client-updates;(前两行,动态dhcp参数)
subnet 192.168.0.0 netmask 255.255.255.0 {(一定要是本地网卡对应的网段)
range 192.168.0.128 192.168.0.254;(定义范围)
default-lease-time 21600;(租约期限,默认秒)
max-lease-time 43200;
host ns {(定义保留地址,ns为标识可自定义)
hardwareethernet 12:34:56:78:AB:CD;(网卡地址)
fixed-address207.175.42.254;
}
}
#service dhcpd start
#netstat -unlp(67port)
#tail /var/lib/dhcpd/dhcpd.lease
#dhclient(客户端执行,不能执行第2次)
#killall dhclient
#dhclient -d(工作在前台,可查看到动态获取地址的详细过程)
#netstat -unlp(68port)
以上是学习《马哥网络视频》做的笔记。
1、软件包:dhcp;
服务名:主程序dhcpd、中继服务dhcrelay;
端口:udp67、68、546、547;
配置文件:/etc/dhcp/dhcpd.conf 主配置文件
/etc/sysconfig/dhcrelay 中继配置文件
/usr/share/doc/dhcp*/dhcpd.conf.sample 主配置文件模板
2、搭建DHCP
服务端:#yum -y install dhcp
#cp /usr/share/doc/dhcp*/dhcpd.conf.sample /etc/dhcp/dhcpd.conf
#vi /etc/dhcp/dhcpd.conf 删除多余配置,保留一个subnet区域
subnet 192.168.1.0 netmask 255.255.255.0 {
range 192.168.1.10 192.168.1.100;
option routers 192.168.1.2;
option subnet-mask 255.255.255.0;
option domain-name-servers 192.168.1.2;
default-lease-time 21600;
max-lease-time 23200;
}
客户端:#vi /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
ONBOOT=yes
BOOTPROTO=dhcp
#service dhcpd restart
3、搭建DHCP中继服务:
服务端:#yum -y install dhcp
#cp /usr/share/doc/dhcp*/dhcpd.conf.sample /etc/dhcp/dhcpd.conf
#vi /etc/dhcp/dhcpd.conf 删除多余配置,保留一个subnet区域
subnet 192.168.1.0 netmask 255.255.255.0 {
range 192.168.1.10 192.168.1.100;
option routers 192.168.1.2;
option subnet-mask 255.255.255.0;
option domain-name-servers 192.168.1.2;
default-lease-time 21600;
max-lease-time 23200;
}
subnet 200.200.200.0 netmask 255.255.255.0 {
range 200.200.200.10 200.200.200.100;
option routers 200.200.200.1;
option subnet-mask 255.255.255.0;
option domain-name-servers 200.200.200.1;
default-lease-time 21600;
max-lease-time 23200;
}
#service dhcpd restart
#route add default gw 192.168.1.2
中继端:
#yum -y install dhcp
#vi /etc/sysctl.conf
net.ipv4.ip_forward=1
#sysctl -p
#vi /etc/sysconfig/dhcrelay
INTERFACE="eth0 eth1"
DHCPSERVER="192.168.1.1"
#service dhcrelay restart
客户端:
#vi /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
ONBOOT=yes
BOOTPROTO=dhcp
#service network restart
注:本文由互联网收集整理(51CTO、360DOC、chinaunix、百度百科、兄弟连免费视频等)。