jamesmcm / vopono

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

Force creating a new namespace? #232

Closed 097115 closed 1 year ago

097115 commented 1 year ago

When vopono finds an existing namespace, it proceeds to using it.

Is it possible to force it to create a new one?

jamesmcm commented 1 year ago

Not at the moment - although you could do it by treating the config file as a custom provider.

It'd be simple to add though, as a flag here - https://github.com/jamesmcm/vopono/blob/master/src/exec.rs#L348-L364 and then also adding some randomness to the netns name generation - https://github.com/jamesmcm/vopono/blob/master/src/exec.rs#L284-L293

What is the use case though - compared to sharing the network namespace?

097115 commented 1 year ago

you could do it by treating the config file as a custom provider

Thanks, this solves it for me :). Sorry that I missed it.

What is the use case

It's nothing significant, just experimenting a bit. Certainly not a reason for any additional code, so I'm probably closing this?

BTW, while we at it, is there any way from within a vopono's namespace to get the current namespace's name (or, even better, the host_ip)? I came up with this (for a Bash script):

IP=$(grep -R -o 'host_ip:"[0-9.]*"' $XDG_CONFIG_HOME/vopono | \
     awk -v FS='"' -v N=$(ip netns identify $$) '($0 ~ N){print $2; exit}')

But maybe there's a better way?

jamesmcm commented 1 year ago

Hmm depending what you need it for - it is available to the host scripts - https://github.com/jamesmcm/vopono/blob/master/USERGUIDE.md#configuration-file

leandrovianna commented 6 months ago

Sorry to reply to an older issue, but I would like some feature like this.

My use case is that I have a lot of *.conf files for Mullvad. I start transmission-daemon with one of them and want to use firefox with another, but vopono use the same namespace of transmission in firefox, even if I specify a different *.conf file, so I can't use a different IP in this case. This only happened when the *.conf files are in the same directory.

097115 commented 6 months ago

@leandrovianna

Not sure if I got you right but you can specify a namespace either via a vopono .toml config, or via exec's --custom-netns-name option. I run exactly firefox and transmission in different namespaces all the time :) (with --custom anf *.ovpn files, though).

leandrovianna commented 6 months ago

@leandrovianna

Not sure if I got you right but you can specify a namespace either via a vopono .toml config, or via exec's --custom-netns-name option. I run exactly firefox and transmission in different namespaces all the time :) (with --custom anf *.ovpn files, though).

Thank you, your suggestion works well for me. I have a script that chose the *.conf file, so I can use --custom-netns-name with the *.conf file name and I can separate a namespace for each file. Thank you for the help.