Ubuntu下DHCP服务器的配置

来源:互联网 发布:windows开源吗 编辑:程序博客网 时间:2024/05/16 19:36

http://blog.sina.com.cn/s/blog_560e310001018u9k.html


Ubuntu DHCP 服务配置

#安装DHCP服务
sudo apt-get install dhcp3-server

---------------------------------------------
#配置DHCP网卡
emacs /etc/default/isc-dhcp-server
#改为对应网卡
INTERFACES="eth0"
---------------------------------------------
(eth0 可能要设置一个IP地址做网关)


#备份当前配置
sudo cp /etc/dhcp/dhcpd.conf /etc/dhcp3/dhcpd.conf.bak
#编辑当前配置
sudo vi /etc/dhcp/dhcpd.conf #删掉所有内容
---------------------------------------------
#emacs /etc/dhcp/dhcpd.conf


ddns-update-style none;
option domain-name "tagpt.mtn";
default-lease-time 14400;
#最小租约14400秒=4小时
max-lease-time 36000;
#最大租约36000秒=10小时
subnet 192.168.2.0 netmask 255.255.255.0 {
#IP地址起止范围
range 192.168.2.77 192.168.2.240;
option subnet-mask 255.255.255.0;
#子网掩码 255.255.255.0
option routers 192.168.2.10;
#默认网关 192.168.2.10
option broadcast-address 192.168.2.255;
#广播地址 192.168.2.255
}
---------------------------------------------
不过现在还不能启动服务器,现在要先去Ubuntu的网络设置那里,把eth0的ipv4 setting修改一下,其中Method设置为Manual。Address添加一个192.168.2.0,Newmask:255.255.255.0然后Apply,并连接eth0就行。

sudo /etc/init.d/isc-dhcp-server restart

service isc-dhcp-server restart

 

客户端设置为dhcp获取IP即可







转载于:http://c2oo56.blog.sohu.com/147783065.html

一、DHCP服务器提供以下两种配置方法

1、地址池:

  这种方法指定了一个用来动态的提供给第一个访问网络的DHCP客户端的IP地址池(有时也称作区域或范围)。当DHCP客户端离开网络超过一定时间后,IP地址就会被回收到地址池以供其它DHCP客户端使用。

2、MAC地址

这种方法强制使用DHCP来区别每一块连接上网络的网卡的硬件地址,之后这块网卡每次连上网络请求DHCP服务时都为它提供这个固定的IP地址。

二、在ubuntu中安装DHCP服务

sudo apt-get install dhcp3-server

这样就完成安装了。

配置DHCP服务器

如果你的Ubuntu服务器上拥有2块网卡,你需要选择哪一块网卡用来监听DHCP服务。默认监听的是eth0。可以通过编辑/etc/default/dhcp3-server这个文件来改变这个默认值。

sudo vi /etc/default/dhcp3-server

找到这行,

INTERFACES=”eth0″

使用下面这行替代它

INTERFACES=”eth1″

保存并退出。这一步可选。

接下来你需要为/etc/dhcp3/dhcpd.conf文件创建一个备份。

cp /etc/dhcp3/dhcpd.conf /etc/dhcp3/dhcpd.conf.back

使用下面的命令编辑/etc/dhcp3/dhcpd.conf文件

sudo vi /etc/dhcp3/dhcpd.conf

使用地址池的方法

你需要修改/etc/dhcp3/dhcpd.conf这个配置文件的以下部分:

default-lease-time 600;
max-lease-time 7200;
option subnet-mask 255.255.255.0;
option broadcast-address 192.168.1.255;
option routers 192.168.1.254;
option domain-name-servers 192.168.1.1, 192.168.1.2;
option domain-name “yourdomainname.com”;
subnet 192.168.1.0 netmask 255.255.255.0 {
range 192.168.1.10 192.168.1.200;
}

保存并退出文件

这会导致DHCP服务器提供一个从192.168.1.10-192.168.1.200这个范围的IP地址给客户端。如果客户端没有请求一个租期的话,服务器会默认提供600秒的地址租期给客户端。最大的(允许的)地址租期是7200秒。

使用MAC地址的方法

使用这种方法你可以保留一个固定地址给一些或者所有机器。在下面的示例中我给server1,server2,printer1和priner2保留了固定的IP地址。

