Skip to content

Instantly share code, notes, and snippets.

@fcwu
Created January 15, 2014 00:46
Show Gist options
  • Save fcwu/8428857 to your computer and use it in GitHub Desktop.
Save fcwu/8428857 to your computer and use it in GitHub Desktop.
#!/bin/bash
# Local Network
NETWORK=192.168.16.0
GW=192.168.16.1
# Server IP Address
SERVER=123.123.123.123
# Server 對外的 Interface
SERVER_IF=eth0
echo "Creating Connection"
ssh -w 0:0 -f $SERVER "ifconfig tun0 10.0.2.1 netmask 255.255.255.252 pointopoint 10.0.2.2 ; echo 1 > /proc/sys/net/ipv4/ip_forward ;/sbin/iptables -t nat -A POSTROUTING -o $SERVER_IF -j MASQUERADE ;route add -net $NETWORK gw 10.0.2.2 dev tun0"
echo "Settingi local interface"
ifconfig tun0 10.0.2.2 netmask 255.255.255.252 pointopoint 10.0.2.1
route add -net ${SERVER%.*}.0/24 gw 10.0.2.1 dev tun0
route add $SERVER gw $GW
route add default gw 10.0.2.1 tun0
route del default gw $GW
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment