65 lines (49 with data), 1.4 kB
#!/bin/bash
# . . . . . . netconf . . . . . . #
# programa de configuracion de la red para DNFD
# autor: niky45
# v 0.1
# vemos si la red esta configurada
echo "
comprobando si hay conexion...."
ping -c 1 www.google.es
#si funciona, salimos sin error
if [ $? == 0 ];then
exit 0
fi
echo "
parece que la red no esta activa"
#la configuramos en caso contario
CONF="/etc/network/interfaces"
NIC=`ifconfig -a |grep Ethernet |cut -c 1-6`
cat $CONF |grep $NIC
if [ $? != 0 ];then
mv $CONF "$CONF.bak"
echo "se le pediran los datos de la red:"
echo "gateway:";read GATE
echo "ip de la maquina";read LIP
echo -e "allow-hotplug $NIC" >> $CONF
echo -e "iface $NIC inet static" >> $CONF
echo -e "address $LIP" >> $CONF
echo -e "netmask 255.255.255.0" >> $CONF
NET=`echo $LIP | cut -d 1-10` ; RNET=`echo "$NET 0" |sed 's: ::g'`
echo -e "network $RNET" >> $CONF
BROAD=`echo "$NET 255" |sed 's: ::g'`
echo -e "broadcast $BROAD" >> $CONF
echo -e "gateway $GATE" >> $CONF
echo -e "dns-nameservers 208.67.222.222 8.8.8.8" >> $CONF
ifup $NIC
fi
ping -c 1 "$GATE"
if [ $? != 0 ];then
exit 1
fi
mv /etc/resolv.conf /etc/resolv.conf~
touch /etc/resolv.conf
echo -e "nameserver 208.67.222.222 \n nameserver 8.8.8.8" >> /etc/resolv.conf
ping -c 1 www.google.es
if [ $? != 0 ];then
exit 2
fi
#si todo ha funcionado, salimos con 0
exit 0