[PowerShell] shell 脚本配置IP地址 →→→→→进入此内容的聊天室

来自 , 2021-03-11, 写在 PowerShell, 查看 136 次.
URL http://www.code666.cn/view/26901deb
  1. #!/bin/bash
  2. ############################配置IP脚本#####################################
  3. ############################ 初学者 #######################################
  4. fun0 () {
  5.         ipfile="/etc/sysconfig/network-scripts/ifcfg-eth0"
  6.         hwaddr=`ifconfig |grep eth0 |awk -F " " '{print $5}'`
  7.         device=`ifconfig |grep eth0 |awk -F " " '{print $1}'`
  8.         type=`ifconfig |grep eth0 |awk -F ":" '{ print $2 }'|awk -F " " '{
  9. print $1 }'`
  10.         echo "DEVICE=$device" > $ipfile
  11.         echo "HWADDR=$hwaddr" >>$ipfile
  12.         echo "ONBOOT=yes" >>$ipfile
  13.         echo "TYPE=$type" >>$ipfile
  14. }
  15. fun1 () {
  16.          echo "Enter the IP that you want to set:"
  17.         read IP
  18.         echo "Enter the netmask:"
  19.         read netmask
  20.         echo "Enter the gateway:"
  21.         read gateway
  22.         echo "Enter the DNS:"
  23.         read dns
  24. }
  25. echo "Enter the IP model you want to set (DHCP/STATIC):"
  26. read model
  27. if [ $model = "DHCP" ]
  28. then
  29.         fun0
  30.         echo "BOOTPROTO=dhcp" >>$ipfile
  31.         service network restart
  32. elif [ $model = "STATIC" ]
  33. then
  34.         fun1
  35.         fun0
  36.         echo "BOOTPROTO=none" >>$ipfile
  37.         echo "NETMASK=$netmask" >>$ipfile
  38.         echo "IPADDR=$IP" >>$ipfile
  39.         echo "GATEWAY=$gateway" >>$ipfile
  40.         echo "$dns" > /etc/resolv.conf
  41.         service network restart
  42.  
  43. else
  44.         echo "error:please enter DHCP or STATIC"
  45.         exit 0
  46. fi
  47.  
  48. //shell/1262

回复 "shell 脚本配置IP地址"

这儿你可以回复上面这条便签

captcha