DHCP automation script

Source: Internet
Author: User

#! /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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.