标签:str mount ip地址 更改 led 自己的 网络 sys 地址
#!/bin/bash ##初始化网络(可在虚拟网络编辑器查看自己的网段) ##方法一:静态初始化 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 <<EOF
TYPE=Ethernet BOOTPROTO=dhcp NAME=$ETH DEVICE=$ETH ONBOOT=yes
EOF
##更改主机名(RHEL6)
cat > /etc/sysconfig/network <<EOF
NETWORKING=yes
HOSTNAME=server-123
EOF
##更改主机名(RHEL7)
hostnamectl --static set-hostname server-123
##关闭防火墙(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
##禁用SELinux
sed -ir ‘/SELINUX/{s/enforcing/disabled/}‘ /etc/selinux/config
##将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
##适用于REHL6,RHEL7
##执行脚本后虚拟机会关机重启
init 6
标签:str mount ip地址 更改 led 自己的 网络 sys 地址
原文地址:https://www.cnblogs.com/1312862978Hg/p/9613852.html