3

I am using Linux Mint 19.3

I want to run two instances of youtube-dl.

All traffic of terminal 1 instance should go through regular network.

All traffic of terminal 2 instance should go through VPN.

Is there any command that will enable terminal 2 to use VPN connection for all future commands? In other words, Is there any command which will instruct terminal 2 to use VPN connection for all future commands?

I found Bind unix program to specific network interface, But I want to bind VPN in specific terminal for all future initiated programs, not a particular program.

What I want is, open a terminal and run youtube-dl to work with regular connection. However, If I enable VPN (through a command) and run youtube-dl then youtube-dl will work through VPN connection.

So, the possible end result being, two instance of same program, one through regular network, another through VPN, where the network selection is real-time and not predefined (through routing table or anything like that).

I found a tool vpnns, but not sure if this is what I am looking for or is there a better solution.

Ahmad Ismail
  • 2,678

2 Answers2

3

What you are asking has already been answered on StackExchange: Bind unix program to specific network interface. I believe the solution using App-Route-Jail will solve it for you. You can't exactly bind a terminal window to a VPN, I believe, but you can force a program to use a specific network interface up on execution.

If it's of any help, you can create a wrapper shell script for youtube-dl with correct command args to force it to use VPN and use that shell script in terminal 2 for usage with VPN.

Example of such shell script (requires POSIX shell, e.g Bash)

#!/bin/bash
MARK=10 LD_PRELOAD=./mark.so /path/to/youtube-dl "$@"

Note that this will require you to have rely on two executables, one which will always work through normal network and another that will always go through VPN.

ColdIce
  • 76
  • 3
3

You cannot "instruct terminal 2 to use a VPN connection for all future commands".

However, you can make a new network namespace, run your VPN in that namespace or move the VPN network interface into that namespace (possibly after connecting it up in a suitable way to the main network namespace and/or your physical network interface), then start a new terminal window in this network namespace, and have all commands use the VPN by connection (and only the VPN connection).

There's plenty of tutorial on network namespaces, google. The main command you'll need is ip netns. You'll also need enough understanding of networking basics to connect up the network namespace.

And yes, vpnns works in a very similar way.

dirkt
  • 32,309