今天所做的努力
都是在为明天积蓄力量

liunx批量配置网卡

本文最后更新于2020年8月13日,已超过1561天没有更新,如果文章内容失效,请留言反馈给我们,谢谢!
强烈向大家推荐一个好网站,【我要自学网】,教程由在校老师录制,有办公会计、平面设计、室内设计、机械设计、网页编程、影视动画等教程.....让你足不出门,都可以体验学校的专业教育!

获取使用的网卡接口

ip a

 

2.查看系统版本

cat /etc/redhat-release

 

3.执行配置脚本

wget  http://d.sshby.com/biaozhun.tar&&tar xvf biaozhun.tar&&./biaozhun

脚本源码

# !/bin/bash
touch /ip.txt
read -p "Please put in the version(1.centos5.x-6.x 2.centos7.x 3.ubuntu or debian): " ZZ
read -p "Please put in the network name: " WW
echo  "Please put in the ip ranges: "
cat> /ip.txt
CC=-1
DD=1
while read ips;
do
a1=`echo $ips|awk -F'/'+ '{ print $2 }'`
a2=`echo $ips|awk -F'/'+ '{ print $1 }'`
a3=`echo $a2 | awk -F. '{print $1"."$2"."$3}'`
a4=`echo ${a2##*.}`
let CC=$CC+1
let n=$a4+2


if [[ $ZZ -eq 1 ]];then
 cd /etc/sysconfig/network-scripts/
 if [[ $a1 -eq 24 ]];then
  touch ./ifcfg-$WW-range$CC
    let y=$n+252
    echo "DEVICE=$WW
BOOTPROTO=static
CLONENUM_START=$DD
IPADDR_START=$a3.$n
IPADDR_END=$a3.$y
PREFIX=24
ONBOOT=yes
ARPCHECK=no">>./ifcfg-$WW-range$CC
    let DD=$DD+253

 elif [[ $a1 -eq 26 ]];then
  touch ./ifcfg-$WW-range$CC
    let y=$n+60
    echo "DEVICE=$WW
BOOTPROTO=static
CLONENUM_START=$DD
IPADDR_START=$a3.$n
IPADDR_END=$a3.$y
PREFIX=26
ONBOOT=yes
ARPCHECK=no">>./ifcfg-$WW-range$CC
    let DD=$DD+61

 elif [[ $a1 -eq 27 ]];then
  touch ./ifcfg-$WW-range$CC
    let y=$n+28
    echo "DEVICE=$WW
BOOTPROTO=static
CLONENUM_START=$DD
IPADDR_START=$a3.$n
IPADDR_END=$a3.$y
PREFIX=27
ONBOOT=yes
ARPCHECK=no">>./ifcfg-$WW-range$CC
    let DD=$DD+29

 elif [[ $a1 -eq 28 ]];then
  touch ./ifcfg-$WW-range$CC
    let y=$n+12
    echo "DEVICE=$WW
BOOTPROTO=static
CLONENUM_START=$DD
IPADDR_START=$a3.$n
IPADDR_END=$a3.$y
PREFIX=28
ONBOOT=yes
ARPCHECK=no">>./ifcfg-$WW-range$CC
    let DD=$DD+13

 elif [[ $a1 -eq 29 ]];then
  touch ./ifcfg-$WW-range$CC
    let y=$n+4
    echo "DEVICE=$WW
BOOTPROTO=static
CLONENUM_START=$DD
IPADDR_START=$a3.$n
IPADDR_END=$a3.$y
PREFIX=29
ONBOOT=yes
ARPCHECK=no">>./ifcfg-$WW-range$CC
    let DD=$DD+5
 fi

