Fix-Linux-Error-111-Connection-Refused

 Linux Error 111 Connection Refused — Causes & Fixes

Linux error 111: Connection refused occurs when a client tries to connect to a service that is unreachable or actively rejecting the connection. This error is commonly seen with database servers, Oracle listeners, web services, or applications that rely on proper hostname resolution.

In many cases, the issue is caused by incorrect host configuration, missing loopback entries, or services not listening on the expected port.

This guide explains the causes and exact steps to fix Linux error 111 safely.

What Does “Connection Refused” Mean?

A connection refused error means:

The target machine is reachable, but no service is accepting the connection.

This can happen due to:

  • Incorrect /etc/hosts configuration
  • Missing loopback address
  • DNS resolution issues
  • Service not running
  • Firewall blocking the port
  • Listener or socket failure
  • Network misconfiguration

Example Error Messages

You may see errors like:

TNS-12547: TNS:lost contact
TNS-12560: TNS:protocol adapter error
Linux Error: 104: Connection reset by peer

or:

TNS-12541: TNS:no listener
Linux Error: 111: Connection refused

These indicate the system cannot establish a valid connection to the service.

Step-by-Step Fix: Edit the Hosts File

One of the most common causes is a broken or incomplete hosts file.

Step 1: Open Terminal

Launch a terminal session with administrative privileges.

Step 2: Edit the Hosts File

Run:

sudo nano /etc/hosts

Enter your administrator password when prompted.

Step 3: Verify Loopback Entries

Make sure the following lines exist:

127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6

These loopback entries are required for internal networking.

Step 4: Add Your Hostname

Add your server IP and hostname:

192.168.1.1 yourhostname oracle

Replace:

  • 192.168.1.1 → your server IP
  • yourhostname → your actual hostname

Incorrect hostname resolution is a common trigger for error 111.

Step 5: Save and Exit

In nano, press:

CTRL + X
Y
Enter

Step 6: Restart Network or Service

Restart networking or the affected service:

sudo systemctl restart network

Or restart the Oracle listener / relevant service if needed.

Additional Checks (If the Error Persists)

Check if the Service Is Running

systemctl status servicename

Check Listening Ports

ss -lntp

Or:

netstat -tulnp

Confirm your service is listening on the expected port.

Check Firewall Rules

sudo iptables -L

Or:

sudo ufw status

Firewall rules may block connections.

Prevent Future Connection Errors

  • Maintain proper hostname configuration
  • Monitor critical services
  • Keep firewall rules documented
  • Use automated monitoring
  • Apply regular system audits

Frequently Asked Questions

What causes Linux error 111?

Linux error 111 is usually caused by hostname/DNS resolution issues, firewall rules blocking the port, or the target service not running or not listening on the expected port.

Is error 111 a network problem?

Not always. “Connection refused” typically means the host is reachable but the application/service is not accepting connections (for example, the service is stopped or listening on a different port).

Can a firewall cause connection refused?

Yes. If a firewall blocks the port (UFW/iptables/firewalld), the connection may fail. Check firewall rules and confirm the port is allowed.

Will editing /etc/hosts fix all cases?

No. Editing /etc/hosts helps when hostname resolution or missing loopback entries are the root cause. If the service is down or the port is blocked, you’ll need to restart the service or adjust firewall/network settings.

Final Thoughts

Linux error 111 connection refused is typically easy to fix once the root cause is identified. Most cases involve host configuration or inactive services. By correcting the hosts file and verifying service status, the system can usually be restored quickly.

If connection failures continue, deeper network diagnostics may be required.

Solve recurring connection failures and optimize your Linux servers with our managed server management services—expert troubleshooting, proactive monitoring, and configuration support to keep your systems stable and accessible.

To get more updates you can follow us on Facebook, Twitter, LinkedIn

Subscribe to get free blog content to your Inbox
Loading

Related Posts