My Linux server works with YouTube videos a lot, downloading and collecting data about them with the help of youtube-dl.

I want to route this program (youtube-dl) through an OpenVPN connection. Seems simple enough, except I need only youtube-dl to use the VPN connection, as I also run a web server among other things which cannot use the VPN connection.

How can I configure my server to only use the OpenVPN connection for youtube-dl?

Without a separate VM.

  • 1
    Is Docker out of question, too? Apr 3 at 5:28
  • On the networking / routing level your options are either: Policy routing (when you know exactly which IP’s are used by your app to download videos from) Network name spaces (which is a pita to set up manually)
    – Bob
    Apr 3 at 7:01
  • @HermanB Policy routing isn't really feasible, as sometimes youtube-dl will also fetch media from other arbitrary sources. Let me look more into network namespaces, thanks! Apr 3 at 9:36
  • You can look at firejail, despite its name it can work with other programs than Firefox, and "enclose" them in various limits, including a networking namespace which should be the ideal option for your problem. See firejail.wordpress.com/documentation-2/basic-usage/#networking Apr 3 at 22:15
  • Can you explain how this could be useful, as U-tube probably isn't part of your VPN? Apr 4 at 16:50

I forgot I asked this question, but I may as well leave the solution I ended up using here:

You can use a program called Vopono that works by creating temporary network namespaces.

It supports the Wireguard, OpenVPN, OpenConnect and OpenFortiVPN protocols, and can also be used out-of-the-box directly with many VPNs such as PIA and NordVPN as well, if that suits your needs.

Example usage with an OpenVPN configuration file:

vopono exec --custom vpn_config.ovpn --protocol openvpn "youtube-dl https://www.youtube.com/watch?v=dQw4w9WgXcQ"

No VM or anything like that needed!

More detailed usage info can be found here.


You can create a virtual machine that connects to the VPN and run the program in that VM.

  • apparently, this was answered before the additional requirement appeared, and for majority of cases this is acceptable solution Apr 6 at 7:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.