文章标题
来源:互联网 发布:女权五姐妹事件知乎 编辑:程序博客网 时间:2024/05/24 05:34
从虚拟机模板部署虚拟机,快速解决网卡配置
#!/bin/bash#此脚本实现从ESXI新开模板之后,快速配置机器网络及MAC地址,涉及两个文件的更改#定义常量net_rule_file="/etc/udev/rules.d/70-persistent-net.rules"net_conf_file="/etc/sysconfig/network-scripts/ifcfg-eth0"netmask_conf="255.255.xxx.0"gateway_conf="192.168.xxx.xx"dns1_conf="114.xxx.xxx.114"old_mac="00:50:56:xx:F6:xx"#判断是否已正确执行过脚本,然后从文件中删除旧的MAC,更改为新的MAC地址,--eth0if (cat $net_rule_file|grep -i $old_mac) ;then new_mac_str=$(sed -n -e '/eth1/ p' $net_rule_file) #new_mac_1=${new_mac_str:64:17} new_mac=$(echo $new_mac_str| awk -F ',' {'print $4'}|awk -F '==' {'print $2'}|sed 's/\"//g') sed -i "/$old_mac/Id" $net_rule_file sed -i "s/eth1/eth0/g" $net_rule_fileelse new_mac_str=$(sed -n -e '/eth0/ p' $net_rule_file) #new_mac_1=${new_mac_str:64:17} new_mac=$(echo $new_mac_str| awk -F ',' {'print $4'}|awk -F '==' {'print $2'}|sed 's/\"//g') echo "done 70-persistent-net.rules file!"fi#===================================#将新的网络配置入写网卡文件,重启网络if (cat $net_conf_file|grep $netmask_conf) ;then echo "done /etc/sysconfig/network-scripts/ifcfg-eth0"elif [ ! -n "$1" ] ;then echo "you have not input a ip address!"else sed -i "/$old_mac/Id" $net_conf_file sed -i "s/dhcp/static/g" $net_conf_file echo "HWADDR=$new_mac" >> $net_conf_file echo "IPADDR=$1" >> $net_conf_file echo "NETMASK=$netmask_conf" >> $net_conf_file echo "GATEWAY=$gateway_conf" >> $net_conf_file echo "DNS1=$dns1_conf" >> $net_conf_file service network restartfi
0 0
- 文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题 文章标题 文章标题 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 最小二乘法与最大似然估计
- nagios的安装配置
- list 和 dict
- Maya菜单中英文对照表(一)
- linux vi 中文乱码的解决方法
- 文章标题
- 设计模式-命令模式(7)
- 41. First Missing Positive
- Unity&Shader案例篇—屏幕渐暗效果
- CentOS下搭建爬虫程序开发环境
- Connection-采用properties配置文件建立Connecton连接
- 模板模式
- Java JNI 入门篇——HelloWorld
- 谈谈malloc ()和free()