fix: use 127.0.0.1 instead of localhost for Ollama connections#156
Merged
kevin-mindverse merged 1 commit intomindverse:masterfrom Apr 7, 2025
Merged
Conversation
yingapple
approved these changes
Apr 7, 2025
kevin-mindverse
approved these changes
Apr 7, 2025
Heterohabilis
pushed a commit
to Heterohabilis/Second-Me
that referenced
this pull request
May 29, 2025
EOMZON
pushed a commit
to EOMZON/Second-Me
that referenced
this pull request
Feb 1, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Use 127.0.0.1 instead of localhost for Ollama local services
Suggested Change
When deploying Ollama as a local service, it is recommended to use
127.0.0.1as the IP address rather thanlocalhost. This is because in environments with an active VPN, DNS resolution forlocalhostmay not resolve to127.0.0.1, leading to connection issues.Technical Explanation
This distinction behaves differently across client libraries:
requests library: When using the requests library to connect to Ollama local services,
127.0.0.1andlocalhostare typically equivalent since these requests are generally not routed through VPN to external networks, allowing DNS to correctly resolvelocalhostto127.0.0.1.OpenAI SDK: When using the OpenAI SDK, VPN may route traffic to external networks, causing
localhostto resolve to an address other than127.0.0.1, preventing proper connection to local services. This is a common issue in regions like China where VPN usage is widespread for accessing international services and APIs.Recommendation
To ensure consistency and stability across various network environments, it is recommended to always use
127.0.0.1rather thanlocalhostwhen connecting to Ollama local services.Test Code