如何安装和配置 DHCP 服务器?

56 server dhcp

如何在 Ubuntu 12.04 中安装和配置 DHCP 服务器?

如果有人有,我需要一个分步教程。

小智 55

您需要做的第一件事是安装我们需要的软件包。

打开终端并输入:

sudo apt-get install isc-dhcp-server
Run Code Online (Sandbox Code Playgroud)

有两个主要的文件/etc/default/isc-dhcp-server/etc/dhcp/dhcpd.conf我们都需要进行配置,以便让我们的第一。

打开终端并使用您喜欢的文本编辑器类型:

sudo vim /etc/default/isc-dhcp-server
Run Code Online (Sandbox Code Playgroud)

你应该得到以下信息:

#Defaults for dhcp initscript
#sourced by /etc/init.d/dhcp
#installed at /etc/default/isc-dhcp-server by the maintainer scripts
#
#This is a POSIX shell fragment
#
#On what interfaces should the DHCP server (dhcpd) serve DHCP requests"
#Separate multiple interfaces with spaces, e.g. “eth0 eth1".
INTERFACES="eth0"
Run Code Online (Sandbox Code Playgroud)

将上面的eth0替换为您希望服务器租用地址的网络接口的名称。进入下一个文件。

打开终端并输入:

sudo vim /etc/dhcp/dhcpd.conf
Run Code Online (Sandbox Code Playgroud)

这应该给你下面的输出。

#
#Sample configuration file for ISC dhcpd for Debian
#
#Attention: If /etc/ltsp/dhcpd.conf exists, that will be used as
#configuration file instead of this file.
#
#
....
option domain-name “example.org”;
option domain-name-servers ns1.example.org, ns2.example.org;
option domain-name “comtech.com”;
default-lease-time 600;
max-lease-time 7200;
log-facility local7;
subnet 10.0.0.0 netmask 255.255.255.0 {
range 10.0.0.150 10.0.0.253;
option routers 10.0.0.2;
option subnet-mask 255.255.255.0;
option broadcast-address 10.0.0.254;
option domain-name-servers 10.0.0.1, 10.0.0.2;
option ntp-servers 10.0.0.1;
option netbios-name-servers 10.0.0.1;
option netbios-node-type 8;
 ......
}
Run Code Online (Sandbox Code Playgroud)

这需要稍微解释一下。

  1. 根据您的网络要求调整您的设置。
  2. 选项域名是您的 dns 区域名称。例如,我的设置为 comtech.com。
  3. 范围应该是您希望服务器分配给客户端的 IP 地址范围。

现在键入以下命令重新启动 dhcp 服务:

sudo service isc-dhcp-server restart
Run Code Online (Sandbox Code Playgroud)

就是这样!!您的 dhcp 服务器应该正在运行,但最好检查一下。打开终端并输入:

sudo netstat -uap
Run Code Online (Sandbox Code Playgroud)

它会告诉你类似如下(寻找dhcpdnmbdnamed):

Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address           Foreign Address State PID/Program name
udp        0      0 10.0.0.255:netbios-dgm  *:*                   1016/nmbd
udp        0      0 10.0.0.255:netbios-ns   *:*                   1016/nmbd
udp        0      0 *:bootps                *:*                   4525/dhcpd
udp        0      0 *:netbios-dgm           *:*                   1016/nmbd
udp        0      0 *:netbios-ns            *:*                   1016/nmbd
udp        0      0 chris-desktop:domain    *:*                   1273/named
udp        0      0 chris-desktop.lo:domain *:*                   1273/named
udp        0      0 chris-deskt:netbios-dgm *:*                   1016/nmbd
udp        0      0 chris-deskto:netbios-ns *:*                   1016/nmbd
udp6       0      0 [::]:domain             [::]:*                1273/named
Run Code Online (Sandbox Code Playgroud)


小智 5

接受的答案中可以包含其他内容

  1. 在启动 isc-dhcp-server 服务之前分配静态 IP。

  2. 您可以通过在特定子网内以以下格式添加 MAC id 来为打印机和 linux 机器等设备保留 IP。

    ------
    host bla1 { 
            hardware ethernet DD:GH:DF:E5:F7:D7;
            fixed-address 10.0.0.10;
    }
    ----
    
    Run Code Online (Sandbox Code Playgroud)

    dhcp3-server 社区维基

    Ubuntu DHCP 服务器