Cov txheej txheem:

Raspberry Pi VPN Gateway: 6 Kauj Ruam
Raspberry Pi VPN Gateway: 6 Kauj Ruam

Video: Raspberry Pi VPN Gateway: 6 Kauj Ruam

Video: Raspberry Pi VPN Gateway: 6 Kauj Ruam
Video: Building The "Ultimate" Router - [PFSense + Pi-hole + PIVPN] 2024, Hlis ntuj nqeg
Anonim
Raspberry Pi VPN Gateway
Raspberry Pi VPN Gateway

Hloov tshiab 2018-01-07:

  • Hloov kho yam uas ploj lawm thiab hloov pauv xav tau rau tam sim no ntawm Raspian.
  • Kuj tsim cov lus qhia tshwj xeeb rau NordVPN.

Muaj qee qhov kev siv sib txawv rau VPN. Xijpeem koj xav tiv thaiv koj tus kheej thiab cov ntaub ntawv ntiag tug los ntawm qhov muag pom lossis koj xav tau los ntawm lwm lub tebchaws. Kev xa khoom los ntawm lwm lub tebchaws tuaj yeem muaj txiaj ntsig zoo kom tau txais kev pabcuam uas tsis muaj hauv koj lub tebchaws. Muaj ntau tus VPN cov kev pabcuam tawm hnub no thiab feem ntau ntawm lawv muab yooj yim siv software rau koj lub khoos phis tawj thiab apps rau koj lub ntsiav tshuaj lossis xov tooj. Tab sis yog tias koj muaj lwm yam khoom siv tsis txhawb nqa los ntawm software uas koj xav mus hla lub VPN? Tom qab ntawd tsim lub rooj vag uas muab kev nkag tau rau internet rau koj hla VPN.

Yog tias koj saib koj lub network teeb tsa yooj yim koj muaj "lub qhov rooj tsis raug" uas yog siv rau ib qho ip-chaw nyob tsis nyob hauv koj lub subnet tam sim no (yooj yim heev). Yog li yog tias koj teeb lub rooj vag uas tuaj yeem hla kev siv internet hla kev tsim VPN txuas ib lub network uas siv tau lub cuab yeej tuaj yeem ua kom zoo dua VPN qhov.

Kuv qhov teeb meem loj hauv kuv chav nyob hauv San Francisco yog VPN qhov rau kuv haiv neeg Sweden yog li kuv tuaj yeem tso tawm Swedish ua si raws ntawm kuv cov media player thiab TV ntse. Nov yog rooj plaub siv zoo nkauj rau cov neeg feem coob xav tau VPN qhov. Txij li thaum kuv cov media player thiab TV ntse tsis tau txhawb nqa los ntawm VPN software Kuv tau tsim ib qho ntawm Raspberry Pi.

Koj tuaj yeem khaws ib qho rau qis dua $ 40 ntawm Amazon. Txawm li cas los xij kuv pom zoo tias koj yuav ib rooj plaub thiab tsim nyog lub hwj chim adapter ib yam. Rau qhov kev qhia no koj xav tau:

  • Raspberry Pi 2 lossis 3
  • Ib qhov xwm txheej uas koj nyiam
  • Ib lub hwj chim tsim nyog
  • Ib lub network cable

Kauj Ruam 1: Xaiv Koj Qhov Kev Pabcuam VPN

Xaiv Koj Qhov Kev Pabcuam VPN
Xaiv Koj Qhov Kev Pabcuam VPN

Qhov tseem ceeb thaum xaiv VPN kev pabcuam yog tias nws ua tau raws li koj xav tau. Txog qhov kev siv no kuv xav tau VPN kev pabcuam nrog lub ntsiab lus tawm ntawm Swedish, uas yog qhov tseem ceeb tshaj plaws txij li kuv xav tau cov kev pabcuam Swedish kom ntseeg tau tias kuv nyob hauv Sweden. Xyoo dhau los kuv tau siv ntau qhov sib txawv thiab hauv qab no yog yam uas kuv coj los txiav txim siab thaum xaiv lub VPN tus neeg xa khoom rau cov ntaub ntawv siv tshwj xeeb:

Kev xeem dawb

Kuv xav tau lub sijhawm sim dawb lossis cov ntaub ntawv ntsuas me me kom tau txais kev xav rau software lossis app. Tsis tas li kuv xav sim qhov ua tau zoo thiab kev paub dhau los ua ntej kuv them rau nws. Nws tseem zoo los txheeb xyuas tias kuv lub tswv yim yuav ua haujlwm ua ntej kuv pib them nyiaj.

