Unbuntu12.04系统安装配置DHCP服务器

来源:互联网 发布:欧莱雅男士 知乎 编辑:程序博客网 时间:2024/04/30 09:49


1、DHCP服务器两种配置方法:

  地址池:指定了一个用来动态的提供给第一个访问网络的DHCP客户端的IP地址池。当DHCP客户端离开网络超过一定时间后,IP地址就会被回收到地址池以供其它DHCP客户端使用。

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

2、在ubuntu中安装DHCP服务

  sudo apt-getinstall dhcp3-server

  完成安装了。

3、配置DHCP服务器

  如果你的Ubuntu服务器上用友2块网卡,你需要选择一块网卡用来监听DHCP服务。默认监听的是eth0。可以通过编辑 /etc/default/isc-dhcp-server来改变监听的网卡。

sudo vi /etc/default/isc-dhcp-server

  

#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=“etho”

  INTERFACES=”eth0″

  使用下面这行替代它

  INTERFACES=”eth1″

  保存并退出。

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

  sudo cp/etc/dhcp/dhcpd.conf  /etc/dhcp/dhcpd.conf.back

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

  sudo vi/etc/dhcp/dhcpd.conf

  使用地址池的方法

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

ddns-update-style none; #option definitions common to all supported networks… option domain-name-servers ns1.example.org, ns2.example.org; option domain-name “yourdomainname.com”; 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. #subnet10.152.187.0 netmask 255.255.255.0 { #} #This is a very basic subnet declaration. 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; }

  保存并退出文件

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

  重启dhcp服务器

  sudo service isc-dhcp-server restart

  配置Ubuntu的DHCP客户端

  如果你想配置另一台ubuntu机子为DHCP客户机,使用以下步骤。打开/etc/network/interface文件

  sudo vi/etc/network/interfaces

  进行如下配置,这里为etho网卡设置动态获取ip:

 auto lo eth0 iface eth0 inet dhcp iface lo inet loopback

  保存并退出文件

  客户机配置完interfaces需重启网络服务

  sudo/etc/init.d/networking restart

  


原创粉丝点击