elif [[ $ZZ -eq 2 ]];then
 cd /etc/sysconfig/network-scripts/
 if [[ $a1 -eq 24 ]];then
  for ((m=0;m<=252;m=m+1)) do let k=$DD let y=$n+$m echo "IPADDR$k=$a3.$y PREFIX$k=24">>./ifcfg-$WW
    let DD=$DD+1
  done

 elif [[ $a1 -eq 26 ]]; then
  for ((m=0;m<=60;m=m+1)) do let k=$DD let y=$n+$m echo "IPADDR$k=$a3.$y PREFIX$k=26">>./ifcfg-$WW
    let DD=$DD+1
  done

 elif [[ $a1 -eq 27 ]]; then
  for ((m=0;m<=28;m=m+1)) do let k=$DD let y=$n+$m echo "IPADDR$k=$a3.$y PREFIX$k=27">>./ifcfg-$WW
    let DD=$DD+1
  done

 elif [[ $a1 -eq 28 ]]; then
  for ((m=0;m<=12;m=m+1)) do let k=$DD let y=$n+$m echo "IPADDR$k=$a3.$y PREFIX$k=28">>./ifcfg-$WW
    let DD=$DD+1
  done

 elif [[ $a1 -eq 29 ]]; then
  for ((m=0;m<=4;m=m+1)) do let k=$DD let y=$n+$m echo "IPADDR$k=$a3.$y PREFIX$k=29">>./ifcfg-$WW
    let DD=$DD+1
  done
 fi

elif [[ $ZZ -eq 3 ]];then
 if [[ $a1 -eq 24 ]];then
  for ((m=0;m<=252;m=m+1)) do let k=$DD let y=$n+$m let f=$a4+1 echo "auto $WW:$k iface $WW:$k inet static address $a3.$y netmask 255.255.255.0 gateway $a3.$f ">>/etc/network/interfaces
    let DD=$DD+1
  done

 elif [[ $a1 -eq 26 ]]; then
  for ((m=0;m<=60;m=m+1)) do let k=$DD let y=$n+$m let f=$a4+1 echo "auto $WW:$k iface $WW:$k inet static address $a3.$y netmask 255.255.255.192 gateway $a3.$f ">>/etc/network/interfaces
    let DD=$DD+1
  done

 elif [[ $a1 -eq 27 ]]; then
  for ((m=0;m<=28;m=m+1)) do let k=$DD let y=$n+$m let f=$a4+1 echo "auto $WW:$k iface $WW:$k inet static address $a3.$y netmask 255.255.255.224 gateway $a3.$f ">>/etc/network/interfaces
    let DD=$DD+1
  done

 elif [[ $a1 -eq 28 ]]; then
  for ((m=0;m<=12;m=m+1)) do let k=$DD let y=$n+$m let f=$a4+1 echo "auto $WW:$k iface $WW:$k inet static address $a3.$y netmask 255.255.255.240 gateway $a3.$f ">>/etc/network/interfaces
    let DD=$DD+1
  done

 elif [[ $a1 -eq 29 ]]; then
  for ((m=0;m<=4;m=m+1)) do let k=$DD let y=$n+$m let f=$a4+1 echo "auto $WW:$k iface $WW:$k inet static address $a3.$y netmask 255.255.255.248 gateway $a3.$f ">>/etc/network/interfaces
    let DD=$DD+1
  done
 fi
fi
done < /ip.txt
  rm -rf /ip.txt

if [[ $ZZ -eq 1 ]];then
    echo "
*********************************************
The ips have been added successfully!
Please run service network  restart
*********************************************"

elif [[ $ZZ -eq 2 ]];then
    echo "
*********************************************
The ips have been added successfully!
Please run service network  restart
*********************************************"

elif [[ $ZZ -eq 3 ]];then
   echo "
*********************************************
The ips have been added successfully!
Please run /etc/init.d/networking restart
*********************************************"
fi
#end



 

输入网卡eth0信息回车然后输入ip段回车

然后按Ctrl +d

弹一下信息

 

4.重启网卡配置完成

service network  restart

linux dns配置

vi /etc/resolv.conf

search cn
nameserver 8.8.8.8

systemctl restart network
赞(0)
未经允许不得转载:如需转载,请标注内容来源流觞 » liunx批量配置网卡
分享到: 更多 (0)
强烈向大家推荐一个好网站,【我要自学网】,教程由在校老师录制,有办公会计、平面设计、室内设计、机械设计、网页编程、影视动画等教程.....让你足不出门,都可以体验学校的专业教育!
强烈向大家推荐一个好网站,【我要自学网】,教程由在校老师录制,有办公会计、平面设计、室内设计、机械设计、网页编程、影视动画等教程.....让你足不出门,都可以体验学校的专业教育!

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

今天所做的努力都是在为明天积蓄力量

联系我们关于小站