I'm currently renting a /24 address block and would like to assign an IP Address from that block to one of my EC2 instances. I heard from a friend a while back that this can be done, but I haven't yet found a way to do it using Elastic IP or through an EC2 instances IP settings.
It is not possible to bring your own range of Public IP address to AWS.
Related
I have an instance inside a VPC with DNS hostnames & DNS resolution enabled
Today, each instances I spawn get the hostname & Private IP DNS name as
ip-xx-xx-xx-xx.ec2.internal
The problem with this is everytime my instance is terminated and I have to replace it, the IP address is going to change. Other machines in the same VPC need a deterministic way to access this instance. e.g. by connecting to mymasterinstance.dev. Any idea how do I give an internal / private DNS for my instance?
Private IP addresses on Amazon EC2 instances do not change. Therefore, the other machines could simply reference the private IP address.
Alternatively, you can create a "Private hosted zone" in Amazon Route 53 and create an A-Record to associate a domain name (eg mymasterinstance.dev) with the private IP address of the instance.
The public IP address on an instance will change when the instance is Stopped and Started (but will not change when the instance is Rebooted). If you require a static public IP address, you can create an Elastic IP Address and associate it with the instance.
Another perhaps simpler way to do this is to add a second IP address to your EC2 instance. When you terminate an instance, and add back a "replacement" instance, set its second IP address to what the terminated instance's second IP address was. Then you can do all of your referencing directly by IP address and you have full control over that second IP address. None of your configs needs to change.
I have a scenario where I want to setup an haproxy cluster with keepalived. I saw this blog post https://www.peternijssen.nl/high-availability-haproxy-keepalived-aws/ and its pretty detailed and easy to follow, but for my scenario I need the elastic IP's to be private. Is this doable ? As from AWS documentation Elastic IP's are only public IPs.
I need a floating IP which will act as a floating cluster IP. What can I use if Elastic IP is not an option.
An elastic IP within AWS is actually a static public IP address. This functionality is required as by default a public IP address is not reserved by an account, and when enabled limits the total IPv4 addresses you can keep.
For private address ranges however, your instances can be assigned any private IP address that is within any of your VPCs CIDR range(s).
In fact for this reason you can select almost any IP address found within your VPC when launching a new instance, in addition the IP addresses that are attached to an EC2 instance are static and will be attached to that instance until it is terminated.
Therefore as long as you don't terminate the instances the private IP(s) will be maintained. However, in the event the instance fails and is not recoverable you would still need to launch a new instance and use that IP.
It might be more beneficial using a DNS record to resolve the IP just in case of an emergency, or failing that use a load balancer to distribute traffic.
For this case you can provision an Elastic Network Interface (ENI) with a static private IP address which you can attach/re-attach to EC2 instances. As long as you don’t delete the ENI, it will retain the I as p address. Find out more here: https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/using-eni.html
How can I migrate an EC2 instance to a different subnet with the same static IP Address (NOT ELASTIC ADDRESS)?
To "migrate" an Amazon EC2 instance, you actually need to create a new Amazon EC2 instance. However, you can copy across the disk contents, so it appears to be the same instance.
To retain a public IP address, you should be using an Elastic IP address. This is a static IP address that is allocated to your AWS Account. You can then assign the IP address to any instance in the same region.
If you are not using an Elastic IP address, then it is not possible to keep the IP address. (It is not static.)
Steps:
Use Create image to create an AMI of the existing instance. This takes a copy of the disks attached to the instance.
Launch a new EC2 instance, specifying this new AMI and changing whatever settings you wish (eg subnet)
Reassociate the Elastic IP address to the new instance
Delete the old instance once you are happy that everything is working.
-> Elastic IP address means Static or fixed IP address, other than that what ever public IP you receive during a session is temporary.
-> AWS will reassign you new public IP address when you start or stop your instance in a span of 5 to 10 minutes. ( irrespective of which subnet you are).
->Hence if you want to migrate EC2 instance with the same IP address, you need to assign an ELastic IP address.You can refer to this moving ec2 instances to another subnet
I have an Amazon EC2 instance that I have been using for production and for some weird reason I did not use an Elastic IP.
Now that I want to use an Elastic IP, it seems AWS doesn't allow connection on the old IP. In my use case I need the instance to be accessible through both IPs. Is this really possible?
No. You cannot use the old public IP once you associate an elastic IP. Remember you have only one network interface, you cannot have 2 public (routable) IPs associated with it.
From Elastic IP Address Basics
If you associate an Elastic IP address with the eth0 network interface
of your instance, its current public IP address (if it had one) is
released to the EC2-VPC public IP address pool. If you disassociate
the Elastic IP address, the eth0 network interface is automatically
assigned a new public IP address within a few minutes. This doesn't
apply if you've attached a second network interface to your instance.
I have a server that is up and running with an auto-assigned public IP address. This IP address was not created with Elastic IP. Is there anyway to transfer this IP address onto a new instance in my account?
I'm afraid you can't.
The auto assigned public IPs are not yours to deassociate and reassociate.
You can't tell them "I changed my mind, I want to use this IP as if it was an Elastic IP". It doesn't work like that. You can't really pick your elastic IP. You just ask for one, and then operate with whatever IP they gave you.
You cannot manually associate or disassociate a non-elastic IP address from your instance. Instead, in certain cases, aws release the public IP address from your instance, or assign it a new one for below cases:
1. They release the public IP address for your instance when it's stopped or terminated. Your stopped instance receives a new public IP address when it's restarted.
They release the public IP address for your instance when you associate an Elastic IP address (EIP) with your instance, or when you associate an EIP with the primary network interface (eth0) of your instance in a VPC. When you disassociate the EIP from your instance, it receives a new public IP address.
If the public IP address of your instance in a VPC has been released, it will not receive a new one if there is more than one network interface attached to your instance.
http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/using-instance-addressing.html#concepts-public-addresses
If you require a persistent public IP address that can be associated to and from instances as you require, use an Elastic IP address (EIP) instead. You can allocate your own EIP, and associate it to your instance. For more information, please see Elastic IP Addresses (EIP).
Easy, setup a HTTP or TCP transparant proxy, with HAProxy or Nginx.