乌班图配置多个ip

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了乌班图配置多个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的主要内容,如果未能解决你的问题,请参考以下文章

乌班图的世界——ubuntu18.04设置静态ip阶段总结

乌班图中怎么安装python

Ubuntu(乌班图)服务器版的操作系统怎么配置光纤存储(IBM v3700)多路径?

乌班图16 配置nginx

VMWare虚拟机怎么安装乌班图系统

乌班图 默认环境配置方法