DHCP Configurator

Publicado por Edersom 30/10/2004

[ Hits: 8.134 ]

Download dhcpd.zip




Script que ajuda na hora de Configurar  o servidor dhcp, ele está em duas versões uma com dialog e otra sem, espero que ajude alquem, pois me ajudou muito..........:)

  



Esconder código-fonte

##################################
######               COM DIALOG                       #######
##################################

#/bin/sh
#
#SCRIPT: dhcpd.sh (Versão Com Dialog)
#AUTOR: EDERSOM ANGELO DA SILVA (maxmaxine@pop.com.br)
#DATA 30/10/2004
#REV: 1.1.0p
#PLATAFORMA: Linux (Testado no Slackware 9.1)
#
#FINALIDADE: 
#   Configuração rápida do servidor dhcp 
#
#
#LISTA DE REVISÃO:
#
# 
# set -n   #Tire o comentário para verificar a sintaxe
#      #Sem executar o Script
# set -x   #Retire o comentário para depurar o script (apenas com ksh (korn shell))
#
###########################################
#### AQUI ESTAO INDICADAS AS VARIAVEIS ####
###########################################
tempfile=`tempfile 2>/dev/null` || tempfile=/tmp/temp$$
netmaskr=/tmp/net$$
bcr=/tmp/bc$$
gwr=/tmp/gw$$
dnsr=/tmp/dns$$
ranger=/tmp/ramge$$

# # # # # # # # # # # # # # # # # # # # # #
DIALOG=${DIALOG=dialog}
BACK=${BACK="Tux O Pinguim Selvagem"}
TITU=${TITU="DHCP Configurator"}

#=========================================>
trap "rm -f $tempfile" 0 1 2 5 15
trap "rm -f $netmask" 0 1 2 5 15
trap "rm -f $bc" 0 1 2 5 15
trap "rm -f $gw" 0 1 2 5 15
trap "rm -f $dns" 0 1 2 5 15

#------------------------------------------

   $DIALOG                                                                          \
   --backtitle "$BACK"                                                              \
   --title "$TITU"                                                                  \
   --inputbox                                                                       \
   "Qual a Mascara de sua rede?\nEx: 255.255.255.0" 0 0 2>$netmaskr
netmask=`cat $netmaskr`

   $DIALOG                                                                          \
   --backtitle "$BACK"                                                              \
   --title "$TITU"                                                                  \
   --inputbox                                                                       \
   "Qual o endereço de broadcast da sua rede?\nEx: 192.168.200.255" 0 0 2>$bcr
bc=`cat $bcr`

   $DIALOG                                                                          \
   --backtitle "$BACK"                                                              \
   --title "$TITU"                                                                  \
   --inputbox                                                                       \
   "Qual o Gatway padrao da sua Rede?\nEx: 192.168.200.254" 0 0 2>$gwr
gw=`cat $gwr`

   $DIALOG                                                                          \
   --backtitle "$BACK"                                                              \
   --title "$TITU"                                                                  \
   --inputbox                                                                       \
   "Especifique a faixa de IP a ser distribuida na rede\n
   No formato: IP_inicial IP_final\nEx: 192.168.200.1 192.168.200.200" 0 0 2>$ranger
range=`cat $ranger`

   $DIALOG                                                                          \
   --backtitle "$BACK"                                                              \
   --title "$TITU"                                                                  \
   --inputbox                                                                       \
   "Especifique Abaixo o(s) Servidor(es) DNS que servem sua Rede\n
   Obs: Se for mais de um número IP, separe-os por virgula e espaço\n
   Ex: 200.193.136.60, 200.203.191.8"
dns=`cat $dnsr`

echo "#ddns-update-style none;" >$tempfile
echo "default-lease-time 600;" >>$tempfile
echo "max-lease-time 7200;" >>$tempfile
echo "option subnet-mask $netmask;" >>$tempfile
echo "option broadcast-address $bc;" >>$tempfile
echo "option routers $gw;" >>$tempfile
echo "#option domain-name-servers 200.193.136.60, 200.203.191.8;" >>$tempfile
echo "option domain-name-servers $dns;" >>$tempfile
echo "option domain-name "$domain";" >>$tempfile
echo "" >>$tempfile
echo "subnet $subnet netmask $netmask {" >>$tempfile
echo "range $range;" >>$tempfile
echo "}" >>$tempfile

