jamesmcm / vopono

Run applications through VPN tunnels with temporary network namespaces
GNU General Public License v3.0
888 stars 46 forks source link

Separated namespaces for each Mullvad devices #272

Closed nosferatus96 closed 5 months ago

nosferatus96 commented 5 months ago

I'd like some clarification as I am somewhat a beginner in programming, my goal is to run two different python scripts under different VPN namespaces so that each are independent of one another and each are representing a different Mullvad device, e.g one script is using Mullvad .conf files with port 51810 with an IP from Sweden, the other script is using Mullvad .conf files with port 51820 with an IP from Canada, all under the same environment.

Running $ vopono sync allows me to create .conf files for one account, how about creating two sets of .conf files and being able to manually select which one I want when running e.g $ vopono exec --provider mullvad --server sweden --protocol wireguard firefox.

jamesmcm commented 5 months ago

Note that Mullvad no longer supports port forwarding.

But the --server flag lets you choose which config file to use, so you could just generate them twice copy them and copy the different ones back if you do need different settings.

But in general:

vopono exec --provider mullvad --server sweden --protocol wireguard "python script1.py"
vopono exec --provider mullvad --server canada --protocol wireguard "python script2.py"

Should work.

nosferatus96 commented 5 months ago

Works well with the scripts, I was originally testing with two instances of Firefox but I read through the past issues brought up and realized it's not just me, nor your code really, just Firefox having some restrictions I take it.

The scripts I am using vopono with are meant to be running for an indefinite amount of time, and after some time I have to reset the script and change IP, manually, I can just Ctrl-C out from vopono and re-enter the same command over again, works flawlessly, it always selects a new node/IP by default. When doing it automatically via my script it get a little more problematic, I'm trying to simulate the Ctrl-C input and then using subprocess to create a new instance but the new namespace doesn't get configured correctly when the command is started via my script:

Error: Failed to add iptables masquerade rule, ip_mask: 10.200.1.0/24, interface: vo_mv_sweden_s@if116

Caused by: Command failed: iptables -t nat -A POSTROUTING -s 10.200.1.0/24 -o vo_mv_sweden_s@if116 -j MASQUERADE

Nonetheless thank you for your continuous support, I wish you could allow us to sponsor you in order to show support for your work.

nosferatus96 commented 5 months ago

Actually just a bash script running the Vopono exec command in a while loop does the trick, just exiting out from the program when needed, changes IP and restarts the script.

jamesmcm commented 5 months ago

Yeah, exactly I would use a bash script to manage that.