📌 Issue: Eureka Registers the Wrong IP (169.254.x.x
)
🔍 Problem Statement
Auth-Service
(running on Mac) was registered with169.254.x.x
(a link-local address) instead of its correct local network IP (192.168.x.x
).- This caused gateway routing failures, as the wrong IP was unreachable.
- As a result, remote debugging could not be triggered, making development and debugging impossible.
- Even after fixing the registration, Eureka UI still showed stale
169.254.x.x
instances.
🔹 Why Did This Happen?
1️⃣ How Eureka Determines an IP
When a service registers with Eureka, it tries to detect its IP in this order:
- Checks if
ip-address
is set explicitly (eureka.instance.ip-address
). - Checks if
prefer-ip-address: true
is enabled (forces Eureka to use an IP instead of hostname). - If no explicit IP is set, Eureka auto-selects the first available non-loopback interface.
- If everything fails, Eureka resolves the hostname to an IP.
2️⃣ Why Was 169.254.x.x
Chosen Instead of 192.168.x.x
?
- Multiple network interfaces on Mac (e.g.,
en0
,lo0
,bridge0
). - Docker networking interference (Docker creates virtual networks that may confuse Eureka).
- Eureka auto-detected the wrong interface (
bridge0
ordocker0
).
✅ Fix: Ensure Eureka Registers the Correct IP
1️⃣ Explicitly Set the Correct IP in application.yml
Modify Auth-Service
configuration:
eureka:
instance:
prefer-ip-address: true # Forces Eureka to use an IP instead of hostname
ip-address: ${HOST_IP} # Uses dynamically assigned IP
hostname: ${HOST_IP} # Ensures consistency
Start the service with the correct IP:
HOST_IP=$(ipconfig getifaddr en0) java -jar auth-service.jar
(Replace en0
with the correct network interface if necessary.)
2️⃣ Reduce Eureka Stale Instance Timeout
Modify Eureka Server’s application.yml
to clean up stale instances faster:
eureka:
server:
eviction-interval-timer-in-ms: 10000 # Eviction check every 10s
client:
registry-fetch-interval-seconds: 5 # Refresh UI every 5s
3️⃣ Manually Remove Stale Instance
Find the incorrect instance ID:
curl -s http://192.168.1.105:8761/eureka/apps/AUTH-SERVICE | grep instanceId
Delete the old entry:
curl -X DELETE http://192.168.1.105:8761/eureka/apps/AUTH-SERVICE/{INSTANCE_ID}
(Replace {INSTANCE_ID}
with the correct ID.)
4️⃣ Restart Eureka to Force Cleanup
If the wrong IP persists, restart Eureka:
docker restart eureka-server
Or (if running standalone):
pkill -f eureka && java -jar eureka-server.jar
5️⃣ Check Current Eureka Connection (More Reliable than Web UI)
To verify Eureka’s registered instance IP, use:
curl -s http://192.168.1.105:8761/eureka/apps/AUTH-SERVICE | grep ipAddr
✅ This command is more accurate than the Eureka web UI, as it directly fetches the latest registered instances.
🎯 Final Outcome
✔ Auth-Service
is now registered only with 192.168.x.x
.
✔ Eureka UI no longer shows 169.254.x.x
.
✔ Gateway correctly routes requests to the correct IP, ensuring full functionality.
✔ Remote debugging now works correctly, allowing normal development and testing.
✔ Stale instances are evicted quickly and automatically.
✔ Checking via curl
ensures accurate real-time Eureka registration info.