#! /Bin/bash
#
DHCP = "/mnt/Server/dhcp-3.0.5-23.el5.i386.rpm"
File =/etc/sysconfig/network-scripts/ifcfg-eth0
Grep DHCP $ File
If [$? -EQ 0]
Then
# Setting IP addresses
Read-P "Enter the IP address": IP
Read-P "Enter the subnet mask": Net
Read-P "Enter the gateway address": GA
Sed-I's/bootproto =. */bootproto = static/'$ File
Echo ipaddr = "$ IP" >>$ File
Echo gateway = $ ga >>$ File
Echo netmask = $ net >>$ File
Service Network restart
Else
# Setting IP addresses
Read-P "Enter the IP address": IP
Read-P "Enter the subnet mask": Net
Read-P "Enter the gateway address": GA
Sed-I's/^ ipaddr. * $/ipaddr = '$ ip'/' $ File
Sed-I's/^ bootproto =. */bootproto = static/'$ File
Sed-I's/^ netmask. * $/netmask = '$ net'/' $ File
Sed-I's/^ gateway. * $/gateway = '$ ga'/'$ File
Service Network restart
Fi
Rpm-q dhcp &>/dev/null
If [$? -EQ 1]
Then
Echo "attaching a cd"
If [! -D/mnt/Server]
Then
Umount/dev/CDROM &>/dev/null
Mount/dev/CDROM/mnt &>/dev/null
Echo "installing Service"
Rpm-IVH $ DHCP &>/dev/null
CP-P/usr/share/doc/dhcp-3.0.5/DHCPD. conf. Sample/etc/DHCPD. conf
Sed-I "4 S/192.168.0.0/192.168.1.0/"/etc/DHCPD. conf
Sed-I "4 S/255.255.255.0/$ net/"/etc/DHCPD. conf
Sed-I "7 S/192.168.0.1/$ Ga/"/etc/DHCPD. conf
Sed-I "12 S/192.168.1.1/$ IP/"/etc/DHCPD. conf
Sed-I "21 S/192.168.0.128/192.168.1.100/"/etc/DHCPD. conf
Sed-I "21 S/192.168.0.254/192.168.1.254/"/etc/DHCPD. conf
Service DHCPD restart
Chkconfig DHCPD on
Else
Echo "mounted"
Rpm-IVH $ DHCP &>/dev/null
CP-P/usr/share/doc/dhcp-3.0.5/DHCPD. conf. Sample/etc/DHCPD. conf
Sed-I's/192.168.0.0/192.168.1.0/'/etc/DHCPD. conf
Sed-I "4 S/255.255.255.0/$ net/"/etc/DHCPD. conf
Sed-I "7 S/192.168.0.1/$ Ga/"/etc/DHCPD. conf
Sed-I "12 S/192.168.1.1/$ IP/"/etc/DHCPD. conf
Sed-I '21 S/192.168.0.128/192.168.1.100/'/etc/DHCPD. conf
Sed-I '21 S/192.168.0.254/192.168.1.254/'/etc/DHCPD. conf
Service DHCPD restart
Chkconfig DHCPD on
Fi
Else
Echo "service installed"
Fi
This article is from the "linuxcbb" blog, please be sure to keep this source http://linuxcbb.blog.51cto.com/9434555/1559331
DHCP automation script