Created
April 20, 2017 01:36
-
-
Save victorrica/41c8653e9d993ac518bdfc8c9aa038f0 to your computer and use it in GitHub Desktop.
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/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 |
#!
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
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