PXE批量安装Centos7,安装后脚本设置静态IP地址,应答文件

#platform=x86, AMD64, 或 Intel EM64T
#version=DEVEL
# Install OS instead of upgrade
install
# Keyboard layouts
keyboard 'us'
# Root password
rootpw --iscrypted $1$gAukPWdA$9KgCXs7IGuVPASkceRfjj0
# Use network installation
url --url="ftp://192.168.100.88/pub"
# System language
lang en_US
# System authorization information
auth  --useshadow  --passalgo=sha512
# Use graphical install
graphical
# SELinux configuration
selinux --disabled
# Do not configure the X Window System
skipx

# Firewall configuration
firewall --enabled --http --ssh --ftp
# Network information
network  --bootproto=dhcp --device=ens33
network  --bootproto=dhcp --device=ens37
# Halt after installation
halt
# System timezone
timezone Africa/Abidjan
# System bootloader configuration
bootloader --location=mbr
# Clear the Master Boot Record
zerombr
# Partition clearing information
clearpart --all --initlabel
# Disk partitioning information
part /boot --fstype="xfs" --size=500
part swap --fstype="swap" --size=2048
part / --fstype="xfs" --grow --size=1

%post --interpreter=/bin/bash
#!/bin/sh
#获取网卡名称,保存到数组a中
a=(`ifconfig | grep ^[a-z] | awk -F: '{print $1}'`)
#获取IP地址,保存到数组b中
b=(`ifconfig | grep 'inet' | sed 's/^.*inet //g' | sed 's/ *netmask.*$//g'|grep -v inet6`)
#获取子网掩码,保存到数组c中
c=(`ifconfig | grep netmask |awk '{print $4}'`)
cd /etc/sysconfig/network-scripts
#修改网卡配置文件,设置静态IP地址
for ((i=0;i<${#a[@]};i++))
  do
     if [ ${a[$i]} != "lo" ];then
       #将静态IP设置信息写入网卡配置文件
       sed -i 's/dhcp/static/' ifcfg-${a[$i]}
       sed -i '/IPADDR/d' ifcfg-${a[$i]}
       sed -i '/NETMASK/d' ifcfg-${a[$i]}
       echo "IPADDR=${b[$i]}">>ifcfg-${a[$i]}
       echo "NETMASK=${c[$i]}">>ifcfg-${a[$i]}
     fi
  done
systemctl restart network
%end

%packages
@^minimal
@core
vim
net-tools
%end
 

  • 9
    点赞
  • 16
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值