Skip to content

Instantly share code, notes, and snippets.

@victorrica
Created April 20, 2017 01:36
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 victorrica/41c8653e9d993ac518bdfc8c9aa038f0 to your computer and use it in GitHub Desktop.
Save victorrica/41c8653e9d993ac518bdfc8c9aa038f0 to your computer and use it in GitHub Desktop.
#!/bin/sh
hostName=$1
sshPort=$2
webPort=$3
OS=$4
lxc-create --name=$hostName --template=$OS
lxc-start --name=$hostName
sleep 10
IP=$(lxc-info -n $hostName -iH)
echo $IP
iptables -t nat -A PREROUTING -i eth0 -p tcp --dport $sshPort -j DNAT --to $IP\:22
iptables -t nat -A PREROUTING -i eth0 -p tcp --dport $webPort -j DNAT --to $IP\:80
@victorrica
Copy link
Author

Usage
$ bash script.sh test 1001 1002 ubuntu

and connect with this command
ssh ubuntu@test.com -p 1001

To use own domain without port, use reverse proxy on web port

@victorrica
Copy link
Author

victorrica commented Apr 20, 2017

#!
bin/sh

hostName=$1
sshPort=$2
webPort=$3
OS=$4
lxc-create --name=$hostName --template=$OS
lxc-start --name=$hostName
sleep 10
IP=$(lxc-info -n $hostName -iH)
iptables -t nat -A PREROUTING -i eth0 -p tcp --dport $sshPort -j DNAT --to $IP\:22
iptables -t nat -A PREROUTING -i eth0 -p tcp --dport $webPort -j DNAT --to $IP\:80
netfilter-persistent save

if [ ! -z "$IP" ]; then
        /root/web.sh $hostName $IP
        service nginx restart
fi

echo $IP

nginx reverse proxy added

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