标签:shell
#!/bin/bash
service iptables stop
chkconfig iptables off
setenforce 0
dhclient &>/dev/null
echo "dhclient is ok"
rm -rf /etc/ssh/ssh_host_*
a=`ip addr | grep eth0 |wc -l`
b=`ip addr | grep eth1 |wc -l`
if [ $a -ne 0 ] ;then
echo -e "DEVICE=eth0\nTYPE=Ethernet\nONBOOT=yes\nBOOTPROTO=static\nNAME=eth0\nIPADDR=`ifconfig eth0 | grep Bcast | awk -F ‘:‘ ‘{print $2}‘ | awk ‘{print $1}‘`\nGATEWAY=` ifconfig eth0 | grep Bcast | awk -F ‘:‘ ‘{print $2}‘ | awk ‘{print $1}‘ |awk -F ‘.‘ ‘{print $1"."$2"."$3}‘`.2\nNETMASK=255.255.255.0\nDNS1=202.106.0.20\nDNS2=180.76.76.76" > /etc/sysconfig/network-scripts/ifcfg-eth0
fi
echo "eth0:ip is `ifconfig eth0 | grep Bcast | awk -F ‘:‘ ‘{print $2}‘ | awk ‘{print $1}‘`"
if [ $b -ne 0 ] ;then
echo -e "DEVICE=eth1\nTYPE=Ethernet\nONBOOT=yes\nBOOTPROTO=static\nNAME=eth1\nIPADDR=`ifconfig eth1 | grep Bcast | awk -F ‘:‘ ‘{print $2}‘ | awk ‘{print $1}‘`\nGATEWAY=` ifconfig eth1 | grep Bcast | awk -F ‘:‘ ‘{print $2}‘ | awk ‘{print $1}‘ |awk -F ‘.‘ ‘{print $1"."$2"."$3}‘`.2\nNETMASK=255.255.255.0\nDNS1=202.106.0.20\nDNS2=180.76.76.76" > /etc/sysconfig/network-scripts/ifcfg-eth1
fi
echo "eth1:ip is `ifconfig eth1 | grep Bcast | awk -F ‘:‘ ‘{print $2}‘ | awk ‘{print $1}‘`"
service network restart &> /dev/null
chkconfig network on
echo "network.service is ok"
yum clean all &>/dev/null
yum makecache &>/dev/null
echo "yum is ok"
yum install -y vim openssh-clients wget mget &>/dev/null
echo "welcome here,thank you"
每次装虚拟机就要配置ip,长时间这样我已经累了,于是乎写了个脚本开机运行下就ok。要学会偷懒。
本文出自 “在时间里愛着你” 博客,谢绝转载!
标签:shell
原文地址:http://solongcc.blog.51cto.com/8979378/1629783