default-lease-time 600;
max-lease-time 7200;
option subnet-mask 255.255.255.0;
option broadcast-address 192.168.1.255;
option routers 192.168.1.254;
option domain-name-servers 192.168.1.1, 192.168.1.2;
option domain-name “yourdomainname.com”;
subnet 192.168.1.0 netmask 255.255.255.0 {
range 192.168.1.10 192.168.1.200;
}
host server1 {
hardware ethernet 00:1b:63:ef:db:54;
fixed-address 192.168.1.20;
}
host server2 {
hardware ethernet 00:0a:95:b4:d4:b0;
fixed-address 192.168.1.21;
}
host printer1 {
hardware ethernet 00:16:cb:aa:2a:cd;
fixed-address 192.168.1.22;
}
host printer2 {
hardware ethernet 00:0a:95:f5:8f:b3;
fixed-address 192.168.1.23;
}

不过现在还不能启动服务器,现在要先去Ubuntu的网络设置那里,把eth1的ipv4 setting修改一下,其中Method设置为Manual。Address添加一个192.168.1.0,Newmask:255.255.255.0然后Apply,并连接eth1就行。

现在你需要使用下面命令来重启dhcp服务器。

sudo /etc/init.d/dhcp3-server restart

配置Ubuntu的DHCP客户端

如果你想配置你的Ubuntu桌面为DHCP客户端,使用以下步骤。你需要打开/etc/network/interface文件

sudo vi /etc/network/interfaces

确保你的配置文件含有以下行(eth0只是一个示例)

auto lo eth0
iface eth0 inet dhcp
iface lo inet loopback

保存并退出文件

你需要使用下面的命令重启网络服务

sudo /etc/init.d/networking restart

如何找到DHCP服务器的IP地址

你需要使用下面的命令

sudo dhclient

或者

tail -n 15 /var/lib/dhcp3/dhclient.*.leases

 

关闭DHCP服务

sudo /etc/init.d/dhcp3-server stop

 






http://network.51cto.com/art/201009/223376_1.htm

安装dhcp服务器

1 服务器环境 
root@ubuntu:/# uname -a 
Linux ubuntu 2.6.22-14-generic #1 SMP Sun Oct 14 23:05:12 GMT 2007 i686 GNU/Linux 
root@ubuntu:/#

2 安装命令 
root@ubuntu:/# apt-get install dhcp3-server 
正在读取软件包列表... 完成 
正在分析软件包的依赖关系树 
Reading state information... 完成 
dhcp3-server 已经是最新的版本了。 
共升级了 0 个软件包,新安装了 0 个软件包,要卸载 0 个软件包,有 0 个软件未被升级。

3 设置dhcpd工作接口 
root@ubuntu:~# nano /etc/default/dhcp3-server 
# Defaults for dhcp initscript 
# sourced by /etc/init.d/dhcp 
# installed at /etc/default/dhcp3-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 eth1 eth2" 
INTERFACES="eth0" 
(注*上面一行指明服务器端通过哪一块网卡提供dhcp服务)

4 主要设置 
root@ubuntu:~# nano /etc/dhcp3/dhcpd.conf 
# Sample configuration file for ISC dhcpd for Debian 

# $Id: dhcpd.conf,v 1.1.1.1 2002/05/21 00:07:44 peloy Exp $ 

# The ddns-updates-style parameter controls whether or not the server will 
# attempt to do a DNS update when a lease is confirmed. We default to the 
# behavior of the version 2 packages ('none', since DHCP v2 didn't 
# have support for DDNS.) 
ddns-update-style none;

#下面是全局设置,这里定义的信息全dhcp服务器生效 
#我一般注释掉了,下面可以分不同的子网进行设置 
# option definitions common to all supported networks... 
#option domain-name "apt-get.cn"; 
#option domain-name-servers 202.103.0.117, 202.103.24.68; 
#default-lease-time 600; 
#max-lease-time 7200;

# If this DHCP server is the official DHCP server for the local 
# network, the authoritative directive should be uncommented. 
#authoritative;

# Use this to send dhcp log messages to a different log file (you also 
# have to hack syslog.conf to complete the redirection). 
log-facility local7;

# No service will be given on this subnet, but declaring it helps the 
# DHCP server to understand the network topology.

#subnet 10.152.187.0 netmask 255.255.255.0 { 
#}

# This is a very basic subnet declaration.

#subnet 10.254.239.0 netmask 255.255.255.224 { 
# range 10.254.239.10 10.254.239.20; 
# option routers rtr-239-0-1.example.org, rtr-239-0-2.example.org; 
#}

# This declaration allows BOOTP clients to get dynamic addresses, 
# which we don't really recommend.

#subnet 10.254.239.32 netmask 255.255.255.224 { 
# range dynamic-bootp 10.254.239.40 10.254.239.60; 
# option broadcast-address 10.254.239.31; 
# option routers rtr-239-32-1.example.org; 
#}

