All Projects → laserbat → Vpnify

laserbat / Vpnify

Licence: wtfpl
vpnify - transparently route traffic of a process through VPN

Programming Languages

shell
77523 projects

Projects that are alternatives of or similar to Vpnify

Meshbird
Meshbird is open-source cloud-native multi-region multi-cloud distributed private networking.
Stars: ✭ 3,401 (+4495.95%)
Mutual labels:  network, vpn, privacy
Dsvpn
A Dead Simple VPN.
Stars: ✭ 4,894 (+6513.51%)
Mutual labels:  vpn, privacy
Easy Wg Quick
Creates Wireguard configuration for hub and peers with ease
Stars: ✭ 502 (+578.38%)
Mutual labels:  vpn, privacy
Openmptcprouter
OpenMPTCProuter is an open source solution to aggregate multiple internet connections using Multipath TCP (MPTCP) on OpenWrt
Stars: ✭ 652 (+781.08%)
Mutual labels:  network, vpn
Docker Ipsec Vpn Server
Docker image to run an IPsec VPN server, with IPsec/L2TP, Cisco IPsec and IKEv2
Stars: ✭ 4,356 (+5786.49%)
Mutual labels:  network, vpn
Glorytun
Multipath UDP tunnel
Stars: ✭ 437 (+490.54%)
Mutual labels:  network, vpn
Wireguard Install
WireGuard VPN server installer
Stars: ✭ 616 (+732.43%)
Mutual labels:  vpn, privacy
Ovpm
OpenVPN Management Server - Effortless and free OpenVPN server administration
Stars: ✭ 256 (+245.95%)
Mutual labels:  network, vpn
Nipe
An engine to make Tor network your default gateway
Stars: ✭ 1,032 (+1294.59%)
Mutual labels:  network, privacy
V2ray Core
A platform for building proxies to bypass network restrictions.
Stars: ✭ 13,438 (+18059.46%)
Mutual labels:  network, vpn
Fem
Blokada 5 for Android and iOS (repo moved).
Stars: ✭ 57 (-22.97%)
Mutual labels:  vpn, privacy
Vpn At Home
1-click, self-hosted deployment of OpenVPN with DNS ad blocking sinkhole
Stars: ✭ 1,106 (+1394.59%)
Mutual labels:  vpn, privacy
Trojan Go
Go实现的Trojan代理,支持多路复用/路由功能/CDN中转/Shadowsocks混淆插件,多平台,无依赖。A Trojan proxy written in Go. An unidentifiable mechanism that helps you bypass GFW. https://p4gefau1t.github.io/trojan-go/
Stars: ✭ 4,049 (+5371.62%)
Mutual labels:  network, privacy
Wireguard Manager
Self-hosted Wireguard Installer / Manager for CentOS, Debian, Ubuntu, Arch, Fedora, Redhat, Raspbian
Stars: ✭ 478 (+545.95%)
Mutual labels:  vpn, privacy
Fpnd
Python package for freepn network daemon
Stars: ✭ 271 (+266.22%)
Mutual labels:  vpn, privacy
Openpyn Nordvpn
Easily connect to and switch between, OpenVPN servers hosted by NordVPN on Linux (+patch leakes)
Stars: ✭ 544 (+635.14%)
Mutual labels:  vpn, privacy
Setup Ipsec Vpn
Scripts to build your own IPsec VPN server, with IPsec/L2TP, Cisco IPsec and IKEv2
Stars: ✭ 16,987 (+22855.41%)
Mutual labels:  network, vpn
Netshoot
a Docker + Kubernetes network trouble-shooting swiss-army container
Stars: ✭ 3,709 (+4912.16%)
Mutual labels:  network, containers
Xiringuito
SSH-based "VPN for poors"
Stars: ✭ 969 (+1209.46%)
Mutual labels:  network, vpn
Dnscrypt Menu
Manage DNSCrypt from the macOS menu bar (BitBar plugin)
Stars: ✭ 59 (-20.27%)
Mutual labels:  network, privacy

vpnify

This tool can be used to transparently route traffic of certain programs through VPN, while keeping the rest of it routed normally. It is protocol-agnostic and can work with any VPN software.

