- Newest
- Most votes
- Most comments
- I think your hypothesis is correct.
- You could do as you suggest. But why not use the Instance Metadata Service to retrieve the instance id instead? It would be much more unique; and would avoid an issue where an instance is reusing an IP address from some time in the past.
- Using the instance id you can query the EC2 control plane; find the attached network interfaces; then find the associated public/elastic IP address. However, the servers are behind a load balancer so will (most likely) not have an individual public IP.
- Great. Thanks for input.
- Interesting idea yes. However, I like the idea of the public IP more since it shortens the time for us to remote to the server if there is a problem.
- Thanks for the input. I'll look into this.
Hi.
You are using FirstOrDefault, have you checked if you can get only one?
You can exclude the loopback address as follows:
https://docs.microsoft.com/en-us/dotnet/api/system.net.ipaddress.isloopback?view=net-6.0
ip.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork &&! ipAddresses.isLoopback (ip)
Yes. I actually saw this possibility in terms of the following piece of code. Not sure if I understand all of it though.. :(
public IPAddress GetLocalIp() { var firstUpInterface = NetworkInterface.GetAllNetworkInterfaces() .OrderByDescending(c => c.Speed) .FirstOrDefault(c => c.NetworkInterfaceType != NetworkInterfaceType.Loopback && c.OperationalStatus == OperationalStatus.Up); var props = firstUpInterface?.GetIPProperties(); return props?.UnicastAddresses .Where(c => c.Address.AddressFamily == AddressFamily.InterNetwork) .Select(c => c.Address) .FirstOrDefault(); }
However, I guess it does not solve the actual problem in retrieving the private IP adress since it does not exist yet according to my hypothesis.
I also had this happen after a migration. Any ideas as to why the migrated site is resolving to 127.0.0.1? How can I get it to resolve to be publically available? For reference it's a WP multisite. Thanks!
Many, many, many moons ago I saw this problem; and it was because the application (web server in this case) was starting up and looking to bind to a network interface before the "real" network interface was ready - so the only one it could grab was the loopback. So maybe check the start sequence and ensure that the web server starts well after the network is initialised?
Relevant content
- Accepted Answerasked 2 years ago
- asked a month ago
- AWS OFFICIALUpdated 9 months ago
- AWS OFFICIALUpdated 2 years ago
- AWS OFFICIALUpdated a year ago