网络配置
静态指定
动态获取: bootp:boot protocol MAC与IP一一静态对应
dhcp:增强的bootp,动态
DHCP: (Dynamic Host Configuration Protocol)
动态主机配置协议
局域网协议,UDP协议
主要用途:
用于内部网络和网络服务供应商自动分配IP地址给用户
用于内部网络管理员作为对所有电脑作集中管理的手段
使用场景
自动化安装系统
解决IPV4资源不足问题
续租
同网段多DHCP服务(广播机制)
DHCP服务必须基于本地
先到先得的原则
相关协议
Arp
rarp
跨网段
RFC 1542 Compliant Routers
dhcrelay: 中继代理
Linux DHCP协议的实现程序:dhcp, dnsmasq(dhcp,dns)
Dhcp Server
/usr/sbin/dhcpd
/etc/dhcp/dhcpd.conf--> /etc/rc.d/init.d/dhcpd
/etc/dhcp/dhcpd6.conf--> /etc/rc.d/init.d/dhcpd6
/usr/sbin/dhcrelay
/etc/rc.d/init.d/dhcrelay
dhcp server:67/udp
dhcp client: 68/udp
dhcpv6 client:546/udp
Dhcp client
dhclient
自动获取的IP信息:/var/lib/dhclient
/etc/dhcp/dhcpd.conf:
帮助参考:man 5 dhcpd.conf
全局配置
subnet {
...
}
host {
}
地址分配记录
/var/lib/dhcpd/dhcpd.leases
option domain-name "magedu.com";
option domain-name-servers 192.168.0.1,8.8.8.8;
default-lease-time 86400;
max-lease-time 86400;
subnet 192.168.100.0 netmask 255.255.255.0 {
range 192.168.100.1 192.168.100.200;
option routers 192.168.100.1;
}
yum install dhcp
rpm -ql dhcp //找到这两个
/etc/dhcp/dhcpd.conf
/usr/share/doc/dhcp-4.2.5/dhcpd.conf.example
cp /usr/share/doc/dhcp-4.2.5/dhcpd.conf.example /etc/dhcp/dhcpd.conf //因为/etc/dhcp/dhcpd.conf是空的
编写/etc/dhcp/dhcpd.conf文件
[root@centos7 ~]#cat /etc/dhcp/dhcpd.conf
option domain-name "zhangqifei.com";
option domain-name-servers 114.114.114.114,8.8.8.8; //DNS解析
option routers 192.168.109.1;//全局默认网关
default-lease-time 84600; //有效期
max-lease-time 84600; //特殊要求最大有效期
log-facility local7;
subnet 192.168.109.0 netmask 255.255.255.0 { //网段
range 192.168.109.100 192.168.109.200; //分配ip范围 如果这里写网关,就是这些范围ip,外面的网关是全局的这里不设置网关会是全局网关
filename "pxelinux.0";/文件名网络中启动程序的文件名
next-server 192.168.100.100;(tftp)//程序的文件名地址
}
host fantasia { //绑定mac地址,分配默认ip
hardware ethernet 08:00:07:26:c0:a5;
fixed-address 192.168.109.101;
这里网关和DNS都可以单独设置
}
启动服务 systemctl start dhcpd
查看端口 ss -ntlup //服务器端udp67端口,客户端udp68端口
查看网关 route -n
查看DNS cat /etc/resolv.conf
dhcp数据库 /var/lib/dhcpd/dhcpd.leases
[root@centos7 ~]#cat /var/lib/dhcpd/dhcpd.leases //发放地址的
#lease 192.168.109.100 {
starts 6 2018/01/13 06:41:45;
ends 0 2018/01/14 06:11:45;
tstp 0 2018/01/14 06:11:45;
cltt 6 2018/01/13 06:41:45;
binding state active;
next binding state free;
rewind binding state free;
hardware ethernet 00:0c:29:12:6c:bc;
}
[root@centos7 ~]#cat /var/lib/dhclient/dhclient-eth0.leases //接受地址的数据库 可以看到从哪里获取的多有信息
其它配置选项: filename: 指明引导文件名称 next-server:提供引导文件的服务器IP地址 示例: filename “pxelinux.0”; next-server 192.168.100.100;(tftp) 检查语法 service dhcpd configtest(centos6)