For example:

vpnify sudo openvpn --config vpn.conf

Creates an isolated VPN connection. To make a program use this connection, you can use

vpnify <program>

That's all. No configuration needed. It creates network namespace and configures it on the first run and deletes it once the last process using it exits.

Installation

Just copy to /usr/local/bin/

sudo cp $HOME/vpnify/vpnify /usr/local/bin/vpnify

Multiple VPN's

To create two or more distinct VPN connections, you just need to create a new symlink.

ln -s /usr/local/bin/vpnify /usr/local/bin/vpnify2

Now you can do this:

vpnify sudo openvpn --config vpn.conf
vpnify2 sudo openvpn --config vpn2.conf

Programs run with vpnify2 will use different connection from programs run with vpnify.

Custom resolv.conf and hosts

You can put your custom hosts and resolv.conf file to /etc/vpnify/ (or /etc/vpnify/<name> for a symlinked version).

Also you can create folders named "pre.d" and "post.d" in the same folder with custom hooks that will be executed before running the supplied command inside the namespace and after the cleanup respectively.

Advanced features: Limiting clearnet access

You can use hooks to limit clearnet access by the applications run inside vpnify. First let's create a folder /etc/vpnify/pre.d/:

mkdir -p /etc/vpnify/pre.d/

Or, if you want to setup a symlinked version,

mkdir -p /etc/vpnify/<symlink-name>/pre.d/

Now we need to create a hook that will execute firewall commands:

vim /etc/vpnify/pre.d/limit.sh

Contents of this file can be something like:

iptables -I FORWARD -i $VETH0 -j DROP # Drop all outgoing traffic
iptables -I FORWARD -i $VETH0 -d 198.51.100.157 -p udp --destination-port 1024 -j ACCEPT # Allow ONLY packets going to your VPN server

Where 198.51.100.157 is IP address of your VPN server. Replace udp/1024 with transport protocol your VPN uses it's port. This forbids all outgoing traffic from inside vpnify except for traffic going to 198.51.100.157 udp:1024.

Don't forget to make the hook executable!

chmod +x /etc/vpnify/pre.d/limit.sh

If your VPN configuration uses a hostname you need to add this hostname to /etc/vpnify/hosts (which will be /etc/hosts inside the namespace). Otherwise it will fail to resolve, since all traffic outside is blocked.

Take a look at files in example-hooks/*.d/limit.sh for a better explanation and a clean-up hook!

unVpnify

You can use this script to route all the traffic on your machine through a VPN except for applications running inside (un)vpnify!

To do this, let's create a symlink:

ln -s /usr/local/bin/vpnify /usr/local/bin/unvpn

Then, we create the configuration folders

mkdir -p /etc/vpnify/unvpnify/pre.d/
mkdir -p /etc/vpnify/unvpnify/post.d/

And now, create a hook that does some routing magic. Look here for a deeper explanation of routing commands used in this hook.

vim /etc/vpnify/unvpnify/pre.d/unvpn.sh

ip rule add iif $VETH0 table rt2 # Route all traffic from our namespace through a second routing table
ip route add default via 192.168.1.1 table rt2 # Set up the default gateway on our second table

chmod +x /etc/vpnify/unvpnify/unvpn.sh

Also we need to add the 'rt2' routing table to our system:

echo '1 rt2' >> /etc/iproute2/rt_tables

Check out example-hooks/*.d/unvpn.sh for more information and a clean-up hook.

bashrc

You might want your bash prompt to change when you are using vpnify, so you can easily tell apart which consoles are runing through vpnify and which are not. Luckily it is very easy to do. Just put something like this in your bashrc:

netns() {
    [[ -z "$NETNS" ]] || echo "[$NETNS]"
}

PS1="$(netns)$PS1"

sudoers

If you want to use this script without having to type your password every time, you can add this line to your /etc/sudoers

%wheel ALL=(ALL) NOPASSWD:SETENV: /usr/local/bin/vpnify

Warning: this might not be secure, use with caution.

Compatibility

This script should work on any modern linux that supports network and mount namespaces and has nsenter command available. I have tested it on Void Linux, Ubuntu 16.04, CentOS 6.5 and 7.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].