欧卡2中文社区

 找回密码
 立即注册

QQ登录

只需一步,快速开始

需要三步,才能开始

只需两步,慢速开始

玩欧卡就用莱仕达V99方向盘欧卡2入门方向盘选莱仕达V9莱仕达折叠便携游戏方向盘支架欢迎地图Mod入驻
查看: 2867|回复: 1
收起左侧

[环境搭建] centos增加虚拟网卡

[复制链接]
oppo 发表于 2014-9-17 15:04 | 显示全部楼层 |阅读模式
[tex=code]#!/bin/bash

# Name:  addvip.sh
# Use:   Configure Linux(centos=6) add ip to virtual ethernet
# Usage:  bash addvip.sh
# History:
# release20140917  hean  basic function
set -x
DIR=`pwd`
CONF=$DIR/ip.conf
ETH=eth0
FLAG=0 #是否替换ETH IP,0 替换 ,1 不替换
RSYNCSERVER="10.217.13.242::hean/addvip/tmp/"
SUM=`ifconfig | grep "$ETH:" | wc -l`

PDH=`cat /etc/sinainstall.conf | awk -F '[=]' '{print $2}'`

LOGFILE=/tmp/$PDH.log

rm -f $LOGFILE && touch $LOGFILE

cd /etc/sysconfig/network-scripts/

function Separation()
{
echo -e "\n*********************************************************" >>$LOGFILE
}
#按照要求修改网卡
function ModifyEth()
{
#备份配置文件
if [ ! -d backup ]; then
  mkdir backup
  cp ifcfg-* backup/
fi
rm ifcfg-* -f
cp backup/ifcfg-* ./

cat $CONF | grep "$PDH" |sed 's/\ /\n/g' | sed "/$PDH/d" | sed '/^$/d' >$PDH.conf
while read ip; do
  if [ $SUM -eq 0 ] && [ $FLAG -eq 0 ]; then
   sed -i "s/IPADDR.*/IPADDR=$ip/g" ifcfg-$ETH
   GATEWAY=`echo $ip | awk -F '[.]' '{print $1"."$2"."$3".1"}'`
   sed -i "s/GATEWAY.*/GATEWAY=$GATEWAY/g" ifcfg-$ETH
   FLAG=1
   Separation
   cat ifcfg-$ETH >>$LOGFILE
   continue
  fi
  cp ifcfg-$ETH ifcfg-$ETH:$SUM
  sed -i "s/DEVICE.*/DEVICE=\"$ETH:$SUM\"/g" ifcfg-$ETH:$SUM
  sed -i "s/IPADDR.*/IPADDR=$ip/g" ifcfg-$ETH:$SUM
  sed -i '/GATEWAY.*/d' ifcfg-$ETH:$SUM
  Separation
  cat ifcfg-$ETH:$SUM >>$LOGFILE
  ((SUM++))
done <$PDH.conf
  
Separation
cat $PDH.conf >>$LOGFILE && rm -f $PDH.conf
}

#回滚操作
function RollBack()
{

if [ ! -d /etc/sysconfig/network-scripts/backup ]; then
  echo "you have not bond yet!"
  exit 0
fi

rm /etc/sysconfig/network-scripts/ifcfg-* -f && cp /etc/sysconfig/network-scripts/backup/ifcfg-* /etc/sysconfig/network-scripts/
echo "RollBack Finished!"
exit 0
}

if [ $# -eq 0 ]; then
ModifyEth
rsync $LOGFILE $RSYNCSERVER
fi

if [ "$1"x = "-r"x ]; then
RollBack
fi[/tex]
 楼主| oppo 发表于 2014-9-17 15:06 | 显示全部楼层
ip.conf样例
PHD11010001 10.28.228.169 10.28.228.170 10.28.228.171 

联系我们|手机版|欧卡2中国 ( 湘ICP备11020288号-1 )

GMT+8, 2024-11-25 16:55 , Processed in 0.047961 second(s), 11 queries , Redis On.

Powered by Discuz! X3.4

Copyright © 2001-2023, Tencent Cloud.

快速回复 返回顶部 返回列表