How to set up a Raspberry Pi VPN server - Raspberry Pi Forums
after lot of frustration, i've set working tls vpn server raspberry pi. had set static key server worked nicely, decided tls server better because of disadvantages associated former. there lot of tutorials out there on how this, didn't find 1 complete solution worked me in once place; in end, solution found came few different sources. among them, [url=hhttp://readwrite.com/2014/04/10/raspberry-pi-vpn-tutorial-server-secure-web-browsing]this[/url] readwrite, great paper eric jodoin, , openvpn website's howto.
clear, goal have pi vpn server @ home connect client while on public wifi networks. importantly, of client's network traffic routed through encrypted vpn connection. main reason wanted post howto make easier others might facing difficulty trying same thing. i've tried provide both rationale behind why being done throughout , relevant citation interested in reading more. i've assumed starting point new version of raspbian strong password , ssh enabled. also, assumed commands entered root.
fixed problem me.
clear, goal have pi vpn server @ home connect client while on public wifi networks. importantly, of client's network traffic routed through encrypted vpn connection. main reason wanted post howto make easier others might facing difficulty trying same thing. i've tried provide both rationale behind why being done throughout , relevant citation interested in reading more. i've assumed starting point new version of raspbian strong password , ssh enabled. also, assumed commands entered root.
- update , upgrade:
enter following terminal:code: select all
sudo -s # **rest of instructions assume you've done sudo apt-get update sudo apt-get upgrade
- install openvpn, make few changes:
install openvpnonce installed, move easy-rsa directory /etc/openvpn, because,code: select all
sudo apt-get install openvpn
it's best copy directory location such /etc/openvpn, before edits, future openvpn package upgrades won't overwrite modifications (from openvpn's howto).
can done with:then:code: select all
cp -r /usr/share/doc/openvpn/examples/easy-rsa/2.0 /etc/openvpn/easy-rsa
find export easy_rsa= line , changecode: select all
nano /etc/openvpn/easy-rsa/vars
if want, can change export key_size=1024code: select all
export easy_rsa=”/etc/openvpn/easy-rsa”
code: select all
export key_size=2048
- generate certificate , key:
in terminal, enter:after ./build-ca need enter (for example, "vpnserver") "common name". else can press enter. you'll have enter 'y' couple of times @ end.code: select all
cd /etc/openvpn/easy-rsa . ./vars ./clean-all ./build-ca
generate certificate , private server key:can press enter again, enter "server" common name.code: select all
./build-key-server server
create client:press enter except enter "client1" common name , pem passphrase (you'll asked when log in).code: select all
./build-key-pass client1
now,generate static preshared hmac key shown below.code: select all
./build-dh
"because server drop packet lacking authentication code computed preshared openvpn hmac key.
furthermore, clients preshared openvpn hmac key able exchange certificates.
therefore, attempts @ buffer overflow through malicious packet injection or mitm using fake certificates defeated attacker unable compute valid authentication code without openvpn hmac key." jodoin "soho remote access vpn. easy pie, raspberry pi ..."code: select all
openvpn --genkey --secret /etc/openvpn/easy-rsa/keys/ta.key
- copy files , make few system changes:
once complete, ssh client pi , securely transfer files required client:copy text here , save /etc/openvpn/server.conf on pi server. remember @ file , change values appropriate before moving on. specifically, make sure enter pi's lan address in correct spot (see comments) , make sure dh key size correct.code: select all
scp /etc/openvpn/easy-rsa/keys/client1.key user@123.456.789.101:/home/user/ scp /etc/openvpn/easy-rsa/keys/client1.crt user@123.456.789.101:/home/user/ scp /etc/openvpn/easy-rsa/keys/ca.crt user@123.456.789.101:/home/user/ scp /etc/openvpn/easy-rsa/keys/ta.key user@123.456.789.101:/home/user/
go here , copy/past text file called client.conf on client. remember again go through file , make appropriate changes (see comments). make sure copy/paste entire contents of /etc/openvpn/easy-rsa/keys/ta.key server <tls-auth> ... </tls-auth> block.
now, on server:find , uncomment line:code: select all
nano /etc/sysctl.conf
then,code: select all
#net.ipv4.ip_forward=1
now, reboot pi.code: select all
sysctl -p
enter:if pi connected wirelessly, interface wlan0, not eth0, change if necessary in above commands. note these commands have entered each time pi reboots. commands above assume pi connected through ethernet cable. if error this:code: select all
iptables -a input -i tun+ -j accept iptables -a output -o tun+ -j accept iptables -t nat -a postrouting -s 10.8.0.0/24 -o eth0 -j masquerade iptables -i forward -i tun0 -o eth0 -s 10.8.0.0/24 -d 192.168.0.0/24 -m conntrack --ctstate new -j accept iptables -a input -i eth0 -m state --state new -p udp --dport 1194 -j accept iptables -a forward -i tun+ -j accept iptables -a forward -i tun+ -o eth0 -m state --state related,established -j accept iptables -a forward -i eth0 -o tun+ -m state --state related,established -j accept service openvpn restart
see section below on how fix (i had this).code: select all
"iptables v1.4.14: can't initialize iptables table `nat': table not exist (do need insmod?) perhaps iptables or kernel needs upgraded.":
make sure port forwarding set on router - port 1194 upd should forwarded pi's lan address. - connect client , verify traffic being routed through vpn:
go client machine , connect:if successful, should see message sayingcode: select all
sudo openvpn /home/user/client.conf
on client make sure web traffic being routed through vpn doingcode: select all
initialization sequence completed
first step shouldcode: select all
traceroute www.google.com
using setup, verified wireshark web traffic being routed through vpn server (except dns).code: select all
1 10.8.0.1 (10.8.0.1)
- that's it! basic set can own customization/security hardening
code: select all
sudo apt-get install rpi-update sudo skip_backup=1 rpi-update
hey rmurr --
when './clean-all' -
thoughts? did '. ./vars' first? tried 'source ./vars/' no avail...
-cw
when './clean-all' -
code: select all
please source vars script first (i.e. "source ./vars") make sure have edited reflect configuration
-cw
raspberrypi
Comments
Post a Comment