VPN stands for Virtual private network (VPN). As the name suggests it is a virtually created private network. First, we will try to understand some key terms.
Virtual Network: In our systems, we have physical network cards (for LAN or WAN) which are responsible for data in and out from the system. Virtual networks mimic the physical network at the software level but in the background, it also has connections to the physical network device and all the data is transmitted or received through the physical network. Eg. are networks created when you create a virtual machine or run Docker containers.
Private Network: The reach in the private network is local (can only access their subnet IPs) and for public access, you need special rules at the gateway to forward the local traffic for public and receive data from the public and forward back to the local machine(for reference refer to How to do Network address translation (NAT) in Linux).
VPN Server: It is a physical or virtual machine that provides VPN services to users. On these servers, we install VPN server software which are based on Point-To-Point Tunneling Protocol (PPTP). It creates a tunnel from the remote client to the VPN server over the Internet.
VPN Client: A client is our machine or end device where we install VPN client software that is seeking connection from a VPN server.
What happen when we connect to the VPN server
Now when we look closely when we connect (VPN client) to VPN server it creates a virtual interface in our system. See the below mention screenshots. After connecting to the VPN server it has created tun0 interface. The IP address would be the same subnet which is from the VPN server.
The above snapshot shows the interface after connecting the VPN server, while the below snapshot shows interface status before connecting to VPN you can see that when we are not connected to the VPN we don’t have this extra virtual interface.
When VPN creates the virtual private network that means from your system now some of the traffic will be redirected to the VPN server.
In the below-mentioned code section, you can see all traffic with destination 172.16.0.1/16 will be redirected from tun0 which will forward to VPN server. All the internet access we are doing from wlp0s20f3 interface which is basically the interface responsible for wi-fi. For more information regarding IP routing table refer to How to check Routing Table in Linux article.
foofunc@ubuntu:~$ route -n Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface 0.0.0.0 192.168.1.1 0.0.0.0 UG 600 0 0 wlp0s20f3 172.16.0.0 0.0.0.0 255.255.0.0 U 50 0 0 tun0 169.254.0.0 0.0.0.0 255.255.0.0 U 1000 0 0 virbr0 192.168.1.0 0.0.0.0 255.255.255.0 U 600 0 0 wlp0s20f3 192.168.1.1 0.0.0.0 255.255.255.255 UH 600 0 0 wlp0s20f3 192.168.122.0 0.0.0.0 255.255.255.0 U 0 0 0 virbr0 foofunc@ubuntu:~$
If we don’t have VPN connected then we have the following routing entries.
foofunc@ubuntu:~$ route -n Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface 0.0.0.0 192.168.1.1 0.0.0.0 UG 600 0 0 wlp0s20f3 169.254.0.0 0.0.0.0 255.255.0.0 U 1000 0 0 virbr0 192.168.1.0 0.0.0.0 255.255.255.0 U 600 0 0 wlp0s20f3 192.168.1.1 0.0.0.0 255.255.255.255 UH 600 0 0 wlp0s20f3 192.168.122.0 0.0.0.0 255.255.255.0 U 0 0 0 virbr0 foofunc@ubuntu:~$
The above-mentioned routing gateways are configurable you can redirect traffic from the different gateway by adding IP rules.
Advantage of using VPN:
- We can access resources available within the private network by connecting to VPN of that network. eg. Universities, Company etc.
- By using VPN you can access to the web contents or web services which are restricted in you country.
- VPN connections are more secure because it creates the tunnel which is fully encrypted.
- Provides full anonymity.
- Can slow down internet speeds, depending on your needed server
- It does cost you money
- Consume network traffic too much
- Reduced MTU which also slows down interned speed.
- Extra efforts for configuration.