SentOS 7 脚本
#!/bin/bash
echo 'IP:'
read ip
echo 'HOSTNAME:'
read hn
arr=(${ip//./ })
gw="${arr[0] }.${arr[1] }.${arr[2] }.2"
#配置IP
echo "TYPE='Ethernet'
BOOTPROTO='static'
NAME='ens33'
DEVICE='ens33'
ONBOOT='yes'
IPADDR='$ip'
GATEWAY='$gw'
NETMASK='255.255.255.0'
DNS1='223.5.5.5'
DNS2='8.8.8.8'" > /etc/sysconfig/network-scripts/ifcfg-ens33
echo "NETWORKING=yes" > /etc/sysconfig/network
#配置主机名
echo "$hn" > /etc/hostname
#删除物理网卡
rm -r /etc/udev/rules.d/*
#关闭防火墙
systemctl stop firewalld
systemctl disable firewalld
#域名映射
echo "$ip $hn" >> /etc/hosts
sleep 5
#重启
reboot