# A slightly different configuration for an internal subnet. 
#subnet设置一个子网192.168.1.0/24 
#range定义可以分配出去的地址为1.50到1.70 
#option domain-name-servers定义dns为202.103.0.117等三个,这里注意每个之间要有个逗号 
#option domain-name定义域名称 
#option routers定义网关地址 
#broadcast-address定义广播地址 
#default-lease-time默认租约时间 
#max-lease-time 最大租约时间 
(注*下面这一段是生效部分,请按照实际情况修改) 
subnet 192.168.1.0 netmask 255.255.255.0 { 
range 192.168.1.50 192.168.1.70; 
(注*上行的动态IP范围请不要与系统中已有的dhcp服务器冲突,比如无线路由器上自带的dhcp,但是也不需要把原有的关掉,只要范围不冲突就可以了,因为客户端在启动时会自动使用服务器端的dhcp所分配的地址、而不使用无线路由器上分配的) 
option domain-name-servers 202.103.0.117,202.103.24.68,202.103.150.44; 
option domain-name "apt-get.cn"; 
(注*上行的domain-name在联网系统里会起作用,所以请选择一个你肯定不会去访问的名字、即使你并不知道它是否被注册成为域名) 
option routers 192.168.1.1; 
option broadcast-address 192.168.1.255; 
default-lease-time 864000; 
max-lease-time 86400000; 
filename "pxelinux.0"; 
(注*上面这一行是要手工加的很关键的信息,实际就是启动无盘工作站网卡的方式,而其中的pxelinux.0其实是一个文件名,下文将谈到这个文件如何生成) 
}

# Hosts which require special configuration options can be listed in 
# host statements. If no address is specified, the address will be 
# allocated dynamically (if possible), but the host-specific information 
# will still come from the host declaration.

#host passacaglia { 
# hardware ethernet 0:0:c0:5d:bd:95; 
# filename "vmunix.passacaglia"; 
# server-name "toccata.fugue.com"; 
#}

# Fixed IP addresses can also be specified for hosts. These addresses 
# should not also be listed as being available for dynamic assignment. 
# Hosts for which fixed IP addresses have been specified can boot using 
# BOOTP or DHCP. Hosts for which no fixed address is specified can only 
# be booted with DHCP, unless there is an address range on the subnet 
# to which a BOOTP client is connected which has the dynamic-bootp flag 
# set. 
#host fantasia { 
# hardware ethernet 08:00:07:26:c0:a5; 
# fixed-address fantasia.fugue.com; 
#}

# You can declare a class of clients and then do address allocation 
# based on that. The example below shows a case where all clients 
# in a certain class get addresses on the 10.17.224/24 subnet, and all 
# other clients get addresses on the 10.0.29/24 subnet.

#class "foo" { 
# match if substring (option vendor-class-identifier, 0, 4) = "SUNW"; 
#}

#shared-network 224-29 { 
# subnet 10.17.224.0 netmask 255.255.255.0 { 
# option routers rtr-224.example.org; 
# } 
# subnet 10.0.29.0 netmask 255.255.255.0 { 
# option routers rtr-29.example.org; 
# } 
# pool { 
# allow members of "foo"; 
# range 10.17.224.10 10.17.224.250; 
# } 
# pool { 
# deny members of "foo"; 
# range 10.0.29.10 10.0.29.230; 
# } 
#}

不过现在还不能启动服务器,现在要先去Ubuntu的网络设置那里,把eth0的ipv4 setting修改一下,其中Method设置为Manual。Address添加一个192.168.1.0,Newmask:255.255.255.0然后Apply,并连接eth0就行。

5 启动服务器 
root@ubuntu:/# /etc/init.d/dhcp3-server start 
* Starting DHCP server dhcpd3 [ OK ] 
root@ubuntu:/#

6 查看服务是否已经正常监听 
root@ubuntu:/# netstat -aunp|grep dhcp 
udp 0 0 0.0.0.0:67 0.0.0.0:* 23011/dhcpd3 
已经在67号udp口上开始监听了



linux配置dhcp服务器时authoritative参数的作用

 

http://blog.sina.com.cn/s/blog_558090d20100zo8q.html

authoritative;
指定当一个客户端试图获得一个不是该DHCP服务器分配的IP信息,DHCP将发送一个拒绝消息,而不会等待请求超时。当请求被拒绝,客户端会重新向当前DHCP发送IP请求获得新地址。
当网络中有其他的DHCP服务器时,加上此参数可以忽略其他DHCP服务器。
可把此参数加在dhcp.conf配置文件的第一行。



另可参考:http://bbs.51cto.com/thread-21313-1.html



原创粉丝点击