-2

I know I can get new IP address by going to Elastic IPs --> Allocate new address but by doing this I always get IPs in different subnet range.

I want to IPs with same subnet.

I have two ec2 instance, Actually I want a 2 new IP address with in same subnet range! Am trying to join two instances which is in same ZONE and same VPC, but their primary private IPs are in different subnet, so this is the issue!

I Have added a secondary Private IP directly to both instances with same subnet range ( by not using Elastic IP and then associating them) , So is there a way I can make this secondary Private IP as my primary one?

slm
  • 15,396
  • 12
  • 109
  • 124
programmer
  • 71
  • 1
  • 12
  • How are you creating the instances? – Chetan Feb 27 '19 at 13:10
  • using the AMI's in the marketplace @ChetanRanpariya – programmer Feb 27 '19 at 13:33
  • Then you must be selecting AZ and availability zone while creating the instance. are you sure you are selecting appropriate AZ and subnet ? – Chetan Feb 27 '19 at 13:38
  • @ChetanRanpariya No the instance already exits , Actually i want a new IP address with in same subnet range! Am trying to join two instances in same ZONE same VPC , but their primary private IPs are in different subnet , so this is the issue . – programmer Feb 27 '19 at 13:40

2 Answers2

1

Based on the documentation it isn't possible to select the IP from an address range for Elastic IP's unless you own the IP address space.

You can allocate an Elastic IP address from Amazon's pool of public IPv4 addresses, or from a custom IP address pool that you have brought to your AWS account. For more information about bringing your own IP address range to your AWS account, see Bring Your Own IP Addresses (BYOIP).

You may be able to hack around this but I don't think AWS would look kindly upon it.

slm
  • 15,396
  • 12
  • 109
  • 124
kenlukas
  • 3,616
  • 9
  • 25
  • 36
  • I have added a secondary Private IP directly to both instances with same subnet range ( by not using Elastic IP and then associating them) , So is there a way i can make this secondary Private IP as my primary one ?? @kenlukas – programmer Feb 27 '19 at 13:57
  • I am not clear what you're trying to accomplish. If I understand this correctly you have two subnets each with a host. The subnets are in the same AZ and VPC. You want a host in subnet X to have an IP address range from subnet Y. If that's correct my question is what is the purpose of that? – kenlukas Feb 27 '19 at 14:30
  • No thats not what I need, let me explain I have two instance / host in same AZ and VPC, but both of them IP address with different subnet. My requirement here is to make both instance to have IP address with same subnet. Also I need additional IP address in same subnet range for using as Virtual IP. @kenlukas – programmer Feb 27 '19 at 18:33
  • This kind of setup is required for my project, Two ec2 instance in same AZ and VPC and both their primary IP should be in same subnet. Additionaly I need two more IPs also in same subnet range. So far I have this setup except for the IPs part. So is there a way to generate IP with same subnet range? – programmer Feb 27 '19 at 18:43
  • One way I found was to assign same subnet range IP as the secondary private address to both the instance, but then they are not associated with those IP that's the problem. In Ifconfig the primary IP is still associated. So other way I have taught of setting up again Two new ec2 instance with same subnet range. Am still figuring how to do this? – programmer Feb 27 '19 at 18:46
0

I Found a solution for my problem:

While creating new instance itself we can assign IP address within the same subnet range.

Here are the steps : First have this ready

  • goto VPC --> Create Subnet
  • goto network&security --> create networkinterface

Then, * Launch Instance --> Choose the AMI --> choose instance type --> configure instance

Under configure instance :

*Select the network and subnet you have just created

  • Auto-assign Public IP : Enable

Then in same Page , downside you see Network interfaces : Here , Add Primary Ip , secondary Ip (you can add as many based on your subscription)

But for a free tier max 2 you can add !!

But main thing is you can assign any IP you need from that subnet range you had created.

Hoping this will help someone.

programmer
  • 71
  • 1
  • 12