Tsis pub twg paub

Yog tias kev nqis tes ua yog rau kev txhawj xeeb txog kev ceev ntiag tug ces nws tseem ceeb heev li txoj cai ntiag tug hais li cas. Nws tseem ceeb npaum li cas lub tuam txhab ua haujlwm los ntawm lub tebchaws thiab txoj cai twg uas tiv thaiv koj tus kheej. Kev txhawj xeeb txog tus kheej tiag tiag cov neeg siv yuav tsum saib cov kev pabcuam uas hais tias tsis muaj cov ntaub ntawv teev tsheb khiav mus los thiab tso nyiaj tsis qhia npe ntawm Bitcoin piv txwv.

Tso cai tsheb

Tej zaum yuav muaj kev txwv ntawm hom kev tsheb twg koj yuav raug tso cai khiav. Qhov loj tshaj qhov ua tiav feem ntau thaiv cov neeg sib tw-rau-phooj ywg. Qhov no tsis yog tsuas yog zam qhov teeb meem kev cai tab sis tuaj yeem tswj hwm kev ua haujlwm rau txhua tus neeg siv. Muaj pes tsawg tus neeg muab khoom lag luam zoo nyob ntawd uas tso cai rau phooj ywg-rau-phooj ywg thiab tseem xa kev pabcuam zoo. Tab sis yog tias tsis yog koj qhov kev rov zoo tseem ceeb Kuv pom zoo kom xaiv cov kev pabcuam uas tsis tso cai rau phooj ywg-rau-phooj ywg.

Cov ntaub ntawv cap

Tsis txhob siv qhov kev pabcuam uas khaws cov ntaub ntawv npog lawv cov neeg siv them nyiaj. Qhov no tsuas yog yuav tawm ntawm lub sijhawm phem tshaj plaws raws nraim li cov ntaub ntawv ntawm koj lub xov tooj ua ntej qhov lom zem hauv daim vis dis aus!

Tawm hauv lub tebchaws

Nyob ntawm qhov xwm txheej siv qhov no muaj qhov sib txawv tseem ceeb. Txog qhov xwm txheej siv zoo ib yam li kuv, qhov twg kuv xav tau xaus rau hauv ib lub tebchaws tshwj xeeb, tau kawg uas yuav tsum muaj nyob hauv cov npe. Kuv kuj yuav tsum raug tso cai xaiv lub tebchaws twg kuv tawm hauv. Muaj cov kev pabcuam uas koj tsis tuaj yeem xaiv lub tebchaws tawm, nyob deb ntawm cov ntawd. Koj tuaj yeem xaus rau hauv lub tebchaws nrog kev ua haujlwm tsis zoo lossis kev cai ntiag tug. Txawm hais tias koj tsis xav tau lub tebchaws tshwj xeeb koj tseem yuav tsum xaiv qhov kev pabcuam nrog ob peb lub tebchaws sib txawv los qhia los ntawm kev tuaj yeem nrhiav ib tus uas muaj kev ua tau zoo.

Hom software thiab txhawb nqa

Nov yog ib qho laj thawj tseem ceeb vim li cas kuv thiaj li nyiam cov kev pabcuam nrog kuaj dawb. Muaj ntau tus muab kev pabcuam nrog software tsis zoo uas yog kab laum, tsis nyab xeeb lossis tsuas yog tsis ua haujlwm. Txog kev siv Raspberry Pi Kuv xav tau tus muab kev pabcuam uas txhawb nqa OpenVPN.

Kuv xaiv

Rau qhov kev tsim no kuv tau mus nrog Tunnel Bear. Kev sim pub dawb txog 500GB raug muab yog li kuv tuaj yeem sim tias kuv tuaj yeem ua kwj ua ntej kuv them dab tsi. Lawv nyob hauv tebchaws Canada uas, ze rau Sweden, muaj qee qhov kev cai lij choj uas muaj zog tshaj plaws hauv ntiaj teb. Tsis muaj cov ntaub ntawv khaws tseg ntawm cov kev pabcuam them nyiaj thiab kuv tseem tso cai kom muaj ntau lub cuab yeej txuas nrog ib zaug. Yog li kev tiv thaiv rau kuv lub xov tooj, ntsiav tshuaj thiab khoos phis tawj thaum mus ncig ntawm qhov tsis ruaj ntseg wifi tau txheeb zoo ib yam. Tawm ntawm qhov nyob hauv Sweden tau txais kev txhawb nqa, nws tau muab los ntawm Bahnhof uas paub txog kev muaj zog ntiag tug hauv Sweden. Txog cov phiaj xwm them nyiaj lawv muab OpenVPN txhawb nqa. Lawv tsis ua rau kev sim dawb tab sis nws txaus los khiav qhov ntawd los ntawm kuv lub laptop kom paub tseeb tias cov kev pabcuam streaming tau ua haujlwm.

