How Linux sets up DHCP
Environment: RH Linux 9.0 uses DHCPD packages that are commonly used under Linux.
Latest Version dhcp3.0.5: Download
1, installation: first copy dhcp-3.0.5.tar.gz software to/tmp directory
#cd/tmp
#gunzip dhcp-3.0.5.tar.gz
#tar XVF Dhcp-3.0.5.tar, you will see a new subdirectory under this directory dhcp-3.0.5
#cd dhcp-3.0.5//Enter the subdirectory
#configure
#make
Installing DHCP #make Install
2. Configuration
The most important configuration of the DHCP service is to configure the/etc/dhcpd.conf content to now post the configuration of the local machine.
/etc/dhcpd.conf:
Default-lease-time 1296000;
#IP最长失效时间
Max-lease-time 4000000;
Option Subnet-mask 255.255.255.0;
#子网的掩码
Option broadcast-address 192.168.0.255;
#网络的广播地址
Option routers 192.168.0.254;
#网关的地址
Option Domain-name-servers 211.151.48.59,211.151.48.47;
#域名解析地址
Ddns-update-style Ad-hoc;
Subnet 192.168.0.0 netmask 255.255.255.0 {
#定义IP池的内容
Range 192.168.0.100 192.168.0.240;
#地址范围为 100-240 A total of 140 IP addresses.
}
#也可以象下面一样按MAC地址指定IP
#host jephe {hardware Ethernet 00:a0:c9:a6:96:33;fixed-address 192.168.1.12;}
Configure the dhcpd.conf file to complete.
3. Start the service
#dhcpd
That is, it can be started in the command line mode.
The following command can be added to the boot.
Edit or create a new/ETC/RC.D/INIT.D/DHCPD file to write the following:
#vi/ETC/INIT.D/DHCPD. /etc/rc.d/init.d/functions. /etc/sysconfig/network# Check that networking are up. [${networking} = "No"] && exit 0[-F/USR/SBIN/DHCPD] | | Exit 0[-f/etc/dhcpd.conf] | | Exit 0retval=0# See how we were Called.case "$" instart) # Start Daemons.echo-n "starting dhcpd:" DAEMON/USR/SBIN/DHCPD eth1retval=$?echo[$RETVAL-eq 0] && TOUCH/VAR/LOCK/SUBSYS/DHCPD; Stop) # Stop Daemons.echo-n "shutting down dhcpd:" Killproc dhcpdretval=$?echo[$RETVAL-eq 0] && rm-f/var/lock /SUBSYS/DHCPD;; restart|reload) stop$0 startretval=$?;; Status) status dhcpdretval=$?;; *) echo "USAGE:DHCPD {start|stop|restart|status}" exit 1esacexit $RETVAL |
Where DAEMON/USR/SBIN/DHCPD eth0 This sentence to specify the need for that network card in the IP segment of the machine to parse.
If the second NIC is set to: eth1
Start and stop using the service command
#service DHCPD Start|stop|restart
Error-Free Output the configuration file is correct.
To join the startup service:
#chkconfig--add DHCPD
#chkconfig--level 2345 DHCPD on
#chkconfig--list DHCPD
#dhcpd 0: Off 1: Off 2: Enable 3: Enable 4: Enable 5: Enable 6: Off
How to set up DHCP in Linux