SSH over WebSocket - Xray's solution

how to ssh login to IPv6 server in IPv4-only network.

I have an IPv6-only VPS. But unfortunately, my house’s network is IPv4-only.
So I am finding a way to ssh login to IPv6-only VPS from IPv4-only network.

  1. The first thing is to convert IPv4 flow to IPv4 flow. CloudFlare could do this, but only support HTTP/HTTPS/WebSocket.
  2. With first condition, we have to explore the way to implement SSH over WebSocket.

And again, Xray has flexiable features, and also support SSH(TCP) over WebSocket.

Here is Xray client config, run at local.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
{
"inbounds": [
// receive ssh connection at 127.0.0.1:8022
// and forward to ipv6-vps.example.com:22
{
"tag": "ssh-inbound",
"port": 8022,
"listen": "127.0.0.1",
"protocol": "dokodemo-door",
"settings": {
"address": "ipv6-vps.example.com",
"port": 22,
"network": "tcp",
"followRedirect": false
}
}
],
"outbounds": [
{
"tag": "proxy",
"protocol": "vmess",
"settings": {
"vnext": [
{
// this domain proxied by CloudFlare
"address": "proxy.example.com",
"port": 443,
"users": [{
"id": "12345678-1234-1234-1234-123456789012"
}]
}
]
},
"streamSettings": {
// proxy encapsulate to websocket
"network": "ws",
"security": "tls"
}
}
],
"routing": {
"rules": [
// ssh-inbound forword through proxy, which support IPv6
{
"type": "field",
"inboundTag": [
"ssh-inbound"
],
"outboundTag": "proxy"
}
]
}
}

And, we need to configure proxy.example.com AAAA record to server’s IPv6 address, and turn Proxy Status to Proxied.

Which makes proxy.example.com could be accessed by IPv4-only network, via WebSocket protocol.

Let’s try to SSH login:

1
2
3
local$ ssh [email protected] -p 8022
vps$ echo $SSH_CONNECTION
2a02:10:6:1::2e 56502 2a02:10:6:1::2e 22

At ssh-server view, this ssh session is from proxy server.

And we are in IPv4-only network, can login VPS through IPv6.


SSH over WebSocket - Xray's solution
http://boblu.net/ssh-over-websocket-by-xray/
Author
Bob
Posted on
March 22, 2025
Licensed under