Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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