Sunday, January 31, 2010

Simple Bash Script

################
#!/bin/sh #
#Script Adduser#
################

echo -n “Insert Username = “;
read name
echo -n “Insert yourname = “;
read namacomplete

echo “Add User”
/usr/sbin/useradd -c”$namacomplete” $name
echo “Insert Password”
/usr/bin/passwd $name

———————–
#######################
#!/bin/sh #
#171207 #
#Script Add IP Address#
#######################

echo “Example Interface = eth0″;
echo -n “Interface = “;
read interface
echo -n “Add IP Address = “;
read ip
echo -n “Subnetmask = “;
read subnetmask
echo -n “Default Gateway = “;
read gateway
echo -n “DNS Server = “;
read dns

echo “Add IP Address”;
/sbin/ifconfig -a $interface $ip $netmask

echo “Add Default Gateway”;
/sbin/route add default gw $gateway

echo “Add DNS Server”;
echo “nameserver $dns” > /etc/resolv.conf

——————————
##############################
#!/bin/sh #
#171207 #
#Script Add Virtual Interface#
##############################

echo “Example Interface Virtual = eth0:1″;
echo -n “Interface Virtual= “;
read interface
echo -n “Insert IP Address = “;
read ip
echo -n “Subnetmask = “;
read subnetmask

echo “Add Interface Virtual”
/bin/touch /etc/sysconfig/network-scripts/ifcfg-$interface
echo “DEVICE=$interface” >> /etc/sysconfig/network-scripts/ifcfg-$interface
echo “ONBOOT=yes” >> /etc/sysconfig/network-scripts/ifcfg-$interface
echo “BOOTPROTO=static” >> /etc/sysconfig/network-scripts/ifcfg-$interface
echo “IPADDR=$ip” >> /etc/sysconfig/network-scripts/ifcfg-$interface
echo “NETMASK=$subnetmask” >> /etc/sysconfig/network-scripts/ifcfg-$interface

echo “Restart Service Network”;
/etc/init.d/network restart

———————————–
###################################
#!/bin/sh #
#171207 #
#Script Transparant Proxy #
###################################

echo -n “Insert source ‘IP/NETMASK’ =”;
read source
echo -n “Insert Destination ‘IP/NETMASK’ =”;
read destination
echo -n “Insert Protocol =”;
read protocol
echo -n “Insert Destination Port =”;
read dport
echo -n “Insert Redirect Port =”;
read redirect

echo “Create redirect rule”

/sbin/iptables -t nat -I PREROUTING -s $source -d $destination -p $protocol –dport $dport -j REDIRECT –to-port $redirect
/sbin/iptables -t nat -I POSTROUTING -s $source -o etho -j MASQUERADE

No comments:

Post a Comment