In the course of learning DHCP, we will certainly be exposed to configuration-related content. You will also learn content related to Linux. Many friends also found that dhcpd applications are involved in Linux DHCP configuration. Today, we mainly talk about the use of DHCP and dhcpd packages in Linux. So the test environment: RH linux 9.0 uses the common dhcpd package in linux. The latest version of dhcp3.0.5: download.
1. install the software: Install the/tmp directory first.
- # Cd/tmp
- # Gunzip dhcp-3.0.5.tar.gz
- # Tar xvf after the dhcp-3.0.5.tar is unlocked, you will see a new sub-directory dhcp-3.0.5 under the Directory
- # Cd dhcp-3.0.5 // enter this subdirectory
- # Configure
- # Make
- # Make install dhcp
2. Configuration
- The most important configuration work of the dhcp service is to configure/etc/dhcpd. conf and paste the configuration of the local machine.
- /Etc/dhcpd. conf:
- Default-lease-time 1296000;
- # Maximum IP address expiration time
- Max-lease-time 4000000;
- Option subnet-mask limit 255.0;
- # Subnet Mask
- Option broadcast-address 192.168.0.255;
- # Broadcast address of the Network
- Option routers 192.168.0.254;
- # Gateway address
- Option domain-name-servers 211.151.48.59, 211.151.48.47;
- # Domain name resolution address
- Ddns-update-style ad-hoc;
- Subnet 192.168.0.0 netmask 255.255.255.0 {
- # Define the IP address pool content
- Range 192.168.0.100 192.168.0.240;
- # The IP address range is 100-240, with a total of 140 IP addresses.
- }
- # You can also specify an IP address based on the MAC address as follows:
- # Host Jephe {hardware ethernet 00: a0: c9: a6: 96: 33; fixed-address 192.168.1.12 ;}
The dhcpd. conf file has been configured.
3. Start the service
- #dhcpd
That is, it can be started in command line mode.
Add the command to the startup.
Edit or create the/etc/rc. d/init. d/dhcpd file and write the following content:
- #vi /etc/init.d/dhcpd
- . /etc/rc.d/init.d/functions
- . /etc/sysconfig/network
-
- # Check that networking is up.
- [ ${NETWORKING} = "no" ] && exit 0
- [ -f /usr/sbin/dhcpd ] || exit 0
- [ -f /etc/dhcpd.conf ] || exit 0
-
- RETVAL=0
- # See how we were called.
- case "$1" in
- start)
-
- # Start daemons.
- echo -n "Starting dhcpd: "
- daemon /usr/sbin/dhcpd eth1
- RETVAL=$?
- echo
- [ $RETVAL -eq 0 ] && touch /var/lock/subsys/dhcpd
- ;;
-
- stop)
- # Stop daemons.
- echo -n "Shutting down dhcpd: "
- killproc dhcpd
- RETVAL=$?
- echo
- [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/dhcpd
- ;;
-
- restart|reload)
- $0 stop
- $0 start
- RETVAL=$?
- ;;
-
- status)
- status dhcpd
- RETVAL=$?
- ;;
-
- *)
- echo "Usage: dhcpd {start|stop|restart|status}"
- exit 1
- esac
- exit $RETVAL
The daemon/usr/sbin/dhcpd eth0 clause specifies that the machine in the IP segment of the NIC needs to be parsed.
If the second Nic is set to: eth1
Start and Stop using service commands
- #service dhcpd start|stop|restart
If no error is returned, the configuration file is correct.
Add to the startup service:
- # Chkconfig -- add dhcpd
- # Chkconfig -- level 2345 dhcpd on
- # Chkconfig -- list dhcpd
- # Dhcpd 0: Disable 1: Disable 2: Enable 3: Enable 4: Enable 5: Enable 6: Disable
The configuration is complete!