批量修改服务器ip-凯发app官方网站

凯发app官方网站-凯发k8官网下载客户端中心 | | 凯发app官方网站-凯发k8官网下载客户端中心
  • 博客访问: 377777
  • 博文数量: 112
  • 博客积分: 10
  • 博客等级: 民兵
  • 技术积分: 800
  • 用 户 组: 普通用户
  • 注册时间: 2010-12-29 13:41
文章分类

全部博文(112)

文章存档

2020年(1)

2018年(10)

2017年(27)

2016年(18)

2015年(31)

2014年(25)

相关博文
  • ·
  • ·
  • ·
  • ·
  • ·
  • ·
  • ·
  • ·
  • ·
  • ·

分类: 系统运维

2016-09-06 20:28:44



点击(此处)折叠或打开

  1. #!/bin/bash

  2. file_ip="/tmp/change_ip.csv"
  3. local_ip_config=($(/sbin/ifconfig |awk -f"\n" '$1~/^[^ ]/{print $1}'|awk '$1 !~ /lo/{print $1}'))
  4. #或ifconfig |awk -f"\n" '$1~/^[^ ]/{print $1}'|awk 'nr<=2{print $1}'
  5. ip_wan_config="/etc/sysconfig/network-scripts/ifcfg-${local_ip_config[0]}"
  6. ip_lan_config="/etc/sysconfig/network-scripts/ifcfg-${local_ip_config[1]}"
  7. old_lan_ip=$(cat ${ip_lan_config}|awk -f"=" '$1~/ipaddr/{print $2}')
  8. old_wan_ip=$(cat ${ip_wan_config}|awk -f"=" '$1~/ipaddr/{print $2}')
  9. old_wan_mask=$(awk -f"=" '$1~/netmask/{print $2}' ${ip_wan_config})
  10. old_wan_gateway=$(awk -f"=" '$1~/gateway/{print $2}' ${ip_wan_config})
  11. #
  12. echo "local ip config file is ${local_ip_config[*]}"
  13. #
  14. if [[ -f ${file_ip} ]];then
  15.    echo "${file_ip} is exist."
  16. else
  17.    echo "${file_ip} is not exist."
  18.    exit 1
  19. fi
  20. #
  21. change_ip ()
  22. {
  23. while read line
  24.   do
  25.   local new_wan_ip=`echo $line |awk -f"," '{print $3}'`
  26.   local new_wan_mask=`echo $line |awk -f"," '{print $4}'`
  27.   local new_wan_gateway=`echo $line |awk -f"," '{print $5}'`
  28.   local new_lan_ip=`echo $line |awk -f"," '{print $6}'`
  29.   local file_wan_ip=$(echo $line |awk -f"," '{print $1}')
  30.   local file_lan_ip=$(echo $line |awk -f"," '{print $2}')

  31.     if [[ "$old_wan_ip" = "$file_wan_ip" ]] && [[ "$old_lan_ip" = "$file_lan_ip" ]];then
  32.       echo "local wan ip:${old_wan_ip} is found..."
  33.       echo "local lan ip:${old_lan_ip} is found..."
  34.       sed "s/${old_wan_ip}/${new_wan_ip}/" -i ${ip_wan_config}
  35.       sed "s/${old_wan_mask}/${new_wan_mask}/" -i ${ip_wan_config}
  36.       sed "s/${old_wan_gateway}/${new_wan_gateway}/" -i ${ip_wan_config}
  37.       sed "s/${old_lan_ip}/${new_lan_ip}/" -i ${ip_lan_config}
  38.       break
  39. # /sbin/reboot
  40.     else
  41.       continue
  42.       echo "local ip is no found."
  43.     fi
  44.   done < "${file_ip}"
  45. }
  46. #
  47. if [[ -f ${ip_wan_config} ]] && [[ -f ${ip_lan_config} ]];then
  48.    echo "local ip config is ${local_ip_config[*]}"
  49.    change_ip
  50. else
  51.    echo "local ip config is not ${local_ip_config}"
  52.    exit 1
  53. fi




change_ip.csv内容如下:
old wan old lan new wan netmask gateway new lan
192.168.8.26 10.0.0.26 192.168.8.131 255.255.255.128 192.168.8.129 10.0.1.131
192.168.8.27 10.0.0.27 192.168.8.132 255.255.255.128 192.168.8.129 10.0.1.132
192.168.8.28 10.0.0.28 192.168.8.133 255.255.255.128 192.168.8.129 10.0.1.133
192.168.8.29 10.0.0.29 192.168.8.134 255.255.255.128 192.168.8.129 10.0.1.134

阅读(1413) | 评论(0) | 转发(0) |
0

上一篇:

下一篇:

给主人留下些什么吧!~~
")); function link(t){ var href= $(t).attr('href'); href ="?url=" encodeuricomponent(location.href); $(t).attr('href',href); //setcookie("returnouturl", location.href, 60, "/"); }
网站地图