如何在GCE上为单个实例分配多个传出IP地址? [英] How to assign multiple outgoing IPs addresses to a single instance on GCE?
问题描述
一个人如何在Google Compute Engine的同一台计算机上分配多个临时外部IP地址? Web界面仅讨论主要IP地址,但我没有提及添加更多地址.
How does one assign multiple ephemeral external IP addresses to the same machine on Google Compute Engine? The web interface only discusses the primary IP addresses, but I see no mention of adding more addresses.
我在 https://stackoverflow.com/a/39963576/14731 上找到了一个相关问题,但重点是将多个传入 IP路由到同一实例上.
I found a related question over at https://stackoverflow.com/a/39963576/14731 but it focuses on routing multiple incoming IPs to the same instance.
我的应用程序是一个Web客户端,需要从多个源IP建立多个传出连接.
My application is a web client that needs to make multiple outgoing connections from multiple source IPs.
推荐答案
是的,可能,并执行以下步骤:
Yes it's possible, with some steps:
- 根据需要的接口创建相同数量的VPC(网络)
- 在每个VPC内创建一个子网,并确保它们不重叠
- 在第一个VPC中添加防火墙规则,以允许您所在位置的SSH
- 创建一个具有多个接口的实例(每个VPC一个),并为每个实例分配外部地址 通过第一个VPC上的地址
- SSH到您的实例
- 为每个网络接口配置单独的路由表
- Create the same number of VPC (Network) as you need interfaces
- Create a subnet inside each VPC and make sure the are not overlapping
- Add a firewall rule in the first VPC to allow SSH from your location
- Create an instance with multiple interfaces (one in each VPC) and assign external address to each one
- SSH to your instance via the address located on the first VPC
- Configure a separate routing table for each network interface
您必须了解的事情:
- 您只能在创建实例时仅添加界面
- 我在配置路由表时遇到了一个错误,但是它起作用了(RTNETLINK答案:文件存在)
- 辅助接口的路由表未持久,您必须管理该操作
- You can add interfaces only on instance creation
- I've got an error on configuration of routing table, but it worked (RTNETLINK answers: File exists)
- Routing table of secondary interfaces are not persisted, you have to manage how to do this
Things you have to know:
yann@test-multiple-ip:~$ ip a
[...]
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1460 qdisc pfifo_fast state UP group default qlen 1000
link/ether 42:01:c0:a8:00:02 brd ff:ff:ff:ff:ff:ff
inet 192.168.0.2/32 brd 192.168.0.2 scope global eth0
valid_lft forever preferred_lft forever
inet6 fe80::4001:c0ff:fea8:2/64 scope link
valid_lft forever preferred_lft forever
3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1460 qdisc pfifo_fast state UP group default qlen 1000
link/ether 42:01:c0:a8:01:02 brd ff:ff:ff:ff:ff:ff
inet 192.168.1.2/32 brd 192.168.1.2 scope global eth1
valid_lft forever preferred_lft forever
inet6 fe80::4001:c0ff:fea8:102/64 scope link
valid_lft forever preferred_lft forever
yann@test-multiple-ip:~$ curl --interface eth0 ifconfig.co
35.241.195.172
yann@test-multiple-ip:~$ curl --interface eth1 ifconfig.co
35.241.253.41
这篇关于如何在GCE上为单个实例分配多个传出IP地址?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!