SSH freezes when running commands on Ubuntu EC2 Instance
A week ago, an old colleague of mine contacted me for help. Her problem was whenever she runs “top” command, or downloads file that is larger than 1Kb from SFTP server, the server stops responding. She was using an Ubuntu instance on AWS. At first she thought there was something wrong with the file system, so she tried to mount the root volume of this instance to another instance to see if this still happens but this was not successful. It was ridiculous that as I logged in to the server, running same commands, or downloading very big file, the server still responded well, although she said she had the same problem on all the machines she used to connect to this instance. Wierd! There’s maybe something fishy with the network configuration, or what?
After a while looking on the Internet for the problem, I found out that this was because of the MTU setting of the network device of the instance was rather big: 9001! The following steps were what I did to fix this:
- First make sure that we have an Inbound rule in Security Groups which accepts all ICMP packets. This is “to avoid potential problems with MTU settings and packet loss”, as stated in this wiki: https://code.google.com/p/opendatakit/wiki/AggregateAWSInstall
- Check your current MTU number:
`ifconfig | grep -A 4 eth0 | grep MTU`
We change it to a lower value, in my case it was 1400:
`ifconfig mtu 1440`
Now check to see if the problem with SSH is solved. It works well when running “top” command? Good. Now we’ll set this value permanently or when we reboot the server, it will come up with the big default value (9001).
Open the file: `/etc/dhcp/dhclient.conf`, add the following lines:
“`default interface-mtu 1400;
supersede interface-mtu 1400;“`
Save it. Done.