修改內網ip,dns,密碼腳本

#!/bin/bash
#author  : falconhero

#qq      :40594324
#version :1.1
#date    :2012-05-29
#This script for  initial eth1,dns,password ,upload information of system to supporting platform
#本腳本用於更新內網網卡,根據地域不同選擇不同dns,修改密碼,
RED='\E[1;31m'
GRN='\E[1;32m'
YEL='\E[1;33m'
MAG='\E[1;35m'
RES='\E[0m'
#initial ifconfig eth1
echo -e "${RED}now set up eth1${RES}"
LAST=`ifconfig |grep "inet addr"|sed -n 1p|awk -F '[. ]' '{print $15}'`
echo -e "${RED}ifconfig eth0 or em0 the last num is:${LAST}${RES}"
#centos 5
if [ -f /etc/sysconfig/network-scripts/ifcfg-eth1  ]
    then
    sed -i '/^BOOTPROTO/ s/.*//g' /etc/sysconfig/network-scripts/ifcfg-eth1
    sed -i '/^ONBOOT/ s/no/yes/g' /etc/sysconfig/network-scripts/ifcfg-eth1
    sed -i '/^IPADDR/ s/.*//g' /etc/sysconfig/network-scripts/ifcfg-eth1
    sed -i '/NETMASK/ s/.*//g' /etc/sysconfig/network-scripts/ifcfg-eth1
    cat  >>/etc/sysconfig/network-scripts/ifcfg-eth1<<EOF
IPADDR=192.168.1.${LAST}
NETMASK=255.255.255.0
EOF
    ifdown eth1
    ifup eth1
    ifconfig
    echo -e "check ifconfig"
    echo -e "${YEL}now eth1 start${RES}"
fi
#centos 6.2,some mechine use eth1
if [ -f /etc/sysconfig/network-scripts/ifcfg-em2  ]
    then
    sed -i '/^BOOTPROTO/ s/.*//g' /etc/sysconfig/network-scripts/ifcfg-em2
    sed -i '/^ONBOOT/ s/no/yes/g' /etc/sysconfig/network-scripts/ifcfg-em2
    sed -i '/^IPADDR/ s/.*//g' /etc/sysconfig/network-scripts/ifcfg-em2
    sed -i '/NETMASK/ s/.*//g' /etc/sysconfig/network-scripts/ifcfg-em2
    cat  >>/etc/sysconfig/network-scripts/ifcfg-em2<<EOF
IPADDR=192.168.1.$LAST
NETMASK=255.255.255.0
EOF
    ifdown em2
    ifup em2
    ifconfig
    echo -e "check ifconfig"
    echo -e "${YEL}now em2 start${RES}"
fi

#change dns

#change dns
function normal()
{
cat > /etc/resolv.conf <<EOF
nameserver 8.8.8.8
nameserver 8.8.4.4
EOF
}
function taiwan()
{
cat > /etc/resolv.conf <<EOF
nameserver 168.95.1.1
nameserver 8.8.8.8
EOF
}
function American()
{
cat > /etc/resolv.conf <<EOF
nameserver 8.8.8.8
nameserver 4.2.2.2
EOF
}
function tailland()
{
cat > /etc/resolv.conf <<EOF
nameserver 203.146.237.237
nameserver 203.146.237.222
EOF
}
function yinni()
{
cat > /etc/resolv.conf <<EOF
nameserver  202.158.3.7
nameserver  202.158.3.6
EOF
}
function china_sanjie()
{
cat > /etc/resolv.conf <<EOF
nameserver 218.2.135.1
nameserver 221.228.255.1
EOF
}
function china_shanghai()
{
cat > /etc/resolv.conf <<EOF
nameserver 202.96.209.5
nameserver 210.22.70.3
EOF
}
echo -e "${RED}NOW ,choose dns for your country${RES}"
echo -e "1) normal"
echo -e "2) taiwan"
echo -e "3) American"
echo -e "4) tailand"
echo -e "5) yinni"
echo -e "6) china_sanjie"
echo -e "7) china_shanghai"
echo -e "if you choose other,default is normal dns:8.8.8.8 and 8.8.4.4"
read n
case $n in
    1)  normal
        ;;
    2)  taiwan
        ;;
    3)  American
        ;;
    4)  tailland
        ;;
    5)  yinni
        ;;
    6)  china_sanjie
        ;;
    7)  china_shanghai
        ;;
    *)  normal
        ;;
esac
#change password
echo -e  "${RED}now ,change password ,please input password and check it${RES}"
read P
echo -e "$P"|passwd --stdin root && history -c

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章