isc-dhcp-server --dhcp服务器
- DHCP(Dynamic Host Configuration Protocol,动态主机配置协议)通常被应用在大型的局域网络环境中,主要作用是集中的管理、分配IP地址
使网络环境中的主机动态的获得IP地址、Gateway地址、DNS服务器地址等信息,并能够提升地址的使用率。
ubuntu下安装
zw@zw-pc:apt-get install isc-dhcp-server
#DHCP的主要配置文件有两个,分别位于 /etc/default/isc-dhcp-server 和 /etc/dhcp/dhcpd.conf
#首先配置isc-dhcp-server
zw@zw-pc:cat /etc/default/isc-dhcp-server [10:18:14] # Defaults for isc-dhcp-server (sourced by /etc/init.d/isc-dhcp-server)
# Path to dhcpd's config file (default: /etc/dhcp/dhcpd.conf).
#DHCPDv4_CONF=/etc/dhcp/dhcpd.conf
#DHCPDv6_CONF=/etc/dhcp/dhcpd6.conf
# Path to dhcpd's PID file (default: /var/run/dhcpd.pid).
#DHCPDv4_PID=/var/run/dhcpd.pid
#DHCPDv6_PID=/var/run/dhcpd6.pid
# Additional options to start dhcpd with.
# Don't use options -cf or -pf here; use DHCPD_CONF/ DHCPD_PID instead
#OPTIONS=""
# On what interfaces should the DHCP server (dhcpd) serve DHCP requests?
# Separate multiple interfaces with spaces, e.g. "eth0 eth1".
INTERFACESv4=""##指定的提供dhcp的网卡 ifconfig查看
INTERFACESv6=""
#配置hdcpd.conf
zw@zw-pc:cat /etc/dhcp/dhcpd.conf [10:21:09] # dhcpd.conf
...
##配置主要在这里
# A slightly different configuration for an internal subnet.
#子网网段 和子网掩码 如果ip为192.168.5.112 c类网 则设置为 如下
subnet 192.168.5.0 netmask 255.255.255.0 {
##地址池 对外分配的ip段
range 192.168.5.113 192.168.5.123;
##dns 服务器地址
option domain-name-servers 114.114.114.114;
##dns服务器域名
# option domain-name "internal.example.org";
##分配主机的子网掩码
option subnet-mask 255.255.255.0;
##默认网关
option routers 192.168.5.1;
##广播地址
# option broadcast-address 10.5.5.31;
##默认租期时间 s
# default-lease-time 600;
##最大租期时间
# max-lease-time 7200;
}
...
#查看服务是否启动
root@localhost:~# netstat -uap
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
udp 0 0 *:bootps *:* 334/dhcpd
udp 0 0 *:49794 *:* 334/dhcpd
udp6 0 0 [::]:15098 [::]:* 334/dhcpd
root@localhost:~#