经常有客户咨询阿里云服务器怎么实现绑定多IP地址? 阿里云服务器多个弹性公网IP是否可以绑定到一台实例上?本文通过实操的方式为大家介绍,步骤相对较多阿里云控制台步骤有所简化,如果有什么不理解可以联系我们。
配置前须知
参考实例规格族绑定弹性网卡和内网IP的个数限制:https://help.aliyun.com/document_detail/25378.html
配置弹性网卡:https://help.aliyun.com/document_detail/56955.html
分配辅助私网IP地址:https://help.aliyun.com/document_detail/101180.htm
Linux实例查看网关信息的方法:https://help.aliyun.com/knowledge_detail/41321.html
配置流程
一、阿里云控制台配置
1、购买阿里云ECS服务器
CPU&内存:1核1 GiB
操作系统:CentOS 7.8 64位
实例规格:ecs.s6-c1m1.small
实例规格族:ecs.s6
2、创建弹性网卡绑定阿里云服务器
3、创建两个弹性公网ip绑定到,分别绑定到辅助网卡的主私网IP和辅助私网IP上。
下图已经绑定完成
二、Cenots 7服务器内部配置流程
appledeMacBook-Pro:~ apple$ ssh root@47.100.180.23
The authenticity of host '47.100.180.23 (47.100.180.23)' can't be established.
ECDSA key fingerprint is SHA256:KQkTuB1q8B3VTPvm1R8s3Cw5Tk/fe1QsGu+b3CV63BM.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added '47.100.180.23' (ECDSA) to the list of known hosts.
root@47.100.180.23's password:
Welcome to Alibaba Cloud Elastic Compute Service !
[root@iZ7u1o01onqjo4Z ~]#
[root@iZ7u1o01onqjo4Z ~]# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> 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: <BROADCAST,MULTICAST,UP,LOWER_UP> 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: <BROADCAST,MULTICAST> 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
[root@iZ7u1o01onqjo4Z ~]#
[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
[root@iZ7u1o01onqjo4Z multi-nic-util-0.6]#
[root@iZ7u1o01onqjo4Z multi-nic-util-0.6]# systemctl restart eni.service
[root@iZ7u1o01onqjo4Z multi-nic-util-0.6]#
[root@iZ7u1o01onqjo4Z multi-nic-util-0.6]# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> 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: <BROADCAST,MULTICAST,UP,LOWER_UP> 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: <BROADCAST,MULTICAST,UP,LOWER_UP> 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
[root@iZ7u1o01onqjo4Z multi-nic-util-0.6]#
[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]# 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]# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> 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: <BROADCAST,MULTICAST,UP,LOWER_UP> 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: <BROADCAST,MULTICAST,UP,LOWER_UP> 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
[root@iZ7u1o01onqjo4Z multi-nic-util-0.6]#
提示:ifcfg-eth1 配置信息修改必看
[root@iZ7u1o01onqjo4Z multi-nic-util-0.6]# cat /etc/sysconfig/network-scripts/ifcfg-eth1
DEVICE=eth1
BOOTPROTO=no
#这个是网络配置参数:
#BOOTPROTO=static 静态IP
#BOOTPROTO=dhcp 动态IP
#BOOTPROTO=none 无(不指定)
#通常情况下是dhcp或者static,通过指定方式的办法来获得地址,如果没有指定的话可能会出现问
ONBOOT=yes
TYPE=Ethernet
USERCTL=yes
PEERDNS=no
IPV6INIT=no
PERSISTENT_DHCLIENT=yes
HWADDR=00:16:3e:26:67:2e #配置辅助弹性网卡对应的MAC地址
IPADDR0=172.19.6.127 #配置辅助弹性网卡的主私网IP
IPADDR1=172.19.6.129 #配置辅助弹性网卡的辅助私网IP 1
DEFROUTE=no #表示网卡接口不是默认路由。为避免在启动(ifup)弹性网卡时改变ECS实例活动的默认路由,不要将eth1设置为默认路由
三、测试结果
分别访问三个公网IP地址,均可以正常访问了,说明配置没问题。