Score:0

Connecting to VPN automatically

cn flag

Hello I have the problem that I want to connect my computer automatically to a VPN which I use personal and only I am using no other people.

In my case the network name changes every time while I am traveling a lot and use a lot of USB tethering and other networks on the way.

I want my computer to connect directly to my VPN which I am using. Even to Wireless and Wired Connections I have never been connected to.

To Networks my Computer once was connected to I know how to auto-connect to my VPN. But for me is more important to set up computer that it will connect to the VPN even for new connections he was never been connected to.

I am using Ubuntu 18.04 LTS and openvpn. I hope it is understandable

Thanks for your help

ar flag
Welcome to Ask Ubuntu. Please [edit your question](https://askubuntu.com/posts/1356752/edit) and add the following information: 1. Which distro and version of Linux are you using? Are you using a corporate VPN (office VPN) or a consumer VPN? What do you mean by "how to set up auto-connect the vpn to a specific network?" can you describe this process? What do you mean by a "specific network"? Do you mean a specific WiFi hotspot, or a specific Ethernet connection? Without more information your question is not answerable.
Theo Jaasp avatar
cn flag
Sorry for that. I exactly don't know how to explain but I hope you can understand it now
John Ronald avatar
ca flag
If your VPN has command, that could launch it from terminal, and if your OS still uses /etc/network/interfaces (instead of netplan), you could use post-up option in the configuration file.
ar flag
Most consumer VPNs that support Linux have a command line option for this feature. Check with your VPN provider's support web page.
Theo Jaasp avatar
cn flag
@JohnRonald is there some documantation how to do it?
John Ronald avatar
ca flag
@TheoJaasp First you need to find out, if there is a command, that would launch your VPN. Then check file /etc/network/interfaces. After that try this - https://askubuntu.com/questions/1030048/how-to-create-post-up-and-pre-down-routes-in-interfaces-file. If you were to struggle with this, We can have a chat in a chatroom.
ar flag
For documentation, look at your VPN service provider, such as NordVPN, ExpressVPN, etc. Each one is different. Which one did you buy?
heynnema avatar
ru flag
What VPN provider? Do you have .ovpn files for your VPN connections? Are you able to use terminal to connect to your VPN? Do you have an application to connect your VPN? If you have .ovpn files, the fix is easy.
Theo Jaasp avatar
cn flag
@heynnema I use OpenVPN but my provider is Protonvpn. I only have the .ovpn file
Theo Jaasp avatar
cn flag
@JohnRonald thanks. I will have a look and try out if I can fix this.
heynnema avatar
ru flag
@TheoJaasp Status please...
Theo Jaasp avatar
cn flag
@heynnema sorry for the late answer. I tried out but I don't know there was some system related error. So that wasn't working out. But I found a different solution. I used the nmcli command tou build a script around it and check every 10s for that specific vpn connecten if its not connected it will reconned. Independent of network name
Score:1
ru flag

No guarantees, but try a variation of this...

# drop into /etc/network/interfaces

# change eth0 if required
# change /path/to/protovpn.ovpn to the correct path and filename
auto eth0
iface eth0 dhcp
        post-up openvpn /path/to/protonvpn.ovpn

# change wlpxxxx to the name of your wireless device
# change /path/to/protovpn.ovpn to the correct path and filename
auto wlpxxxx
iface wlpxxxx dhcp
        post-up openvpn /path/to/protonvpn.ovpn

Then reboot.

Theo Jaasp avatar
cn flag
I will take a look at your advice and see if I can get it working. But I noticed that you told me to insert the wifi-network name. But that's in my case not possible because the name is changing every time. I am using a wired connection. But as soon it looses VPN connectection it changes the name from Wired Connection 1 to Wired Connection 2. When I reconnect the Wired Connection 2 to the VPN and it looses connection there it changes the name to Wired Connection 3 and so on..
heynnema avatar
ru flag
@TheoJaasp I didn't tell you to insert the wifi network name anywhere. I understand that the wifi name may change from your problem description. I asked you to change the wireless device name from my example wlpxxxx, and the path to your .ovpn file. More questions? Please ask.
heynnema avatar
ru flag
@TheoJaasp Your wired connection is a different problem. Delete Wired Connection 1 and Wired Connection 2, etc. Leave only one "Wired Connection".
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.