Skip to content

Instantly share code, notes, and snippets.

@Weapuh
Forked from WisdomCode/moonlightssh.sh
Last active March 30, 2024 00:48
Show Gist options
  • Save Weapuh/cc261c0ea4104fbc563f112fa2786990 to your computer and use it in GitHub Desktop.
Save Weapuh/cc261c0ea4104fbc563f112fa2786990 to your computer and use it in GitHub Desktop.
Moonlight Game Streaming via SSH
#located in ~/.ssh/config
Host *
UseKeychain yes
AddKeysToAgent yes #Mac specific
Host moonlight
Hostname SERVER
User USER
LocalForward 0.0.0.0:47984 GAMING_PC_IP:47984
LocalForward 0.0.0.0:47989 GAMING_PC_IP:47989
LocalForward 0.0.0.0:48010 GAMING_PC_IP:48010
LocalForward 0.0.0.0:48998 SSH_SERVER_IP:48998
LocalForward 0.0.0.0:48999 SSH_SERVER_IP:48999
LocalForward 0.0.0.0:49000 SSH_SERVER_IP:49000
LocalForward 0.0.0.0:49002 SSH_SERVER_IP:49002
LocalForward 0.0.0.0:49010 SSH_SERVER_IP:49010
#/etc/systemd/system/moonlight.service
#create socat commands as a service
[Unit]
Description=moonlight service
After=network-online.target
[Service]
ExecStart=/root/bin/redirectudp.sh
[Install]
WantedBy=multi-user.target
#!/bin/bash
#Enables Playing on a moonlight server via an ssh tunnel. This is useful on restricted networks, as only the ssh port is needed.
#Needs the complimentary script, redirectudp, running on the ssh server to function.
#needs a private key for the ssh server
#sudo apt install ssh socat snap
#snap install moonlight
#Alias of the SSH server from SSH config (sharing local network with the gaming rig
sip=SSH_SERVER_ALIAS
#Program to start with moonlight
app=Desktop
ssh $sip &
socat -T15 udp4-recvfrom:47998,reuseaddr,fork tcp:localhost:48998 &
socat -T15 udp4-recvfrom:47999,reuseaddr,fork tcp:localhost:48999 &
socat -T15 udp4-recvfrom:48000,reuseaddr,fork tcp:localhost:49000 &
socat -T15 udp4-recvfrom:48002,reuseaddr,fork tcp:localhost:49002 &
socat -T15 udp4-recvfrom:48010,reuseaddr,fork tcp:localhost:49010 &
moonlight stream localhost $app
kill $(lsof -t -i:49000)
#!/bin/bash
#complementary script for the moonlightssh script. Run it on the ssh server.
#sudo apt install socat
#IP of the Gaming rig
sip=IP
socat tcp4-listen:48998,reuseaddr,fork udp:$sip:47998 &
socat tcp4-listen:48999,reuseaddr,fork udp:$sip:47999 &
socat tcp4-listen:49000,reuseaddr,fork udp:$sip:48000 &
socat tcp4-listen:49002,reuseaddr,fork udp:$sip:48002 &
socat tcp4-listen:49010,reuseaddr,fork udp:$sip:48010
@c3m3gyanesh
Copy link

did you manage to get it work?

@Weapuh
Copy link
Author

Weapuh commented Mar 30, 2024

I did, which was satisfying, but the performance was pretty patchy. Instead of trying to lessen the lost packets, I opted for running a wireguard VPN docker container and it works beautifully.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment