Last active
March 8, 2021 00:55
-
-
Save TaylorJadin/33a2bdd265ef434e7c65e2cdcda9d526 to your computer and use it in GitHub Desktop.
LXD simple port forwarding
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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