cat $tempfile > /etc/dhcpd.conf

   $DIALOG                                                                          \
   --backtitle "$BACK"                                                              \
   --title "PRONTO!"                                                                \
   --textbox "$tempfile" 0 0

/etc/init.d/dhcpd restart || /sbin/dhcpcd -t 10 -d eth0

   $DIALOG                                                                          \
   --backtitle "$BACK"                                                              \
   --title "PRONTO!"                                                                \
   --msgbox                                                                         \
   "Se Voce usa Slackware, e quer iniciar\n
   seu servidor durante o boot, altere o \n
   arquivo /etc/rc.d/rc.inet1.conf alterando\n
   a linha USE_DHCP[0]=\"\" (caso eth0) para =\"yes\"" 0 0



##################################
######               SEM DIALOG                       #######
##################################

#!/bin/sh
#
#SCRIPT: dhcpd.sh (Versão Sem Dialog)
#AUTOR: EDERSOM ANGELO DA SILVA (maxmaxine@pop.com.br)
#DATA 30/10/2004
#REV: 1.1.0p
#PLATAFORMA: Linux (Testado no Slackware 9.1)
#
#FINALIDADE: 
#   Configuração rápida do servidor dhcp 
#
#
#LISTA DE REVISÃO:
#
# 
# set -n   #Tire o comentário para verificar a sintaxe
#      #Sem executar o Script
# set -x   #Retire o comentário para depurar o script (apenas com ksh (korn shell))
#
###########################################
#### AQUI ESTAO INDICADAS AS VARIAVEIS ####
###########################################
tempfile=`tempfile 2>/dev/null` || tempfile=/tmp/temp$$

#=========================================>
trap "rm -f $tempfile" 0 1 2 5 15
###################################################


echo "Qual a Mascara de sua rede?"
echo "Ex: 255.255.255.0"
read netmask

echo "Qual o endereço de broadcast da sua rede?"
echo "Ex: 192.168.200.255"
read bc

echo "Qual o Gatway padrao da sua Rede?"
echo "ex: 192.168.200.254"
read gw


echo "Especifique a faixa de IP a ser distribuida na rede"
echo "No formato: IP_inicial IP_final"
echo "Ex: 192.168.200.1 192.168.200.200"
read faixa

echo "Especifique Abaixo o(s) Servidor(es) DNS que servem sua Rede"
echo "Obs: Se for mais de um número IP, separe-os por virgula e espaço"
echo "Ex: 200.193.136.60, 200.203.191.8"
read dns


echo "#ddns-update-style none;" >$tempfile
echo "default-lease-time 600;" >>$tempfile
echo "max-lease-time 7200;" >>$tempfile
echo "option subnet-mask $netmask;" >>$tempfile
echo "option broadcast-address $bc;" >>$tempfile
echo "option routers $gw;" >>$tempfile
echo "#option domain-name-servers 200.193.136.60, 200.203.191.8;" >>$tempfile
echo "option domain-name-servers $dns;" >>$tempfile
echo "#option domain-name "$domain";" >>$tempfile
echo "" >>$tempfile
echo "subnet $subnet netmask $netmask {" >>$tempfile
echo "range $faixa;" >>$tempfile
echo "}" >>$tempfile

cat $tempfile > /etc/dhcpd.conf

/etc/init.d/dhcpd restart || /sbin/dhcpcd -t 10 -d eth0
clear
echo "======================================================="
echo "=                                                     ="
echo "= Se Voce usa Slackware, e quer iniciar               ="
echo "= seu servidor durante o boot, altere o               ="
echo "= arquivo /etc/rc.d/rc.inet1.conf alterando           ="
echo "= a linha USE_DHCP[0]=\"\" (caso eth0) para =\"yes\"      ="
echo "=                                                     ="
echo "======================================================="



Scripts recomendados

Baixando e instalando o Asterisk

Script para criar emails

Adicionar usuarios em lote com senha padrao

Inserção de máquinas no banco de dados para controle interno

Backup diario rotativo MySQL + Backup semanal mantendo uma cópia local e remota


  

Comentários
[1] Comentário enviado por slack_boy em 19/11/2004 - 11:17h

Ow, seu script com dialog tem um bugão, não configura dns, mas o sem dialog funfo legal!!!!!


Contribuir com comentário




Patrocínio

Site hospedado pelo provedor RedeHost.
Linux banner
Linux banner
Linux banner

Artigos

Dicas

Tópicos

Top 10 do mês

Scripts