Kauj ruam 2: Nruab Raspberry Pi

Txog kev coj ua zoo li no kuv siv Raspbian Lite kev ua haujlwm. Txij li thaum kuv tsis xav tau GUI txhua. Koj tuaj yeem tau txais qhov kev tshaj tawm tshiab ntawm no.

Kuv siv Win32DiskImager thauj cov ntaub ntawv.img ntawm SD-card rau Raspberry Pi.

Thaum Raspberry Pi tau khau raj Kuv saib hauv kuv tus routers DHCP daim ntawv kom tau tus IP-chaw nyob thiab tom qab ntawd txuas dua SSH nrog Putty. Tus qauv siv lub npe thiab tus lej zais yog pi/raspberry

Thaum txuas nrog kuv khiav lub cuab yeej raspi-teeb tsa txhawm rau hloov cov teeb tsa yooj yim.

sudo raspi-teeb tsa

Qhov tseem ceeb tshaj plaws los saib xyuas hauv qhov teeb tsa no yog:

  • Nthuav cov ntaub ntawv kaw lus
  • Hloov tus password

Koj kuj tseem tuaj yeem hloov lub npe hostname ntawm koj Raspberry Pi yog tias koj nyiam. Kuv DHCP muaj cov ntawv xaum ntev heev thiab kuv tseem tuaj yeem khaws qhov chaw nyob tshwj xeeb. Yog tias koj tsis muaj lub peev xwm ntawd koj yuav tsum teeb tsa Raspberry Pi kom siv IP-chaw nyob zoo li qub. Txij li lwm cov khoom siv yuav siv qhov no raws li muaj lub qhov rooj tsis raug nws yog qhov tseem ceeb uas nws tseem siv tib tus IP-chaw nyob. Nov yog kab ntawv kuv tau sau txog teeb tsa IP zoo li qub hauv Raspbian Jessie.

Tom qab ntawd peb yuav tsum hloov kho txhua yam mus rau qhov hloov tshiab kawg:

sudo apt-tau hloov tshiab sudo apt-tau hloov dua tshiab sudo apt-tau txais-deb-upgrade

Kauj ruam 3: Nruab OpenVPN

Nruab OpenVPN
Nruab OpenVPN

Tam sim no peb yuav tsum teeb tsa OpenVPN ntawm Raspberry Pi.

sudo apt-tau nruab openvpn

Tom qab ntawd peb yuav tsum ua kom ntseeg tau tias qhov kev pabcuam pib zoo.

sudo systemctl qhib openvpn

Thaum qhov kev teeb tsa tiav peb yuav tsum luam theej tawm OpenVPN teeb tsa cov ntaub ntawv thiab daim ntawv pov thawj rau hauv lub thawv. Qhov no yuav muab rau koj los ntawm koj tus kws kho mob VPN. Hauv kuv qhov xwm txheej, siv TunnelBear, Kuv pom muaj blog tshaj tawm txog Linux Kev Txhawb Nqa. Ntawm nplooj ntawv ntawd muaj qhov txuas rau zip cov ntaub ntawv uas muaj txhua yam peb xav tau.

Cov ntaub ntawv muaj cov ntaub ntawv pov thawj thiab.opvn cov ntaub ntawv teeb tsa rau txhua lub tebchaws koj tuaj yeem nkag mus rau. Koj xav tau txhua daim ntawv pov thawj cov ntaub ntawv thiab.opvn cov ntaub ntawv teeb tsa rau lub tebchaws uas koj xaiv, hauv kuv rooj plaub Sweden. Unzip cov ntaub ntawv xav tau thiab siv winscp txhawm rau upload cov ntawv rau koj li Raspberry Pi. Tib lub npe siv/tus lej siv raws li siv rau SSH yuav coj koj mus rau/tsev/pi, cia li tso cov ntawv nyob ntawd.

Tom qab ntawd peb rov qab mus rau SSH lub davhlau ya nyob twg thiab txav cov ntaub ntawv mus rau OpenVPN nplaub tshev. Thawj lo lus txib tsuas yog kom ntseeg tau tias peb nyob hauv /home /pi folder.

