sshnet / sshnet/SSH.NET

Possible issue with IPv6 client connecting to an iPv4 host

Open
#1,639 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C#
Stars
4.4k
Forks
993
Avg merge
9d 21h
Merged PRs (30d)
1

Description

TL;DR; Connections only work if I disable IPv6 on local machine. Client may accept IPv6 connections, but I can only whitelist IPv4 addresses. Can I force SSH.NET to use IPv4 only?

Hey,
I started working on an old project again where an app would connect to a remote server to transfer some files. I could not connect to my remote test servers, connection would time out. I reduced the example right down to the following,

var sshClient = new SshClient(Host, Port, Username, Password);
sshClient.ErrorOccurred += (sender, e) =>
{
    Debugger.Break();
};
sshClient.HostKeyReceived += (sender, eventArgs) =>
{
    Debugger.Break();
};
sshClient.ServerIdentificationReceived += (sender, eventArgs) =>
{
    Debugger.Break();
};
sshClient.Connect();
Debugger.Break();

If I took the credentials I can manually SSH to the server without issues.

ssh User@Host -p PORT
< input password

I have the issue across both my macOS and Windows machines here. Wondering if remote servers had changed I asked friend to try and they have no issues at all.

Remote host makes me input an IP address to whitelist my client machine. It only accepts IPv4 addresses, I tried an IPv6 address but it rejected it. If I disable IPv6 (tested on Windows by disabling in control panel) my connections work right away. So I think what is happening here is the host accepts an IPv6 connection but with no way to whitelist it I can't connect. I assume because the host accepts the IPv6 connection it won't attempt to fallback to IPv4. But if this is the case I don't understand why Terminal connects fine. I tried verbose output with ssh but I couldn't see any IPv4/6 things happening.

If I can confirm host accepts IPv6 connections I'll request they allow adding IPv6 whitelists which should solve the problem (at least on this host)

Is it possible to force SshClient and SftpClient use IPv4 if even if IPv6 is available?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the minimal C# reproduction and the SshClient.Connect and SftpClient connection entry points named in the report. Reproduce with IPv6 enabled and disabled, compare the connection behavior with the terminal SSH client, and determine whether an IPv4-only option is defined. Done means the required behavior and configuration surface are documented or supported by a verified test.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
networking
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.