SSH connection keeps crashing

firewallssh

although this is not a real programming question perhaps anyone has any idea regarding my problem.

It's pretty weird. When I remotely connect one of our ubuntu servers per ssh the connection can be established without any problems.

I log in and enter something that produces output on the console like "ls -al". Then the connection just hangs. If I enter "ls" it shows me the output. If I enter "dmesg" session crashes too.

There's nothing in the servers log and the terminal on my side doesn't recognize the connection being closed it just hangs.

Now I wonder if this could be Firewall-Related. If there's to much output sent back it crashes.

Or maybe one of our programmers messed up something. I really don't know in which direction I can try to track this problem. Any ideas on this? I just can't understand what is happening and if it's related to network problems or system misconfiguration….I can't see why there's a difference between "ls" and "ls -al" or "dmesg". And the login produces a lot of output too on the screen but it always works.

Ok I just found out about serverfault.com and posted my question there. This can be deleted because it's off topic here. Thx anyway!

Best Answer

What you've likely stumbled upon is a PMTU problem.

Many devices have a Maximum Transmission Unit(MTU) which is the maximum size of the packet they can send. If the device sees a packet beyond this threshold it will break it up into smaller parts, but some packets have a special flag that says Don't Fragment(DF). These packets are dropped and a ICMP message is sent to the sender so that the send can resize the packet itself.

In your case it looks like there is something between the SSH server and you that is dropping these packets and not telling the server. If you have a packet dump of the connection you will probably see packets missing. There is a tool on Linux called tracepath that lets you see the mtu of all the hops on the way to the server.

To work around this issue you should add an iptables rule such as the following to the network your server resides in:

iptables -A INPUT -d x.x.x.x/24 -p tcp --tcp-flags SYN,RST SYN -j TCPMSS  --clamp-mss-to-pmtu