云服务器  >  阿里云服务器怎么实现绑定多IP地址?

阿里云服务器怎么实现绑定多IP地址?

经常有客户咨询阿里云服务器怎么实现绑定多IP地址? 阿里云服务器多个弹性公网IP是否可以绑定到一台实例上?本文通过实操的方式为大家介绍,步骤相对较多阿里云控制台步骤有所简化,如果有什么不理解可以联系我们。


配置前须知

1、参考实例规格族绑定弹性网卡和内网IP的个数限制:https://help.aliyun.com/document_detail/25378.html

阿里云服务器支持绑定的IP数(固定Ip和弹性公网IP之和):(弹性网卡-1)*单网卡私有IP+1

以hfc7实例规格“2核4G”为例可绑定的IP数为:(2-1)*6+1=7个;

注意:云服务器封顶绑定IP数21个,因为弹性公网IP一个地域仅支持申请20个。


2、配置弹性网卡:https://help.aliyun.com/document_detail/56955.html 

3、分配辅助私网IP地址:https://help.aliyun.com/document_detail/101180.htm

5、建议您服务器创建快照备份。操作流程请参见创建快照


配置流程

一、阿里云控制台配置

1、购买阿里云ECS服务器

CPU&内存:1核1 GiB

操作系统:CentOS 7.8 64位

实例规格:ecs.s6-c1m1.small

实例规格族:ecs.s6


2、创建弹性网卡绑定阿里云服务器


3、创建两个弹性公网ip绑定到,分别绑定到辅助网卡的主私网IP和辅助私网IP上。

下图已经绑定完成


二、Cenots 7服务器内部配置流程

1、查看网卡信息并没有加载eth0

[root@iZ7u1o01onqjo4Z ~]# ip a

1: lo: mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000

    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00

    inet 127.0.0.1/8 scope host lo

       valid_lft forever preferred_lft forever

    inet6 ::1/128 scope host 

       valid_lft forever preferred_lft forever

2: eth0: mtu 1500 qdisc pfifo_fast state UP group default qlen 1000

    link/ether 00:16:3e:02:3b:0b brd ff:ff:ff:ff:ff:ff

    inet 172.19.6.126/24 brd 172.19.6.255 scope global dynamic eth0

       valid_lft 315359681sec preferred_lft 315359681sec

    inet6 fe80::216:3eff:fe02:3b0b/64 scope link 

       valid_lft forever preferred_lft forever

3: eth1: mtu 1500 qdisc noop state DOWN group default qlen 1000

    link/ether 00:16:3e:26:67:2e brd ff:ff:ff:ff:ff:ff


2、参考:https://help.aliyun.com/document_detail/56955.html 配置弹性网卡

[root@iZ7u1o01onqjo4Z ~]# wget https://image-offline.oss-cn-hangzhou.aliyuncs.com/multi-nic-util/multi-nic-util-0.6.tgz

--2021-06-16 20:30:44--  https://image-offline.oss-cn-hangzhou.aliyuncs.com/multi-nic-util/multi-nic-util-0.6.tgz

正在解析主机 image-offline.oss-cn-hangzhou.aliyuncs.com (image-offline.oss-cn-hangzhou.aliyuncs.com)... 118.31.232.173

正在连接 image-offline.oss-cn-hangzhou.aliyuncs.com (image-offline.oss-cn-hangzhou.aliyuncs.com)|118.31.232.173|:443... 已连接。

已发出 HTTP 请求,正在等待回应... 200 OK

长度:9149 (8.9K) [application/x-gzip]

正在保存至: “multi-nic-util-0.6.tgz”

100%[======================================>] 9,149       --.-K/s 用时 0s      

2021-06-16 20:30:44 (52.0 MB/s) - 已保存 “multi-nic-util-0.6.tgz” [9149/9149])


[root@iZ7u1o01onqjo4Z ~]# tar -zxvf multi-nic-util-0.6.tgz

multi-nic-util-0.6/

multi-nic-util-0.6/install.sh

multi-nic-util-0.6/src/

multi-nic-util-0.6/src/dhcp/

multi-nic-util-0.6/src/dhcp/dhclient-exit-hooks

multi-nic-util-0.6/src/dhcp/dhclient-exit-hooks-for-debug

multi-nic-util-0.6/src/dhcp/dhclient-down-hooks

multi-nic-util-0.6/src/udev/

multi-nic-util-0.6/src/udev/rule_generator.functions

multi-nic-util-0.6/src/udev/write_net_rules

multi-nic-util-0.6/src/udev-rules/

multi-nic-util-0.6/src/udev-rules/61-eni.rules

multi-nic-util-0.6/src/udev-rules/75-persistent-net-generator.rules

multi-nic-util-0.6/src/udev-rules/60-net.rules

multi-nic-util-0.6/src/eni-utils/

multi-nic-util-0.6/src/eni-utils/eni-hotplug

multi-nic-util-0.6/src/eni-utils/eni-function

multi-nic-util-0.6/src/eni-utils/net.hotplug

multi-nic-util-0.6/src/eni-utils/eni-cleanup

multi-nic-util-0.6/src/eni-utils/eni-ifscan

multi-nic-util-0.6/src/eni-utils/eni-version

multi-nic-util-0.6/src/eni-utils/eni-helper

multi-nic-util-0.6/src/boot/

multi-nic-util-0.6/src/boot/eni.service

multi-nic-util-0.6/src/boot/systemd-udevd.service

multi-nic-util-0.6/src/boot/eni-service

multi-nic-util-0.6/src/lib/

multi-nic-util-0.6/src/lib/distro.sh

