12
[转]centos 绑定单个ip方法和快速批量绑定多个ip方法

centos 绑定单个ip方法和快速批量绑定多个ip方法

  •  单个ip或者不连续ip的绑定

依次运行命令:
cd /etc/sysconfig/network-scripts 
cp  ifcfg-eth0 ifcfg-eth0:0
vi  ifcfg-eth0:0

打开文件后如下。

注意:每增加一个ip创建一个文件,如第二个为:cp  ifcfg-eth0 ifcfg-eth0:1
========================华丽分割线=====================================
# broadcom corporation netxtreme bcm5715 gigabit ethernet
device=eth0:0      #此处添加:0,保持和文件名一致,添加多个ip依次递增                                
bootproto=static
dhcpclass=
hwaddr=00:40:d0:xx:xx:xx   #此处为网卡mac地址切勿修改
ipaddr=85.25.xxx.xxx                  #此处修改为要添加的ip
netmask=255.255.255.128
onboot=yes

========================================================
保存退出  (保存退出简洁命令: 摁esc键 然后摁大写键 然后摁 zz)

 

然后重启网络让ip生效: service network restart

  • 批量绑定连续的ip(收集于网络)

 

在/etc/sysconfig/network-scripts下创建一个range文件

比如,vi /etc/sysconfig/network-scripts/ifcfg-eth0-range0

加入以下内容:
====================================

 

device=eth0
bootproto=static
#网卡地址要和原始的一致
hwaddr=00:40:d0:xx:xx:xx
ipaddr_start=xx.xx.xx.xx     #起始ip
ipaddr_end=xx.xx.xx.xx         #结束ip
clonenum_start=1
netmask=255.255.255.248  #子网掩码,参考下方
onboot=yes
type=ethernet

====================================

 

clonenum_start — 网络克隆接口的启始号. # eg “1″  生成的网络接口会从 eth0:1开始。

然后重启网络让ip生效: service network restart

  • netmask 子网掩码参考表:

/29 (5 usable) netmask = 255.255.255.248

/28 (13 usable) netmask = 255.255.255.240

/27 (29 usable) netmask = 255.255.255.224

/26 (61 usable) netmask = 255.255.255.192

/25 (125 usable) netmask = 255.255.255.128

/24 (253 usable) netmask = 255.255.255.0