首页 > 代码库 > Linux DHCP搭建
Linux DHCP搭建
DHCP
实验步骤
1、设置ip
[root@localhost ~]# vim /etc/sysconfig/network-scripts/ifcfg-eth0
# Intel Corporation 82545EM Gigabit Ethernet Controller (Copper)
DEVICE=eth0
BOOTPROTO=none
ONBOOT=yes
HWADDR=00:0c:29:5d:ed:a4
IPADDR=192.168.10.253
PREFIX=24
[root@localhost ~]# vim /etc/sysconfig/network
NETWORKING=yes
NETWORKING_IPV6=yes
HOSTNAME=dhcpser.tarena.com
GATEWAY=192.168.10.254
[root@localhost ~]# vim /etc/resolv.conf
search tarena.com
nameserver 192.168.10.254
nameserver 202.106.0.20
[root@localhost ~]# service network restart
正在关闭接口 eth0: [确定]
关闭环回接口: [确定]
弹出环回接口: [确定]
弹出界面 eth0: [确定]
[root@localhost ~]# chkconfig network on
验证
[root@localhost ~]# ifconfig eth0
eth0 Link encap:Ethernet HWaddr 00:0C:29:5D:ED:A4
inet addr:192.168.10.253 Bcast:192.168.10.255 Mask:255.255.255.0
[root@localhost ~]# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
192.168.10.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
169.254.0.0 0.0.0.0 255.255.0.0 U 0 0 0 eth0
0.0.0.0 192.168.10.254 0.0.0.0 UG 0 0 0 eth0
[root@localhost ~]# hostname
dhcpser.tarena.com
[root@localhost ~]# cat /etc/resolv.conf
search tarena.com
nameserver 192.168.10.254
nameserver 202.106.0.20
安装软件包
[root@localhost ~]# rpm -q dhcp
package dhcp is not installed
[root@localhost ~]# cd /misc/cd
[root@localhost cd]# cd Server/
[root@localhost Server]# ls *dhcp*
dhcp-3.0.5-31.el5_8.1.x86_64.rpm
[root@localhost Server]# rpm -ivh dhcp-3.0.5-31.el5_8.1.x86_64.rpm
warning: dhcp-3.0.5-31.el5_8.1.x86_64.rpm: Header V3 DSA signature: NOKEY, key ID 37017186
Preparing... ########################################### [100%]
1:dhcp ########################################### [100%]
[root@localhost Server]# rpm -q dhcp
dhcp-3.0.5-31.el5_8.1
配置文件
[root@localhost Server]# vim /etc/dhcpd.conf
1 ddns-update-style interim;
2 default-lease-time 21600;
3 max-lease-time 43200;
4 option subnet-mask 255.255.255.0;
5 option domain-name "tarena.com";
6 option domain-name-servers 202.106.0.20;
7 subnet 192.168.10.0 netmask 255.255.255.0 {
8 option routers 192.168.10.254;
9 range dynamic-bootp 192.168.10.128 192.168.10.250;
10 host ns {
11 hardware ethernet 12:34:56:78:AB:CD;
12 fixed-address 207.175.42.254;
13 }
14 }
启动服务
[root@localhost Server]# service dhcpd restart
启动 dhcpd: [确定]
[root@localhost Server]# chkconfig dhcpd on
验证
linux
[root@localhost ~]# dhclient -d eth0
Internet Systems Consortium DHCP Client V3.0.5-RedHat
Copyright 2004-2006 Internet Systems Consortium.
All rights reserved.
For info, please visit http://www.isc.org/sw/dhcp/
Listening on LPF/eth0/00:0c:29:2a:0f:73
Sending on LPF/eth0/00:0c:29:2a:0f:73
Sending on Socket/fallback
DHCPDISCOVER on eth0 to 255.255.255.255 port 67 interval 6 (xid=0x6968cd41)
DHCPOFFER from 192.168.10.253
DHCPREQUEST on eth0 to 255.255.255.255 port 67 (xid=0x6968cd41)
DHCPACK from 192.168.10.253 (xid=0x6968cd41)
bound to 192.168.10.250 -- renewal in 8883 seconds.
[root@localhost ~]# ifconfig
eth0 Link encap:Ethernet HWaddr 00:0C:29:2A:0F:73
inet addr:192.168.10.250 Bcast:192.168.10.255 Mask:255.255.255.0
[root@localhost ~]# dhclient -r eth0
Internet Systems Consortium DHCP Client V3.0.5-RedHat
Copyright 2004-2006 Internet Systems Consortium.
All rights reserved.
For info, please visit http://www.isc.org/sw/dhcp/
Listening on LPF/eth0/00:0c:29:2a:0f:73
Sending on LPF/eth0/00:0c:29:2a:0f:73
Sending on Socket/fallback
DHCPRELEASE on eth0 to 192.168.10.253 port 67 (xid=0x2007e332)
[root@localhost ~]# ifconfig
eth0 Link encap:Ethernet HWaddr 00:0C:29:2A:0F:73
inet6 addr: fe80::20c:29ff:fe2a:f73/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:318 errors:0 dropped:0 overruns:0 frame:0
TX packets:51 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:52884 (51.6 KiB) TX bytes:9935 (9.7 KiB)
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:4077 errors:0 dropped:0 overruns:0 frame:0
TX packets:4077 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:6776360 (6.4 MiB) TX bytes:6776360 (6.4 MiB)
本文出自 “一饮寂寞” 博客,转载请与作者联系!