cd /home /pib

sudo mv */thiab/openvpn/

Tam sim no peb yuav tsum tau ua qee qhov kev hloov kho rau cov ntaub ntawv. Ua ntej peb yuav tsum hloov pauv cov ntaub ntawv teeb tsa los ntawm.ovpn rau.conf. Txhua cov ntaub ntawv xaus rau hauv.conf hauv /etc /openvpn nplaub tshev yuav cia li pib thaum OpenVPN daemon tau pib. Ua ntej peb yuav tsum nkag mus rau hauv cov npe ntawd.

cd /thiab /openvpn

Tom qab ntawd peb hloov lub npe ntawm cov ntawv teeb tsa. Koj tuaj yeem sau nws txhua yam koj xav tau tsuav nws xaus rau hauv.conf. Kuv nyiam siv cov npe cov ntaub ntawv yam tsis muaj qhov khoob, qhov no kuv yuav mus nrog swe.conf.

sudo mv *.ovpn swe.conf

Tom qab ntawd peb xav tau cov ntaub ntawv pov thawj uas muaj lub npe siv thiab tus lej siv rau VPN qhov. Qhib tus kws sau ntawv sau thiab sau lub npe siv thiab tus lej zais ntawm kab sib cais. Peb yuav hu rau cov ntawv no auth.txt.

sudo nano auth.txt cov

Cov ntsiab lus yuav tsum zoo li qhov piv txwv no:

lub npe siv

lo lus zais

Tom qab ntawd siv CTRL + O los sau rau hauv cov ntawv thiab CTRL + X kom tawm ntawm nano text editor. Peb kuj yuav tsum tiv thaiv cov ntaub ntawv auth.txt uas muaj peb daim ntawv pov thawj.

sudo chmod 600 /etc/openvpn/auth.txt

Tom qab ntawd peb yuav tsum hloov kho cov ntaub ntawv teeb tsa kom ntseeg tau tias txhua txoj hauv kev raug thiab ntxiv qhov kev siv rau cov ntaub ntawv tsim tshiab auth.txt.

sudo nano swe.conf

Cov kab uas yuav tsum tau hloov pauv yog cov uas xa mus rau lwm cov ntaub ntawv, lawv yuav tsum yog txoj hauv kev meej. Hauv qhov piv txwv no yog qhov peb tab tom nrhiav:

ca CACertificate.crt

cert UserCertificate.crt qhov tseem ceeb PrivateKey.key

Peb hloov lawv mus rau txoj kev ncaj ncees zoo li no:

ca /etc/openvpn/CACertificate.crt

cert /etc/openvpn/UserCertificate.crt qhov tseem ceeb /etc/openvpn/PrivateKey.key

Tom qab ntawv kawg ntawm cov ntawv peb ntxiv qhov siv rau daim ntawv auth.txt, zoo li no:

auth-user-pass /etc/openvpn/auth.txt

Ib zaug ntxiv peb siv CTRL + O los khaws cov ntawv thiab tom qab ntawd CTRL + X kom tawm nano. Tam sim no peb tuaj yeem rov qhib OpenVPN daemon thiab pom tias qhov av ua haujlwm.

sudo kev pabcuam openvpn rov pib dua

Yog tias koj khiav cov lus txib ifconfig koj yuav tsum pom lub tun0 adapter ntxiv rau koj eth0 thiab lo adapters yog tias lub qhov nkag mus. Koj kuj tseem tuaj yeem khiav qhov kev hais kom ua no los tshuaj xyuas koj tus IP pej xeem:

wget https://ipinfo.io/ip -qO -

Yog tias koj muaj teeb meem tau txais lub qhov taub ua ntej sim rov pib dua koj li Raspberry Pi thiab tom qab ntawd ob zaug txheeb xyuas qhov teeb meem rau qhov ua yuam kev.

Kauj Ruam 4: Teeb Txoj Kev

Tam sim no peb yuav tsum pab kom IP xa mus. Nws ua kom cov kev sib txuas hauv network ntws los ntawm ib qho ntawm lub network cuam tshuam thiab tawm mus rau lwm qhov. Yeej tsim lub router.

sudo /bin /su -c "echo -e '\ n#Pab IP Routing / nnet.ipv4.ip_forward = 1'> /etc/sysctl.conf"

Yog tias koj khiav sudo sysctl -p koj yuav tsum pom qhov no luam tawm ntawm lub vijtsam:

net.ipv4.ip_forward = 1

