Skip to content

Instantly share code, notes, and snippets.

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

victorrica commented Apr 20, 2017

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