144

I have an Ubuntu Server 10.10 32-bit in my home. I'm making SSH connections to it from my PC via Putty.

The problem is, sometimes I'm able to login seamlessly. However, sometimes it gives me an error like this: Network error: Connection refused.

Then, I dont't change anything, try to login a few times more, wait a while and try again. Sometimes I can log in, sometimes I cannot. It seems pretty random to me.

What can I do to solve this?

Edit:

And Sometimes, Putty gives Network error: Software caused connection abort error after displaying login as: text.

Here is the ping -t output:

Pinging 192.168.2.254 with 32 bytes of data:
Reply from 192.168.2.254: bytes=32 time=6ms TTL=64
Reply from 192.168.2.254: bytes=32 time=65ms TTL=6
Reply from 192.168.2.254: bytes=32 time=88ms TTL=6
Reply from 192.168.2.254: bytes=32 time=1ms TTL=64
Reply from 192.168.2.254: bytes=32 time=3ms TTL=64
Reply from 192.168.2.254: bytes=32 time=1ms TTL=64
Reply from 192.168.2.254: bytes=32 time=1ms TTL=64
Reply from 192.168.2.254: bytes=32 time=1ms TTL=64
Reply from 192.168.2.254: bytes=32 time=1ms TTL=64

I turned off firewall of router, and everything seems to work now. Except for that, I still can't enter my web server by typing external IP from my PC.

Braiam
  • 69,112
frbry
  • 1,541

14 Answers14

120

You must install openssh-server on Linux before this will work. Get the internal IP address of Ubuntu and use that IP to setup port forwarding on port 22 (SSH) section of your router. Although if you don't intend to SSH from outside your network, this is not required.

Here's how to install openssh-server:

sudo apt-get install openssh-server openssh-client
[ENTER PASSWORD]
htorque
  • 66,086
58

IP address conflict turned out to be the root cause when I was seeing this SSH error message.

After reading the answers above I suspected an IP address conflict, but needed to prove that address conflict was or was not the problem.

This great article showed how to use arp-scan to see if two pieces of hardware were claiming the same IP address.

In my case the server machine had a static ip address of 192.168.1.42, I used arp-scan to check that address:

$ sudo apt-get install arp-scan
$ arp-scan -I eth0 -l | grep 192.168.1.42
  192.168.1.42 d4:eb:9a:f2:11:a1 (Unknown)
  192.168.1.42 f4:23:a4:38:b5:76 (Unknown) (DUP: 2)

Sure enough there was a conflict, as shown above. Then I ran arp-scan without the grep, found that .43 was available, went and edited /etc/network/interfaces and changed the static ip from .42 to .43

Kulfy
  • 18,154
Rian Sanderson
  • 691
  • 6
  • 5
21

open the file of ssh config:

sudo nano /etc/ssh/ssh_config

find the port

#port 22

uncomment (remove the #) the port option

then save the file by ctrl + x and restart your service

sudo service sshd restart
Auspex
  • 1,158
20

Use arping on the IP address that is having connection issues. That will show the MAC address for each ping reply, and hopefully will unmask the rogue MAC address.

arping 192.168.2.254

You should check the DHCP IP address pool on the DHCP server, make sure no devices have static IPs that collide with the DHCP pool.

These clues point to duplicate IP:

  • ping ttl and round trip time looks like 2 distinct servers
  • intermittent disconnects without rebooting
Eliah Kagan
  • 119,640
10

I had the same problem, even though I had a static IP address. Turns out another server on my network had been assigned the same (static) IP address. (Duh.) So it does appear that the problem is caused by IP address conflicts, but there may be various possible ways they can happen. If you set yours to static and still have a problem, try shutting down your machine and pinging the address. If you get any replies, start looking for what else could have the same address.

DLosc
  • 201
8

What do you get if you do this?

grep 192.168.2.25 /etc/hosts.deny

If that returns anything then you need to remove it.

wjandrea
  • 14,504
4

It's basically because of any one of the following reasons:

  1. Too many users on the network trying to access the server
  2. More than one computer on the network has the same IP as the server causing an IP conflict
  3. Wrong username or your credentials have been revoked
Glutanimate
  • 21,763
4

This looks more of a problem of your network equipment than the server itself.

Check /var/log/messages for ethernet link up/downs (or wlan in case of wireless). If so try changing the cables.

forcefsck
  • 335
4

I can confirm this exact issue: It's not a simple connectivity issue. The ethernet link does not change state; server is reachable via ping; ssh connects flawlessly occasionally, then seemingly randomly does not connect or existing ssh session drops. This occurs on Ubuntu 10.04 and 11.04. Following hheimbuerger's suggestion I gave the server a static IP, this seemed to fix it.

Workaround: Change adapter from DHCP to static.

George
  • 41
3

On my case, fail2ban had banned my IP:

  1. iptables -n -L (use this command to see if you were banned by this ****** or something else)
  2. https://bobcares.com/blog/fail2ban-unban-ip/
user
  • 494
2

You might want to check your iptables rules on your server. It sounds like you've a rule for limiting new SSH connections.

The next rule allows 5 new connections per minute, if you exceed this limit, your new connections will be rejected after some time has passed:

-A INPUT -p tcp --dport 22 -m conntrack --ctstate NEW -m limit --limit 5/min -j ACCEPT

See the IPTables / Netfilter documentation, scroll a bit till limit.

Lekensteyn
  • 178,446
2

I had exactly the same issue, and in my case it turned out to be an IP address conflict. My Ubuntu VM had a dynamic address, but another machine (in this case a phone) had a static IP assigned that the DHCP server did not know about.

Just changing the IP that was assigned by the DHCP server to the Ubuntu VM fixed all connection issues.

2

arp-scan is showing two duplicate devices, but when I run Advanced IP scanner on Win8 they all look fine. So they don't always agree.

I set the router to revoke all the leases by telling it to give only 1-hour leases. Will give it time to see if it clears up.

SDsolar
  • 3,219
0

On Manjaro, while sshd is installed by default, the server daemon was not actice.

sudo systemctl start sshd.service opened it immediately, and works out of the box.

mazunki
  • 133