# # rules.before # # Rules that should be run before the ufw command line added rules. Custom # rules should be added to one of these chains: # ufw-before-input # ufw-before-output # ufw-before-forward # # START OPENVPN RULES # NAT table rules *nat :POSTROUTING ACCEPT [0:0] # Allow traffic from OpenVPN client to eth0 -A POSTROUTING -s 10.8.0.0/8 -o eth0 -j MASQUERADE COMMIT # END OPENVPN RULES # Don't delete these required lines, otherwise there will be errors *filter
enable it
1
ufw enable
gcloud F/W (gcloud)
By default, gcloud only open 80 and 443 port. If we need to open more ports, can use following commands
cd ~/openvpn-ca source vars ./build-key client2 ....................................................................................+++ writing new private key to 'client2.key' ----- You are about to be asked to enter information that will be incorporated into your certificate request. What you are about to enter is what is called a Distinguished Name or a DN. There are quite a few fields but you can leave some blank For some fields there will be a default value, If you enter '.', the field will be left blank. ----- Country Name (2 letter code) [US]: State or Province Name (full name) [CA]: Locality Name (eg, city) [SanFrancisco]: Organization Name (eg, company) [Fort-Funston]: Organizational Unit Name (eg, section) [MyOrganizationalUnit]: Common Name (eg, your name or your server's hostname) [client2]: Name [server]:client2 Email Address [me@myhost.mydomain]: Please enter the following 'extra' attributes to be sent with your certificate request A challenge password []: An optional company name []: Using configuration from /home/<xxxxxxxx>/openvpn-ca/openssl-1.0.0.cnf Check that the request matches the signature Signature ok The Subject's Distinguished Name is as follows countryName :PRINTABLE:'US' stateOrProvinceName :PRINTABLE:'CA' localityName :PRINTABLE:'SanFrancisco' organizationName :PRINTABLE:'Fort-Funston' organizationalUnitName:PRINTABLE:'MyOrganizationalUnit' commonName :PRINTABLE:'client2' name :PRINTABLE:'client2' emailAddress :IA5STRING:'me@myhost.mydomain' Certificate is to be certified until Feb 22 14:11:05 2028 GMT (3650 days) Sign the certificate? [y/n]:y 1 out of 1 certificate requests certified, commit? [y/n]y Write out database with 1 new entries Data Base Updated aaray21cn@instance-1:~/openvpn-ca$
client dev tun proto tcp remote [GLOUD EXTERNAL IP] 2295 resolv-retry infinite nobind user nobody group nogroup persist-key persist-tun ns-cert-type server cipher AES-128-CBC auth SHA256 key-direction 1 comp-lzo verb 3 # script-security 2 # up /etc/openvpn/update-resolv-conf # down /etc/openvpn/update-resolv-conf
sudo apt-get update sudo apt-get install openvpn ls /etc/openvpn vi ~/client2.ovpn
Uncomment the three lines we placed in to adjust the DNS settings if you were able to find an update-resolv-conf file:
1 2 3
script-security 2 up /etc/openvpn/update-resolv-conf down /etc/openvpn/update-resolv-conf
Add following 4 lines
1 2 3 4
#by pass shadowsocks server address route [GCLOUD EXTERNAL_IP_ADDRESS] 255.255.255.255 net_gateway #use ss socks5 socks-proxy 127.0.0.1 1080
run following command
1 2 3 4 5 6 7 8 9 10 11
sudo openvpn --config client2.ovpn
... Sat Feb 24 23:05:00 2018 /sbin/ip route add 0.0.0.0/1 via 10.8.0.9 Sat Feb 24 23:05:00 2018 /sbin/ip route add 128.0.0.0/1 via 10.8.0.9 Sat Feb 24 23:05:00 2018 /sbin/ip route add 35.194.128.249/32 via 192.168.1.1 Sat Feb 24 23:05:00 2018 /sbin/ip route add 10.8.0.1/32 via 10.8.0.9 Sat Feb 24 23:05:00 2018 GID set to nogroup Sat Feb 24 23:05:00 2018 UID set to nobody Sat Feb 24 23:05:00 2018 Initialization Sequence Completed
download build release. Find the package for your system. kcptun-linux-amd64-20171201.tar.gz, get the URL link https://github.com/xtaci/kcptun/releases/download/v20171201/kcptun-linux-amd64-20171201.tar.gz
1 2 3 4
mkdir -p ~/tool/kcptun cd ~/tool/kcptun wget https://github.com/xtaci/kcptun/releases/download/v20171201/kcptun-linux-amd64-20171201.tar.gz tar xzvf kcptun-linux-amd64-20171201.tar.gz
create server-config.json file as following content. localaddr is the kcptun listen port. remoteaddr is the shadowsocks ip:port.
mkdir -p ~/tool/kcptun cd ~/tool/kcptun wget https://github.com/xtaci/kcptun/releases/download/v20171201/kcptun-linux-amd64-20171201.tar.gz tar xzvf kcptun-linux-amd64-20171201.tar.gz
create client-config.json file as following content. localaddr is the kcptun listen port on local. remoteaddr is the remote kcptun server ip:port. Others should be same as server.