Linux系统添加绑定多IP和IP段的方法

2020年04月1日

Centos:

一、先用命令查看网卡设备名称,执行命令后会返回网卡接口信息,再看要绑定哪一个接口。

[root@localhost ]# ip link | awk 'NR%2==1' | awk '{print $2,$8,$9}' | tr -d ':'

二、用以下命令查看所有网卡接口配置文件,留意ifcfg开头的文件

/etc/sysconfig/network-scripts/

三、配置内容一般就是以下这些,这里可以设置默认DNS地址、IP4地址、IP6地址,IPADDR=这里多个地址以半角状态下的逗号,分隔开多个IP地址。

TYPE=Ethernet
BOOTPROTO=none
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
NAME=enp3s0
UUID=a007fd6d-4cc5-45b6-9a38-991a8e820eaf
DEVICE=enp3s0
ONBOOT=yes
IPADDR=10.0.0.2,10.0.0.3,10.0.0.4,10.0.0.5,10.0.0.6
PREFIX=29
GATEWAY=10.0.0.1
DNS1=8.8.8.8
DNS2=8.8.4.4
IPV6_PEERDNS=yes
IPV6_PEERROUTES=yes
BOOTPROTO=static
DEVICE=eth0
IPADDR0=IP0
NETMASK0=子网掩码
IPADDR1=IP1
NETMASK1=子网掩码
IPADDR2=IP2
NETMASK2=子网掩码
GATEWAY=网关
NM_CONTROLLED=no
ONBOOT=yes
TYPE=Ethernet
USERCTL=no
PERSISTENT_DHCLIENT=yes

四、将以下文本附加到文件的末尾并保存: NM_CONTROLLED=NO

systemctl restart network.service
或
service network restart

五、另外的方法

If you own 192.168.125.0/24, and you need to add all of the IP's in that range, we can add it like the following:

Create a file '/etc/sysconfig/network-scripts/ifcfg-eth0-range0' based on which ethernet card you are using.

vi /etc/sysconfig/network-scripts/ifcfg-eth0-range0

Add the following lines in the file:

IPADDR_START=192.168.125.3

IPADDR_END=192.168.125.254

NETMASK=255.255.255.255

CLONENUM_START=1

Here you need to replace the start IP and end IP based on what you own.

If you needed to add first 100 IP's only, you can set the first IP as 192.168.125.3 and end IP as 192.168.125.102. But make sure that any IP's in between these are not used somewhere else.

3. Once the configuration is added you can restart the network service or reboot the server. It is better to have IPMI access before doing such changes.

Debian

编辑 /etc/network/interfaces 添加上你的新IP,
假设你原有IP为 11.11.11.11,想要添加 22.22.22.22 和 33.33.33.33 新IP,按以下样例修改:

    auto lo iface lo inet loopback
    auto eth0 iface eth0 inet static address 11.11.11.11 netmask 255.255.255.0 gateway 11.11.11.1
    auto eth0:0 iface eth0:0 inet static address 22.22.22.22 netmask 255.255.255.0
    auto eth0:1 iface eth0:1 inet static address 33.33.33.33 netmask 255.255.255.0

就是只要按着顺序添加 eth0:0 , eth0:1 , eth0:X 一直加下去
修改之后,/etc/init.d/networking restart 重启网络,
另需要将新IP上线,ifup eth0:0 有多个IP,就按顺序 ifup eth0:1 ifup eth0:2 ifup eth0:3 ifup eth0:x ….


sicnature ---------------------------------------------------------------------
Your current IP address is: 18.206.187.81
Your IP address location: 美国 弗吉尼亚州阿什本amazon数据中心
Your IP address country and region: 美国 美国
Your current browser is:
Your current system is:
Original content, please indicate the source:
同福客栈论坛 | 蟒蛇科普海南乡情论坛 | JiaYu Blog
sicnature ---------------------------------------------------------------------
Welcome to reprint. Please indicate the source http://myzhenai.com.cn/post/3218.html

没有评论

发表评论

电子邮件地址不会被公开。 必填项已用*标注