In today's guide, we'll walk you through the detailed steps to establish a PPTP VPN connection on Ubuntu Server 16.04. Plus, we'll cover how to ensure automatic reconnections and route management.
Please note: PPTP has known vulnerabilities, so consider this method for learning purposes and evaluate more secure VPN options for critical applications.
Step-by-Step Guide: Setting up a PPTP Server on Ubuntu
1. Switching to Superuser Mode
To begin, you'll want to access your system's root. Do this with:
sudo su
2. System Update
Always start by updating your system to the latest versions:
apt-get update && apt-get upgrade && apt-get dist-upgrade
3. Installing the PPTP Client
To get the required client, run:
apt-get install pptp-linux
4. Configuring the Connection
Use the nano editor to create and configure your connection file:
nano /etc/ppp/peers/vpn
Within this file, you'll enter several parameters. Remember to adjust settings such as the server address, username, and password to fit your setup. Example of the file content:
pty "pptp 192.168.1.125 --nolaunchpppd" #change the server address to yours
require-mschap-v2
require-mppe-128
user test1 #username
password "testtest" #password
nodeflate
nobsdcomp
noauth
nodefaultroute #disable default route,
#if you need it - replace with defaultroute
persist #reconnect when disconnected
maxfail 10 #number of reconnection attempts
holdoff 15 #interval between connections
5. Testing the Connection
After setup, connect using:
pppd call vpn
To verify the connection, use:
ifconfig ppp
ppp0 Link encap:Point-to-Point Protocol
inet addr:192.168.6.100 P-t-P:192.168.6.1 Mask:255.255.255.255
UP POINTOPOINT RUNNING NOARP MULTICAST MTU:1396 Metric:1
RX packets:5 errors:0 dropped:0 overruns:0 frame:0
TX packets:5 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:3
RX bytes:68 (68.0 B) TX bytes:68 (68.0 B)
If you need to disconnect, a simple:
killall pppd
will do the trick.
6. Automating Route Addition and Reconnections
For seamless connectivity, it's wise to automate route additions and ensure your VPN auto-reconnects if there's a drop.
For route additions:
nano /etc/ppp/ip-up
You should add lines to the end of the file:
case "$5" in 192.168.6.1) route add -net 192.168.6.0/24 gw 192.168.6.1 ;; *) esac
Don't forget to change addresses to yours.
For auto-connect and auto-reconnect you can use 2 scripts:
First one - pptp.sh
:
nano ~/pptp.sh
#!/bin/sh vpn='192.168.1.125' #external address or domain name of your vpn server ps=`ps ax | grep $vpn | wc -l` if [ $ps -ge 2 ]; then exit 1; else /usr/sbin/pppd call vpn exit 0; fi
Second - pptp-reconnect.sh
:
nano ~/pptp.sh
#!/bin/bash SHELL=/bin/sh PATH=/sbin:/bin:/usr/sbin:/usr/bin #change 192.168.6.1 to your server's internal IP. if ! ping -Q 2 -c 4 -t 2 192.168.6.1; then pids=( $(pgrep -f pppd) ) for pid in "${pids[@]}"; do if [[ $pid != $$ ]]; then kill "$pid" fi done /root/pptp.sh fi
Don't forget to make theese scripts executable:
chmod +x ~/pptp.sh ~/pptp-reconnect.sh
And add them to cron:
crontab -e
Add to the end of the file line:
*/1 * * * * /bin/bash /root/pptp-reconnect.sh
In Conclusion
Setting up a PPTP client on Ubuntu Server 16.04 can be achieved with the above steps. Whether you're an IT professional or a hobbyist looking to learn, this guide provides an easy-to-follow route to get your VPN up and running.
Disclaimer: While PPTP provides a foundational understanding of VPN configurations, always explore and consider modern and more secure VPN solutions for robust applications.
Share the article with your friends in social networks, maybe it will be useful to them.
If the article helped you, you can >>thank the author<<