VPN一切! OpenVPN網關教程



說明和示例文件可在以下位置找到:https://drive.google.com/open?id=1xz6Ek2ZE3YwkUUoR2qot3849PjT3b8Rm

膩子下載:https://www.chiark.greenend.org.uk/~sgtatham/putty/latest.html

但是在我們開始之前…我在喝什麼???

沒有名字的家庭食譜…建議。它是2盎司菠蘿汁,2盎司白朗姆酒,1/2盎司簡單糖漿和一匙檸檬汁。搖晃直至菠蘿起泡。這是一種非常奶油和光滑的熱帶飲料,非常適合炎熱的一天。

本教程將教您如何在家庭網路上創建VPN網關。要求是要運行的基於Linux的系統,以及與OpenVPN兼容的VPN服務。我個人使用NordVPN(未贊助),但是任何兼容的服務都可以使用。

要將設備連接到VPN網關,必須在客戶端上配置靜態IP地址。具體操作方法因設備而異。網關IP地址只需要指向您的VPN網關伺服器。

此服務將僅允許VPN流量離開您的網路。如果VPN連接斷開,您的客戶端設備也會斷開。只需重新啟動VPN連接(或重新啟動VPN伺服器)即可重新連接。如果失敗,也可以設置CRON作業以自動重新啟動VPN連接。

在我的亞馬遜商店中找到我推薦的零件:https://www.amazon.com/shop/craftcomputing

在Twitter上關注我@CraftComputing

在Patreon上為我提供支持,並可以訪問我的專有Discord伺服器。整整一周與我和其他主持人在Talking Heads上聊天。 https://www.patreon.com/CraftComputing

在Ubuntu論壇上,我從以下位置複製了大多數IPTables配置:https://ubuntuforums.org/showthread.php?t=2399250

來自https://filmmusic.io的音樂:
凱文·麥克勞德(Kevin MacLeod)的「春天的陰影」(https://incompetech.com)
許可證:CC BY(http://creativecommons.org/licenses/by/4.0/)。

49 comments
  1. Nice and easy guide. Thanks. Thou, it is not complete when running Ubuntu 18.04 as the OpenVPN is not forwarding DNS. It bypasses the runnel and leaks DNS information.. Can you comment on it, e.g do you have a fix for it?

  2. Thank you so much for this awesome tutorial! I used Ubuntu Server 19.10.1 for the Raspberry Pi 4 2GB Model and it works!

  3. Thanks for this… I am looking for something like this to use with my Smart TV.
    But one thing is not 100% clear for me: Can I just plug in the Raspberry into my Router (Fritzbox) via Ethernet and connect the TV via Wifi to my home network and only put the Gateway IP of the VPN into the TV? So no physical or direct Wifi connection to the Raspberry needed by the TV?

  4. I'm really enjoying your videos. Not sure if you're still using freeNAS but a video idea I would appreciate is how to access applications running in a FreeBSD jail from outside a home network securely. Either accessing via OpenVpn or a reverse proxy over TLS.

  5. Hey I've tried it but I get an error when enabling the service:

    ubuntu@ubuntu:/etc$ sudo systemctl start rc-local.service

    Job for rc-local.service failed because the control process exited with error code.

    See "systemctl status rc-local.service" and "journalctl -xe" for details.

    Can you please help?

  6. Hey,

    Do you know of a way to monitor the VPN connection? I don't constantly use it, but I'd like to know if the VPN goes down while not utilizing it.

  7. Falls ihr bei Swisscom seid und mit Raspberry Pi einen VPN machen möchtet, müsst ihr erst bei Swisscom anrufen. Die weisen euch dann eine spezielle IP-Adresse zu und nur mit der ist es möglich. Kein Scherz. 10.11.2019

  8. Great video, i try so many tutorial to do something like this on proxmox.
    I try to build a seedbox with a killswitch for the vpn, but alltogether, i didn't know you can just use a vm with a vpn on it like a gateway for a other machine, so mutch easy to setup.

  9. @all
    I think some of you might end up my rabbit hole and getting error messages at the end of tutorial
    Please change /etc/rc.local to executable

    sudo chmod +x /etc/rc.local

  10. without the iptables.sh (BUT with the ip_forward enabled), client using the gateway can't reach the internet.
    Also, if beforehand i launch the iptables.sh, when i run openvpn (connect.sh) it keeps on giving me:

    write UDP: Operation not permitted (code=1)
    openvpn 2.4.6
    openssh-server 1:7.9p1-10
    on Ubuntu server 19.04

    Any help?

  11. I run iptables.sh and everything stops working. if I run just openvpn it works fine but can't connect from another machine. the second i run iptables i get "write UDP: Operation not permitted (code=1)" and (Temporary failure in name resolution)

  12. When I'm thinking privacy I had an idea, Think of A PFSENSE BOX and you can plob several boxes connected to several HIGH SPEED ISPs. Now each box has it's own public IP that has a spoofed MAC ADDRESS TO OBTAIN A RANDOM PUBLIC IP. Now if you can install the program MACCHANGER to the WAN PORT ADAPTER to randomize it's MAC ADDRESS and obtain a new public IP, but this only happens when a user of these randomized PFSENSE BOXES that point to ech other via OSPF to your address, email, or other desti ation domain your trying to connect to. Now to further complicate the anominity all boxes are set up by OpenVPN ,and has each boxs UPDATED ROUTING TABLE THAT RESETS AT EACH ESTABLISHED CONNECTION PACKET BY PACKET. This can create a bunch of overhead but if there is a way to randomize the route by OSPF then by In ORDER down the line then back by a randomization through an algorithm? Also I probably would have a constant DD script that can write garbage to it's log files?!?! Coulld something like that be accomplished?

  13. Hey! Great Video. VPN works like a charm. I cant get the last command to work. when i start the rc-local – i get "job for rclocal.service failed because control process exited with error code" I checked the script – it is copy and paste from yours?

    in log i see: rc-local.service: Failed to execute command: Permission denied
    .

  14. Will this slow down the internet speed at home? How about VPN client setup for you away from home and connect to home using VPN setup?

  15. Great guide, with this i finally got the VPN gateway to work, but i have some questions.

    After server reboot, when the server starts my computers can access internet for a few pings, exposing my ISP IP until the VPN starts, is there anything we can do about that?

    What if my VPN gateway is on subnet 192.168.50.0/24 but my router is on 192.168.1.0/24, do i need to create a route or iptable for that? and how do i do it?

    I had problems to create a static route from 192.168.50.0/24 to this device while on 192.168.1.0/24 in my USG 3p, so need to find another solution

  16. Great tutorial. Very succinct and to the point. I also really liked your tutorial on ad blocking the whole house. I just need to set up Nextcloud and these two and I'll be set. 🙂

  17. I'm having slight issues here, when enabling and running the rc-local.service, it constantly is trying to save the iptables,(constant save done being printed to the terminal) the vpn works, but snail pace(5 down 1 up on a 40/10 connection) any ideas?

  18. It is truly brave apply netplans without testing and lost the ssh connect with typos. 😀 Thanks for a good video. Is there any reason to not to use permanent chances on iptables?

  19. Hi Jeff! Great video tutorial. I've been running an openvpn server when needed on my main system up until now but I've been wanting to migrate it to my FreeNAS server for a while now.
    I see you have an InWin 301 case on your desk and I am curious to know how you setup the fans (seeing as I have one myself). Do you have 2 bottom intake fans, 2 front exhaust fans and one rear exhaust? I've noticed despite my best cable management attempts that the exhaust area on the right of the case behind the honeycomb mesh is quite air restrictive. I cannot seem to be able to dump hot air out of the case quickly enough whilst gaming.

  20. When using and email "In auth.txt" as username the connection fails to connect with status "Auth Failed", when passing the username and password manually connection works … any suggestions on how to bypass this? could be a character (@) on the username that makes it fail?

  21. You don't need to type sudo bash every time. You can just type sudo <script> as you've defined the shell within the script with the #!. You just need to make the script executable with chmod +x <script>

  22. 'gateway4' doesn't need to be in brackets because it's not an array; you can't have more than one gateway. the other fields can support multiple entries per line, whether you use them or not.

  23. Real questions – how do you daisy chain OpenVPN VPNs? Because there are issues with default gateway settings when you connect to VPN while being already connected to different VPN.

  24. Excellent tutorial. I came here because I'm interested in making a local VPN for other reasons. Couple comments:

    The sysctl port forwarding would be better in a static file /etc/systctl.d/40-portforwarding.conf would be okay
    echo "net.ipv4.ip_forward net.ipv4.ip_forward = 1" > /etc/systctl.d/40-portforwarding.conf

    It'll now apply this setting on boot.
    Then sysctl -p to enable it for the session (or reboot is fine)

    Then you don't have to run the sysctl command in your start script.

    Meanwhile, the /etc/rc.local hack was just… No..
    Put the script in /usr/local/bin/startvpn.sh and use systemd properly 😀

  25. Yaml square brackets denote arrays or lists. You can have multiple address and multiple nameservers so they're in brackets. You can only have one gateway so there are no brackets

Comments are closed.