Skip to content

Instantly share code, notes, and snippets.

@TaylorJadin
Last active March 8, 2021 00:55
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 TaylorJadin/33a2bdd265ef434e7c65e2cdcda9d526 to your computer and use it in GitHub Desktop.
Save TaylorJadin/33a2bdd265ef434e7c65e2cdcda9d526 to your computer and use it in GitHub Desktop.
LXD simple port forwarding
#!/bin/bash
if [ $# -ne 3 ]
then
echo "Usage: ./port-forward.sh [container] [tcp|udp] [port number]"
exit
fi
container="${1}"
protocol="${2}"
port="${3}"
# Get ip of container
ip=`lxc list $container -c 4 | awk '!/IPV4/{ if ( $2 != "" ) print $2}'`
rulename="${container}${protocol}${port}"
listen="${protocol}:0.0.0.0:${port}"
connect="${protocol}:${ip}:${port}"
# Debug
#echo "lxc config device add ${container} ${rulename} proxy listen=${listen} connect=${connect}"
# Do the stuff
lxc config device add ${container} ${rulename} proxy listen=${listen} connect=${connect}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment