#!/bin/bash
echo -e "e[1;32;41m 您是否要使用DHCP,默认使用statice[0m"
read DHCP
echo "请输入您要设定的IP地址"
read IP
echo "请输入您要使用的DNS地址"
read DNS
echo "请输入您的网关"
read GATEWAY
echo "请输入您的子网掩码"
read NETMASK
function network_settings(){
echo "TYPE=Ethernet" > /etc/sysconfig/network-scripts/ifcfg-ens33
echo "BOOTPROTO="$A"" >> /etc/sysconfig/network-scripts/ifcfg-ens33
echo "DEFROUTE="no"" >> /etc/sysconfig/network-scripts/ifcfg-ens33
echo "PEERDNS="yes"" >> /etc/sysconfig/network-scripts/ifcfg-ens33
echo "PEERROUTES="yes"" >> /etc/sysconfig/network-scripts/ifcfg-ens33
echo "IPV4_FAILURE_FATAL="no"" >> /etc/sysconfig/network-scripts/ifcfg-ens33
echo "IPV6INIT="yes"" >> /etc/sysconfig/network-scripts/ifcfg-ens33
echo "IPV6_AUTOCONF="no"" >> /etc/sysconfig/network-scripts/ifcfg-ens33
echo "IPV6_DEFROUTE="no"" >> /etc/sysconfig/network-scripts/ifcfg-ens33
echo "IPV6_PEERDNS="no"" >> /etc/sysconfig/network-scripts/ifcfg-ens33
echo "IPV6_PEERROUTES="no"" >> /etc/sysconfig/network-scripts/ifcfg-ens33
echo "IPV6_FAILURE_FATAL="no"" >> /etc/sysconfig/network-scripts/ifcfg-ens33
echo "NAME="ens33"" >> /etc/sysconfig/network-scripts/ifcfg-ens33
echo "UUID="0e6ca219-0d2e-4000-8f17-bf7424e46595"" >> /etc/sysconfig/network-scripts/ifcfg-ens33
echo "DEVICE="ens33"" >> /etc/sysconfig/network-scripts/ifcfg-ens33
echo "ONBOOT="yes"" >> /etc/sysconfig/network-scripts/ifcfg-ens33
echo "IPADDR="$IP"" >> /etc/sysconfig/network-scripts/ifcfg-ens33
echo "GATEWAY="$GATEWAY"" >> /etc/sysconfig/network-scripts/ifcfg-ens33
echo "NETMASK="$NETMASK"" >> /etc/sysconfig/network-scripts/ifcfg-ens33
echo "DNS="$DNS"" >> /etc/sysconfig/network-scripts/ifcfg-ens33
}
if [ "$DHCP" = "DHCP" ];then
A="dhcp"
else
A="static"
fi
network_settings
echo "nameserver "$DNS"" >>/etc/resolv.conf
systemctl restart network
echo "设置成功"