The openwrt firmware needs to be compiled on the local virtual machine, and dependencies need to be continuously downloaded during the compilation process. Due to the existence of GFW, compilation may fail, so you need to compile the VM to connect to the VPN.
The virtual machine system is CentOS6. The connection to PPTP is used as an example.
First install the pptp client:
Yum install pptp-setup
Create a VPN connection:
Pptpsetup -- create myvpn -- server 123.456.789.123 -- username vpnuser -- password 123456 -- encrypt # This
Create a VPN connection named myvpn
If the error "FATAL: Module ppp_mppe not found." occurs, you must register the Module:
Modprobe ppp_mppe
Connect to VPN
Pppd call myvpn
Verify connection:
Ip a | grep ppp
If no information is available, the connection fails. For details, see/var/log/message troubleshooting.
After the connection is successful, if you want to access other clients of the VPN server, add the route:
Route add-net 192.168.0.0 netmask 255.255.255.0 dev ppp0 #192.168.0.0 is the intranet segment of the VPN server
If you want all traffic to pass through the VPN, add the route after the VPN connection is successful:
Ip route replace 123.456.789.123 via 192.168.1.1 dev eth0 src 192.168.1.188 #123.456.789.123 is the ip address of the VPN server, and 192.168.1.1 is the virtual machine Gateway (because the virtual machine uses bridging, it is also the ip address of my router).
Ip route replace default dev ppp0
After the VPN is disconnected, you also need to delete the route:
Ip route del 123.456.789.123 via 192.168.1.1 dev eth0 src 192.168.1.188
Ip route add default via 192.168.1.1
Ppp also provides a more convenient way to connect to and disconnect a VPN:
Cp/usr/share/doc/ppp-2.4.5/scripts/pon/usr/sbin/
Cp/usr/share/doc/ppp-2.4.5/scripts/poff/usr/sbin/
Chmod + x/usr/sbin/pon
Chmod + x/usr/sbin/poff
Pon myvpn # connect to VPN
Poff myvpn # disconnect the VPN
I have also written a script to integrate the VPN connection and disconnection. No route is required each time. You can modify the ip address as needed before use.
Vpnstart script:
#! /Bin/bash
/Usr/sbin/pon myvpn
Echo "OK! Change route now! "
Sleep 5
/Sbin/ip route replace 123.456.789.123 via 192.168.1.1 dev eth0 src 192.168.1.188
Ip route replace default dev ppp0
Echo "Successful! VPN is start! "
Vpnstop script:
#! /Bin/bash
/Usr/sbin/poff myvpn
Echo "Wait! Change route now! "
Sleep 5
/Sbin/ip route del 123.456.789.123 via 192.168.1.1 dev eth0 src 192.168.1.188
/Sbin/ip route add default via 192.168.1.1
Echo "Successful! VPN is stop! "