Skip to content

Instantly share code, notes, and snippets.

@hovo1990
Forked from WisdomCode/moonlightssh.sh
Created June 29, 2022 19:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hovo1990/4ab40bd9ce92f3edfb574182f36d1265 to your computer and use it in GitHub Desktop.
Save hovo1990/4ab40bd9ce92f3edfb574182f36d1265 to your computer and use it in GitHub Desktop.
Moonlight Game Streaming via SSH
#!/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
#IP of the gaming rig on the local network
gip=IP
#User and Address of the SSH server (sharing local network with the gaming rig
sshuser=USER
sip=DOMAIN
#Program to start with moonlight
app=Desktop
ssh \
-L 47984:$gip:47984 \
-L 47989:$gip:47989 \
-L 48010:$gip:48010 \
-L 48998:localhost:48998 \
-L 48999:localhost:48999 \
-L 49000:localhost:49000 \
-L 49002:localhost:49002 \
-L 49010:localhost:49010 \
-N $sshuser@$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
@Weapuh
Copy link

Weapuh commented May 25, 2023

Have you had success in getting this code to work?
I've gotten it to work remotely up until I get no video output and it kills the session.
I moved all the local port forwards into an ssh config alias to clean it up a little.

@c3m3gyanesh
Copy link

Have you had success in getting this code to work? I've gotten it to work remotely up until I get no video output and it kills the session. I moved all the local port forwards into an ssh config alias to clean it up a little.

how did you fix the 'no video output' issue?

@Weapuh
Copy link

Weapuh commented Apr 16, 2024

Have you had success in getting this code to work? I've gotten it to work remotely up until I get no video output and it kills the session. I moved all the local port forwards into an ssh config alias to clean it up a little.

how did you fix the 'no video output' issue?

Sorry, I don't remember, maybe lowering the bitrate.
I'm having much more success using a wireguard container to my home network, highly recommend.

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