1 #!/bin/bash 2 #描述: 基于RHEL7¢os7的初始化配置 3 4 #读取用户输入的ip 5 read -p "输入你当前Linux的IP地址:" LAST 6 7 #截取网卡名称 8 ETH=` ifconfig | head -1 | awk -F ":" ‘{print $1}‘` 9 10 #截取ip地址的前三位 + ‘2‘ 作为网关地址 11 GATE="`echo $LAST | awk -F "." ‘{print $1"."$2"."$3"."}‘`2" 12 13 #截取ip的最后一位 作为主机名 14 END=`echo $LAST | awk -F "." ‘{print $NF}‘` 15 16 #修改网卡配置信息 17 cat > /etc/sysconfig/network-scripts/ifcfg-$ETH <<EOF 18 TYPE=Ethernet 19 BOOTPROTO=static 20 NAME=$ETH 21 DEVICE=$ETH 22 IPADDR="$LAST" 23 GATEWAY=$GATE 24 ONBOOT=yes 25 DNS1=202.96.128.166 26 EOF 27 28 #更改主机用户名称 29 hostnamectl --static set-hostname server-$END 30 31 #配置本地镜像yum源 32 mkdir /tmp/yum.bak 33 mkdir /iso 34 chmod u+x /etc/rc.d/rc.local 35 echo "mount /dev/sr0 /iso" >> /etc/rc.d/rc.local 36 mv /etc/yum.repos.d/*.repo /tmp/yum.bak 37 touch /etc/yum.repos.d/base.repo 38 39 cat > /etc/yum.repos.d/base.repo << EOF 40 [base] 41 name=base 42 baseurl=file:///iso 43 enabled=1 44 gpgcheck=0 45 EOF 46 47 48 cat > /etc/selinux/config << EOF 49 SELINUX=disabled 50 SELINUXTYPE=targeted 51 EOF 52 53 iptables -F 54 systemctl stop firewalld 55 systemctl disable firewalld 56 57 systemctl stop NetworkManager 58 systemctl disable NetworkManager 59 60 init 6
原文地址:https://www.cnblogs.com/zhoul/p/9926339.html
时间: 2024-10-10 09:03:30