虚拟机初始配置

[root@localhost ~]# cat init.sh
#!/bin/bash

# 安装必要的软件包
yum -y install wget vim net-tools telnet
ip=$(ifconfig ens33 |awk '/inet /' | awk '{print $2}') #获取本机服务的ip
gateway=$(ip route |grep default |awk '{print $3}') #获取本机的网关
# 停止和禁用防火墙
systemctl stop firewalld
systemctl disable firewalld

# 修改SELinux配置
sed -i 's/enforcing/disabled/' /etc/selinux/config

# 修改网络配置
sed -i -e 's/dhcp/static/' -e '7,11d' /etc/sysconfig/network-scripts/ifcfg-ens33
echo "IPADDR=$ip" >> /etc/sysconfig/network-scripts/ifcfg-ens33
echo "NETMASK=255.255.255.0" >> /etc/sysconfig/network-scripts/ifcfg-ens33
echo "GATEWAY=$gateway" >> /etc/sysconfig/network-scripts/ifcfg-ens33
echo "DNS1=8.8.8.8" >> /etc/sysconfig/network-scripts/ifcfg-ens33

# 重启网络
systemctl restart network

你可能感兴趣的:(linux)