Fallback to 127.0.0.1 if localhost is unusable

Fix #937