1.配置网络
##初始化网络(可在虚拟网络编辑器查看自己的网段)
##方法一:静态初始化
read -p "输入你当前Linux的IP地址:" ip
ETH=` ifconfig -a | head -1 | awk -F ":| " '{print $1}'`
GATE="`echo $ip | awk -F "." '{print $1"."$2"."$3"."}'`.2"
cat > /etc/sysconfig/network-scripts/ifcfg-$ETH <<EOF
TYPE=Ethernet
BOOTPROTO=static
NAME=$ETH
DEVICE=$ETH
IPADDR="$ip"
GATEWAY=$GATE
ONBOOT=yes
DNS1=8.8.8.8
EOF
##方法2:dhcp分配
cat > /etc/sysconfig/network-scripts/ifcfg-$ETH <<EOFTYPE=Ethernet
BOOTPROTO=dhcp
NAME=$ETH
DEVICE=$ETH
ONBOOT=yes
EOF
2.更改主机名(设为ip号的后三位有利于日后使用)
##(RHEL6) cat > /etc/sysconfig/network <<EOF NETWORKING=yes HOSTNAME=server-123 EOF ##(RHEL7) hostnamectl --static set-hostname server-123
3.关闭防火墙
##关闭防火墙(RHEL6)
iptables -t filter -F
iptables -t nat -F
service iptables save
service iptables stop
chkconfig iptables off
chkconfig ip6tables off
chkconfig ip6tables off
##关闭防火墙(RHEL7)
iptables -t filter -F
iptables -t nat -F
systemctl save iptables
systemctl stop iptables
systemctl disabled iptables
sed -ir '/SELINUX/{s/enforcing/disabled/}' /etc/selinux/config
4.配置yum源
##将sr0永久性挂载 mkdir /iso chmod u+x /etc/rc.d/rc.local echo "mount /dev/sr0 /iso" >> /etc/rc.d/rc.local ##配置yum源 touch /etc/yum.repos.d/base.repo cat > /etc/yum.repos.d/base.repo << EOF [base] name=mybase baseurl=file:///iso/ enabled=1 gpgcheck=0 EOF
5.重启虚拟机
init 6
总结:将适用于自己RHEL/CENTOS (6,7)版本的脚本代码复制执行即可