[LINUX] IPv6 should be disabled when ssh of Raspberry Pi 4 is very slow

environment

For details on the setup environment, refer to Set up raspbian buster on Raspberry Pi 4.

phenomenon

When I ssh connect to Raspberry Pi, it takes time to connect.

Cause

The default is IPv6 connection → IPv4 connection, and it took time for the IPv6 connection to time out. (Maybe I made a mistake during setup)

I wondered if it was a problem on the Raspberry Pi side because it is slow to connect from Windows Powershell or other Linux.

Debug information can be displayed by executing it with the -v option when sshing. Here, you can see that you are connecting to Raspberry Pi from Windows, and after failing to connect like an IPv6 address due to a timeout, you are connecting with IPv4.

$ ssh -v Username@Machine name
OpenSSH_for_Windows_7.7p1, LibreSSL 2.6.5
debug1:Connecting to machine name[xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx] port 22.
debug1: connect to address xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx port 22: Connection timed out
debug1:Connecting to machine name[yyy.yyy.yyy.yyy] port 22.
debug1: Connection established.

How to improve

Change the Raspberry Pi settings.

$ sudo vi /etc/sysctl.conf

Add the following to sysctl.conf.

net.ipv6.conf.all.disable_ipv6 = 1
net.ipv6.conf.default.disable_ipv6 = 1

Reflect changes in sysctl.conf.

$ sudo sysctl -p

Confirm that there is no item called inet6 with the following command.

$ ip a

Close the ssh connection once.

$ exit

Connect with ssh again and check.

$ ssh -v Username@Machine name
OpenSSH_for_Windows_7.7p1, LibreSSL 2.6.5
debug1:Connecting to machine name[yyy.yyy.yyy.yyy] port 22.
debug1: Connection established.

(..) φ memo

The above disables IPv6 on all interfaces. If you want to disable only a specific interface, add the following items to /etc/sysctl.conf. Below is an example of disabling only eth0.

net.ipv6.conf.eth0.disable_ipv6 = 1

Recommended Posts

IPv6 should be disabled when ssh of Raspberry Pi 4 is very slow
Why detectMultiScale () is slow on Raspberry Pi B +
When a file is placed in the shared folder of Raspberry Pi, the process is executed.
I want to be notified of the connection environment when the Raspberry Pi connects to the network
What is Raspberry Pi?
Phone notification when surveillance camera motion is detected on Raspberry Pi