Network script

slackware | Κυρ, 04/08/2012 - 01:24 | 2'

#!/bin/bash

##################################################
#
# This script help to setup a Linux computer
# in your network.
# It is quite simple, but if you have any question
# you can contact with me with pm or email
# kapellakis[at]gmail[dot]com
#
# It is tested in Slackel-current kde-4.8.2
################################################### 



root=$UID;
#echo "You have ID: "$root

echo -n "Enter the interface to setup [default eth0]: "
read eth
echo -n "Insert the static lan ip: "
read ip
echo -n "Insert the default gateway: "
read gw
echo -n "Insert the primary nameserver [default 195.170.0.1]: "
read nameserver
echo -n "Insert the secondary nameserver [default 195.170.2.2]: "
read nameserver2

if [ $root != 0 ]; then

echo "You must be root."
echo "Boodbye".
exit
fi

######################################
#
# Check the values
#
######################################
if [ !$eth ]; then
echo "Default interface eth0"
eth=eth0
fi

if [ !$ip ]; then
echo "Enter a lan ip."
exit
fi

if [ !$gw ]; then
echo "Enter your gateway."
exit
fi

if [ !$nameserver ]; then
nameserver=195.170.0.1
fi

if [ !$nameserver2 ]; then
nameserver2=195.170.2.2
fi

echo "Setting up $eth..."
`ifconfig $eth $ip up`
echo "done!"

echo "Setting up route on $eth"
`route add default gw $gw $eth`
echo "done!"

echo "Setting up primary nameserver"
`echo nameserver=$nameserver>/etc/resolv.conf`
echo "done!"

echo "Setting up secondary nameserver"
`echo nameserver=$nameserver2>>/etc/resolv.conf`
echo "done!"

echo -n "Do you want to check internet connectivity? [Yes]: ";
read awnser

if [ !$awnser ]; then
echo "Aborting and exiting script"
else
echo "Sending 10 packets in google.com"
`ping -c 10 www.google.com`
fi

Δώσε αστέρια!