码迷,mamicode.com
首页 > 其他好文 > 详细

乌班图配置多个ip

时间:2016-07-01 23:11:21      阅读:506      评论:0      收藏:0      [点我收藏+]

标签:ubuntu   多ip   

乌班图配置多个ip

首先要创建一个脚本

vi 1.sh

脚本语言开始:

# !/bin/bash

touch /ip.txt

echo  "Please put in the ip ranges: "

cat>ip.txt

read -p "Please put in the network name: " WW

CC=-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 [[ $a1 -eq 24 ]];then

 for ((m=0;m<=252;m=m+1))

 do

    let k=253*$CC+$m

    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

  done


elif [[ $a1 -eq 26 ]]; then

 for ((m=0;m<=60;m=m+1))

 do

    let k=61*$CC+$m

    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

  done


elif [[ $a1 -eq 27 ]]; then

 for ((m=0;m<=28;m=m+1))

 do

    let k=29*$CC+$m

    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

  done


elif [[ $a1 -eq 28 ]]; then

 for ((m=0;m<=12;m=m+1))

 do

    let k=13*$CC+$m

    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

  done


elif [[ $a1 -eq 29 ]]; then

 for ((m=0;m<=4;m=m+1))

 do

    let k=5*$CC+$m

    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

  done

fi


done < ip.txt

rm -rf ip.txt

echo "*********************************************

The ips have been added successfully!

Please run "/etc/init.d/networking restart".

*********************************************"

#end

脚本语言结束

给执行权限

chmod +x 1.sh

执行:

bash 1.sh

安装服务器的ip复制进去.

(从小到大复制)

技术分享

ps:ip段就不给大家详细说明

回车后, 按Ctrl-D结束

然后重启网卡即可


暂时还不知适不适用于debian

本文出自 “李景祥” 博客,谢绝转载!

乌班图配置多个ip

标签:ubuntu   多ip   

原文地址:http://9283898.blog.51cto.com/9273898/1795000

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!