DHCP configuration simple script

Source: Internet
Author: User
Tags dns2

Dhcp_install.sh
#! /Bin/bash
# Install Yum Source
# Configuration
# Start

# Mount-o loop/dev/CDROM/mnt
# Echo "Mount-o loop/dev/CDROM/mnt">/etc/rc. Local

Cat>/etc/yum. Repos. d/DVD. Repo <ENDF
[Autoyum]
Baseurl = file: // mnt
Gpgcheck = 0
ENDF
Yum clean all & Yum list all &>/dev/null & Echo "yum is OK"

Yum install-y DHCP &>/dev/null & Echo "DHCP is installed"

Dhcp_configure.sh
#! /Bin/bash
Read-P "Please input your IP:" ip
Read-P "Please input your netmask:" Net
Read-P "Please input your gateway:" GW
Read-P "Please input your dns1:" dns1
Read-P "Please input your dns2:" dns2

Sam =/usr/share/doc/dhcp-4.1.1/DHCPD. conf. Sample
Itr = $ (ifconfig eth0 | grep-EO '([0-9] {1, 3} \.) {2} [0-9] {1, 3}' | head-1)
Mask = $ (ifconfig eth0 | grep-EO '([0-9] {1, 3 }\.) {3} [0-9] {255}) '| grep ^)
Bor_add = $ (ifconfig eth0 | grep-EO '([0-9] {1, 3 }\.) {3} [0-9] {255}) '| grep $)
MAC = $ (ifconfig eth0 | grep-EO '([0-9 A-Z A-Z] {1, 2} :) {5} [0-9 A-Z A-Z] {1, 2 }) ')

Export Sam itr mask bor_add Mac

Cat>/etc/sysconfig/network-scripts/ifcfg-eth0 <ENDF
Device = "eth0"
Bootproto = "NONE"
Hwaddr = "00: 0C: 29: 23: 15: 40"
Onboot = "yes"
Ipaddr = $ IP
Netmask = $ Net
Gateway = $ GW
Dns1 = $ dns1
Dns2 = $ dns2
ENDF

Read-P "Please input your hostname:" HN
Cat>/etc/sysconfig/Network <ENDF
Networking = Yes
Hostname = $ HN
ENDF

Echo "$ IP $ HN">/etc/hosts &>/dev/null & Echo "hostname is OK"


\ CP-p $ SAM/etc/DHCP/DHCPD. conf &>/dev/null & Echo "copy is OK"

Cat>/etc/DHCP/DHCPD. conf <ENDF
Option domain-name "$ HN ";
Option domain-name-servers $ dns1, $ dns2;
Default-lease-time 600;
Max-lease-time 7200;

Subnet $ itr.0 netmask $ mask {
Range $ itr.100 $ itr.200;
Option routers $ GW;
Option broadcast-address $ bor_add;
Default-lease-time 600;
Max-lease-time 7200;
}

Host Fantasia {
Hardware Ethernet $ MAC;
Fixed-address $ GW;
}
ENDF
# Check whether the DHCPD syntax is correct
# DHCPD-D &>/dev/null & Echo "DHCPD grammer is OK"

Service DHCPD restart &>/dev/null & Echo "DHCPD is OK"
Chkconfig DHCPD on

DHCP configuration simple 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.