[root@iZ7u1o01onqjo4Z ~]# cd multi-nic-util-0.6

[root@iZ7u1o01onqjo4Z multi-nic-util-0.6]# bash install.sh

the file /lib/udev/write_net_rules NOT exist...

the file /lib/udev/rule_generator.functions NOT exist...

delete the file: /etc/udev/rules.d/70-persistent-net.rules

replace the file: /lib/udev/rules.d/60-net.rules

Created symlink from /etc/systemd/system/multi-user.target.wants/eni.service to /usr/lib/systemd/system/eni.service.

ecs_mq.service                                enabled 


3、重启网卡

[root@iZ7u1o01onqjo4Z multi-nic-util-0.6]# systemctl restart eni.service


4、测试绑定到弹性网卡主ip的弹性公网IP已经可以正常访问,说明配置没问题。

[root@iZ7u1o01onqjo4Z multi-nic-util-0.6]# ip a

1: lo: mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000

    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00

    inet 127.0.0.1/8 scope host lo

       valid_lft forever preferred_lft forever

    inet6 ::1/128 scope host 

       valid_lft forever preferred_lft forever

2: eth0: mtu 1500 qdisc pfifo_fast state UP group default qlen 1000

    link/ether 00:16:3e:02:3b:0b brd ff:ff:ff:ff:ff:ff

    inet 172.19.6.126/24 brd 172.19.6.255 scope global dynamic eth0

       valid_lft 315359623sec preferred_lft 315359623sec

    inet6 fe80::216:3eff:fe02:3b0b/64 scope link 

       valid_lft forever preferred_lft forever

3: eth1: mtu 1500 qdisc pfifo_fast state UP group default qlen 1000

    link/ether 00:16:3e:26:67:2e brd ff:ff:ff:ff:ff:ff

    inet6 fe80::216:3eff:fe26:672e/64 scope link tentative 

       valid_lft forever preferred_lft forever


5、参考分配辅助私网IP地址,配置单网卡多个内网IP

[root@iZ7u1o01onqjo4Z multi-nic-util-0.6]# cat /etc/sysconfig/network-scripts/ifcfg-eth1

DEVICE=eth1

BOOTPROTO=dhcp

ONBOOT=yes

TYPE=Ethernet

USERCTL=yes

PEERDNS=no

IPV6INIT=no

PERSISTENT_DHCLIENT=yes

HWADDR=00:16:3e:26:67:2e

DEFROUTE=no

[root@iZ7u1o01onqjo4Z multi-nic-util-0.6]# 

[root@iZ7u1o01onqjo4Z multi-nic-util-0.6]# vi /etc/sysconfig/network-scripts/ifcfg-eth1

[root@iZ7u1o01onqjo4Z multi-nic-util-0.6]# 

[root@iZ7u1o01onqjo4Z multi-nic-util-0.6]# cat /etc/sysconfig/network-scripts/ifcfg-eth1

DEVICE=eth1

BOOTPROTO=no

ONBOOT=yes

TYPE=Ethernet

USERCTL=yes

PEERDNS=no

IPV6INIT=no

PERSISTENT_DHCLIENT=yes

HWADDR=00:16:3e:26:67:2e

IPADDR0=172.19.6.127

IPADDR1=172.19.6.129

DEFROUTE=no

[root@iZ7u1o01onqjo4Z multi-nic-util-0.6]# 

[root@iZ7u1o01onqjo4Z multi-nic-util-0.6]# service network restart

Restarting network (via systemctl):                        [  OK  ]

[root@iZ7u1o01onqjo4Z multi-nic-util-0.6]# 

[root@iZ7u1o01onqjo4Z multi-nic-util-0.6]# 

[root@iZ7u1o01onqjo4Z multi-nic-util-0.6]# ip a

1: lo: mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000

    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00

    inet 127.0.0.1/8 scope host lo

       valid_lft forever preferred_lft forever

    inet6 ::1/128 scope host 

       valid_lft forever preferred_lft forever

2: eth0: mtu 1500 qdisc pfifo_fast state UP group default qlen 1000

    link/ether 00:16:3e:02:3b:0b brd ff:ff:ff:ff:ff:ff

    inet 172.19.6.126/24 brd 172.19.6.255 scope global dynamic eth0

       valid_lft 315359953sec preferred_lft 315359953sec

    inet6 fe80::216:3eff:fe02:3b0b/64 scope link 

       valid_lft forever preferred_lft forever

3: eth1: mtu 1500 qdisc pfifo_fast state UP group default qlen 1000

    link/ether 00:16:3e:26:67:2e brd ff:ff:ff:ff:ff:ff

    inet 172.19.6.127/16 brd 172.19.255.255 scope global eth1

       valid_lft forever preferred_lft forever

    inet 172.19.6.129/16 brd 172.19.255.255 scope global secondary eth1

       valid_lft forever preferred_lft forever

    inet6 fe80::216:3eff:fe26:672e/64 scope link 

       valid_lft forever preferred_lft forever


三、测试结果

分别访问三个公网IP地址,均可以正常访问了,说明配置没问题。


阿里云优惠购买攻略

阿里云代理购买,可获得:免费提供技术支持、优惠折扣、官方原价发票
注册阿里云账号
通过客服发送的链接
注册阿里云官网会员
关联成为VIP客户
免费协助产品选购
阿里官网直接提交订单
阿里云官网下单
通过阿里云官网控制台
申请阿里云合同
付款(自付/代付)
订单完成支付后
申请阿里云原价发票
售后专家护航
免费环境配置 协助备案
解决云上各种难题