shell脚本案例

作者:行癫(盗版必究) ------ ## 一:脚本案例 #### 1.配置静态IP案例 ```shell #!/bin/bash # This script configures a static IP address on CentOS 7 # Define variables for the IP address, netmask, gateway, and DNS servers IP_ADDRESS=192.168.1.100 NETMASK=255.255.255.0 GATEWAY=192.168.1.1 DNS_SERVERS="8.8.8.8 114.114.114.114" # Backup the original network configuration file cp /etc/sysconfig/network-scripts/ifcfg-ens33 /etc/sysconfig/network-scripts/ifcfg-ens33.bak # Modify the network configuration file with the static IP address, netmask, gateway, and DNS servers cat << EOF > /etc/sysconfig/network-scripts/ifcfg-ens33 TYPE=Ethernet BOOTPROTO=none NAME=ens33 DEVICE=ens33 ONBOOT=yes IPADDR=$IP_ADDRESS NETMASK=$NETMASK GATEWAY=$GATEWAY DNS1=${DNS_SERVERS%% *} DNS2=${DNS_SERVERS##* } EOF # Restart the network service to apply the changes systemctl restart network # Display the new network configuration ip addr show ens33 ``` centos stream 9 ``` ```