Skip to content

Instantly share code, notes, and snippets.

@Vaviloff
Created August 14, 2023 15:10
Show Gist options
  • Select an option

  • Save Vaviloff/cfed8b44468ec8ac8344fd922d0b38f5 to your computer and use it in GitHub Desktop.

Select an option

Save Vaviloff/cfed8b44468ec8ac8344fd922d0b38f5 to your computer and use it in GitHub Desktop.
#!/bin/bash
SERVER=$1
EXTIP=$(curl -s api.ipify.org)
line=$( lxc info $SERVER | grep inet: | grep /24 )
IP=$(echo "$line" | grep -oE 'inet:\s+([0-9]{1,3}\.){3}[0-9]{1,3}' | awk '{print $2}')
SERVERPORT=$(echo $IP | cut -d '.' -f4 )
echo extip: $EXTIP
echo lxc ip: $IP
echo
echo lxc config device add $SERVER ssh-redirect proxy listen=tcp:${EXTIP}:${SERVERPORT}22 connect=tcp:$IP:22
echo
echo Press [Enter] to execute or CTRL+C to abort
read dummy
lxc config device add $SERVER ssh-redirect proxy listen=tcp:${EXTIP}:${SERVERPORT}22 connect=tcp:$IP:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment