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.