Tam sim no txoj kev tau qhib thiab cov tsheb tuaj yeem hla Raspberry Pi, hla qhov av thiab tawm hauv is taws nem.

Kauj ruam 5: Teeb Firewall thiab NAT

Txij li thaum peb yuav muaj ntau tus neeg siv khoom sab hauv nkag mus siv internet hla ib tus IP chaw nyob pej xeem peb yuav tsum siv NAT. Nws sawv cev rau kev sib tham chaw nyob txhais lus thiab yuav taug qab seb tus neeg thov kev thov li cas thaum cov ntaub ntawv rov qab hla lub qhov. Peb kuj yuav tsum teeb tsa qee qhov kev nyab xeeb nyob ib puag ncig Raspberry Pi nws tus kheej thiab qhov av.

sudo iptables -t nat -A POSTROUTING -o tun0 -j MASQUERADE

Enabling NAT.

sudo iptables -A FORWARD -i eth0 -o tun0 -j ACCEPT

Tso cai rau kev khiav tsheb los ntawm eth0 (sab hauv) mus hla tun0 (qhov av).

sudo iptables -A FORWARD -i tun0 -o eth0 -m xeev -xeev RELATED, ESTABLISHED -j ACCEPT

Tso cai tsheb los ntawm tun0 (qhov av) kom rov qab hla eth0 (sab hauv). Txij li thaum peb hais qhia lub xeev RELATED, ESTABLISHED nws yuav raug txwv rau kev sib txuas pib los ntawm kev sib tham sab hauv. Thaiv lwm cov tsheb khiav los pib ua qhov txuas tshiab.

sudo iptables -A INPUT -i lo -j ACCEPT

Tso cai rau Raspberry Pi tus kheej txoj kev tsheb khiav rov los.

sudo iptables -A INPUT -i eth0 -p icmp -j ACCEPT

Tso cai khoos phis tawj ntawm lub network hauv cheeb tsam kom ping Raspberry Pi.

sudo iptables -A INPUT -i eth0 -p tcp --dport 22 -j ACCEPT

Tso cai SSH los ntawm sab hauv network.

sudo iptables -A INPUT -m xeev -xeev ESTABLISHED, RELATED -j ACCEPT

Tso cai rau txhua lub tsheb pib los ntawm Raspberry Pi rov qab los. Nov yog tib lub xeev tus thawj xibfwb li yav tas los.

sudo iptables -P FORWARD DROP

sudo iptables -P INPUT DROP sudo iptables -L

Yog tias tsheb tsis zoo ib yam ntawm cov cai tau teev tseg nws yuav raug tshem tawm.

sudo apt-tau nruab iptables-persistent

sudo systemctl pab netfilter-persistent

Thawj kab teeb tsa kev thaj yeeb ntawm cov cai uas ua rau txoj cai iptable peb nyuam qhuav tsim tsis tu ncua ntawm kev rov pib dua. Qhov thib ob txuag txoj cai tom qab koj hloov lawv. Lub sijhawm no nws txaus los khiav thawj zaug. Yog tias koj hloov txoj cai khiav qhov thib ob kom txuag. Iptable cov cai tau siv sai li sai tau thaum koj ntxiv lawv yog tias koj cuam tshuam thiab poob kev nkag mus tsuas yog rov pib dua thiab cov uas tsis tau txais kev cawmdim yuav rov qab los.

Kauj Ruam 6: Xaus

Tam sim no koj tuaj yeem siv lub qhov no los ntawm ib lub cuab yeej lossis khoos phis tawj ntawm tib lub network. Tsuas yog hloov lub qhov rooj tsis raug rau txhua tus IP-chaw nyob uas koj Raspberry Pi muaj. Hauv kuv qhov xwm txheej ob qho kuv Kodi media chaw (ib chav pw thiab ib chav nyob) siv qhov kev sib txuas no yog li kuv tuaj yeem tso kuv li Swedish ua si raws. Tau kawg muaj lwm yam uas koj tuaj yeem siv rau qhov no ib yam.

Tsuas yog nco ntsoov tias nyob ntawm VPN tus neeg xa khoom koj tau xaiv thiab qhov nrawm ntawm koj li kev txuas hauv is taws nem yuav muaj kev ua haujlwm qeeb.

Yog tias koj muaj lus nug lossis xav kom kuv qhia meej dab tsi qhia rau kuv paub hauv cov lus! Yog xav paub ntau tshaj tawm xov xwm thov mus ntsib kuv blogg Hackviking!

Pom zoo: