Auto reconnect to VPN on disconnect?
I'm an Ubuntu GNOME user and I was wondering if there is a way to be able to automatically reconnect to a VPN on disconnection. I'm using the OpenVPN protocol.
I've checked Network Manager thoroughly but could not find such an option, only to connect to the VPN when connected to a specific WiFi.
vpn ubuntu-gnome
add a comment |
I'm an Ubuntu GNOME user and I was wondering if there is a way to be able to automatically reconnect to a VPN on disconnection. I'm using the OpenVPN protocol.
I've checked Network Manager thoroughly but could not find such an option, only to connect to the VPN when connected to a specific WiFi.
vpn ubuntu-gnome
add a comment |
I'm an Ubuntu GNOME user and I was wondering if there is a way to be able to automatically reconnect to a VPN on disconnection. I'm using the OpenVPN protocol.
I've checked Network Manager thoroughly but could not find such an option, only to connect to the VPN when connected to a specific WiFi.
vpn ubuntu-gnome
I'm an Ubuntu GNOME user and I was wondering if there is a way to be able to automatically reconnect to a VPN on disconnection. I'm using the OpenVPN protocol.
I've checked Network Manager thoroughly but could not find such an option, only to connect to the VPN when connected to a specific WiFi.
vpn ubuntu-gnome
vpn ubuntu-gnome
asked Sep 27 '15 at 17:24
Inoki
3232516
3232516
add a comment |
add a comment |
6 Answers
6
active
oldest
votes
OpenVPN has a build-in mechanism to automatically detect dead links and reconnect. In Network Manager go to "Edit Connections", select your VPN connection and choose "Edit". In the "VPN" tab click on "Advanced..." and go to the "General" Tab. There you have two relevant options:
"Specify ping interval" tell OpenVPN how frequently to check if the link is still alive. "Specify exit or restart ping" tells it how long to wait until it takes action and which action to take.
Example: My setting are "30 / ping-restart / 300". This means OpenVPN checks every 30 seconds if the link is still active. If the link is down for 300 seconds it initiates a restart.
This way there is no need for external scripts...
This should be the accepted answer.
– necbot
Sep 12 '17 at 1:50
3
This is not true for Ubuntu 18.04 at least. I have ping interval and ping-restart but it will disable itself anyway.
– Sarge Borsch
Aug 13 at 9:42
add a comment |
After a bit of digging I found this answer, tested it (on Ubuntu GNOME 15.04) and so far it seems working.
The only thing I might add is that once the script file is created it doesn't necessarily need to be saved to your /home folder. You can save it anywhere, make it executable and add it to the list of startup programs.
add a comment |
As of 18.10 (cannot check in earlier versions) VPN connections in NetworkManager have a setting vpn.persistent
which does just that: reconnects to a VPN on connection loss until you disconnect manually. It is set to "no"
by default and unfortunately isn't exposed neither in Gnome Network Settings nor in nm-connection-editor.
But you can set it through a CLI like this:
nmcli connection modify <Your VPN connection name> vpn.persistent yes
The connection must exist before you do that, of course
add a comment |
After claiming it was a SMOP (Simple Matter of Programming), I wrote a bash script that monitors for "Link Down", then executes a user script. Less CPU usage, more responsive than the while true....sleep 30
method. See my answer at here. It's about "rotating WiFi connections", but will probably work for you, too
add a comment |
this script will work on 16.04 where nmcli con status
no longer works:
#!/bin/bash
CON="purple"
STATUS=`nmcli con show --active | grep purple | cut -f1 -d " "`
if [ -z "$STATUS" ]; then
nmcli con up $CON
fi
A bit shorterSTATUS="$(nmcli con show -f name | grep purple)"
. Or you can simply check if the actual connection is active by doingnmcli con show --active id 'purple'
– smac89
May 29 '17 at 2:38
add a comment |
I think the complete answer based on other answers goes as follow :
#!/bin/bash +x
while [ "true" ]
do
CON="Your-VPN-Name"
STATUS=`nmcli con show --active | grep $CON | cut -f1 -d " "`
if [ -z "$STATUS" ]; then
echo "Disconnected, trying to reconnect..."
(sleep 1s && nmcli con up $CON)
else
echo "Already connected !"
fi
sleep 30
done
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "89"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f679059%2fauto-reconnect-to-vpn-on-disconnect%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
6 Answers
6
active
oldest
votes
6 Answers
6
active
oldest
votes
active
oldest
votes
active
oldest
votes
OpenVPN has a build-in mechanism to automatically detect dead links and reconnect. In Network Manager go to "Edit Connections", select your VPN connection and choose "Edit". In the "VPN" tab click on "Advanced..." and go to the "General" Tab. There you have two relevant options:
"Specify ping interval" tell OpenVPN how frequently to check if the link is still alive. "Specify exit or restart ping" tells it how long to wait until it takes action and which action to take.
Example: My setting are "30 / ping-restart / 300". This means OpenVPN checks every 30 seconds if the link is still active. If the link is down for 300 seconds it initiates a restart.
This way there is no need for external scripts...
This should be the accepted answer.
– necbot
Sep 12 '17 at 1:50
3
This is not true for Ubuntu 18.04 at least. I have ping interval and ping-restart but it will disable itself anyway.
– Sarge Borsch
Aug 13 at 9:42
add a comment |
OpenVPN has a build-in mechanism to automatically detect dead links and reconnect. In Network Manager go to "Edit Connections", select your VPN connection and choose "Edit". In the "VPN" tab click on "Advanced..." and go to the "General" Tab. There you have two relevant options:
"Specify ping interval" tell OpenVPN how frequently to check if the link is still alive. "Specify exit or restart ping" tells it how long to wait until it takes action and which action to take.
Example: My setting are "30 / ping-restart / 300". This means OpenVPN checks every 30 seconds if the link is still active. If the link is down for 300 seconds it initiates a restart.
This way there is no need for external scripts...
This should be the accepted answer.
– necbot
Sep 12 '17 at 1:50
3
This is not true for Ubuntu 18.04 at least. I have ping interval and ping-restart but it will disable itself anyway.
– Sarge Borsch
Aug 13 at 9:42
add a comment |
OpenVPN has a build-in mechanism to automatically detect dead links and reconnect. In Network Manager go to "Edit Connections", select your VPN connection and choose "Edit". In the "VPN" tab click on "Advanced..." and go to the "General" Tab. There you have two relevant options:
"Specify ping interval" tell OpenVPN how frequently to check if the link is still alive. "Specify exit or restart ping" tells it how long to wait until it takes action and which action to take.
Example: My setting are "30 / ping-restart / 300". This means OpenVPN checks every 30 seconds if the link is still active. If the link is down for 300 seconds it initiates a restart.
This way there is no need for external scripts...
OpenVPN has a build-in mechanism to automatically detect dead links and reconnect. In Network Manager go to "Edit Connections", select your VPN connection and choose "Edit". In the "VPN" tab click on "Advanced..." and go to the "General" Tab. There you have two relevant options:
"Specify ping interval" tell OpenVPN how frequently to check if the link is still alive. "Specify exit or restart ping" tells it how long to wait until it takes action and which action to take.
Example: My setting are "30 / ping-restart / 300". This means OpenVPN checks every 30 seconds if the link is still active. If the link is down for 300 seconds it initiates a restart.
This way there is no need for external scripts...
answered May 30 '16 at 8:43
OttoEisen
2921314
2921314
This should be the accepted answer.
– necbot
Sep 12 '17 at 1:50
3
This is not true for Ubuntu 18.04 at least. I have ping interval and ping-restart but it will disable itself anyway.
– Sarge Borsch
Aug 13 at 9:42
add a comment |
This should be the accepted answer.
– necbot
Sep 12 '17 at 1:50
3
This is not true for Ubuntu 18.04 at least. I have ping interval and ping-restart but it will disable itself anyway.
– Sarge Borsch
Aug 13 at 9:42
This should be the accepted answer.
– necbot
Sep 12 '17 at 1:50
This should be the accepted answer.
– necbot
Sep 12 '17 at 1:50
3
3
This is not true for Ubuntu 18.04 at least. I have ping interval and ping-restart but it will disable itself anyway.
– Sarge Borsch
Aug 13 at 9:42
This is not true for Ubuntu 18.04 at least. I have ping interval and ping-restart but it will disable itself anyway.
– Sarge Borsch
Aug 13 at 9:42
add a comment |
After a bit of digging I found this answer, tested it (on Ubuntu GNOME 15.04) and so far it seems working.
The only thing I might add is that once the script file is created it doesn't necessarily need to be saved to your /home folder. You can save it anywhere, make it executable and add it to the list of startup programs.
add a comment |
After a bit of digging I found this answer, tested it (on Ubuntu GNOME 15.04) and so far it seems working.
The only thing I might add is that once the script file is created it doesn't necessarily need to be saved to your /home folder. You can save it anywhere, make it executable and add it to the list of startup programs.
add a comment |
After a bit of digging I found this answer, tested it (on Ubuntu GNOME 15.04) and so far it seems working.
The only thing I might add is that once the script file is created it doesn't necessarily need to be saved to your /home folder. You can save it anywhere, make it executable and add it to the list of startup programs.
After a bit of digging I found this answer, tested it (on Ubuntu GNOME 15.04) and so far it seems working.
The only thing I might add is that once the script file is created it doesn't necessarily need to be saved to your /home folder. You can save it anywhere, make it executable and add it to the list of startup programs.
answered Sep 27 '15 at 17:40
community wiki
Inoki
add a comment |
add a comment |
As of 18.10 (cannot check in earlier versions) VPN connections in NetworkManager have a setting vpn.persistent
which does just that: reconnects to a VPN on connection loss until you disconnect manually. It is set to "no"
by default and unfortunately isn't exposed neither in Gnome Network Settings nor in nm-connection-editor.
But you can set it through a CLI like this:
nmcli connection modify <Your VPN connection name> vpn.persistent yes
The connection must exist before you do that, of course
add a comment |
As of 18.10 (cannot check in earlier versions) VPN connections in NetworkManager have a setting vpn.persistent
which does just that: reconnects to a VPN on connection loss until you disconnect manually. It is set to "no"
by default and unfortunately isn't exposed neither in Gnome Network Settings nor in nm-connection-editor.
But you can set it through a CLI like this:
nmcli connection modify <Your VPN connection name> vpn.persistent yes
The connection must exist before you do that, of course
add a comment |
As of 18.10 (cannot check in earlier versions) VPN connections in NetworkManager have a setting vpn.persistent
which does just that: reconnects to a VPN on connection loss until you disconnect manually. It is set to "no"
by default and unfortunately isn't exposed neither in Gnome Network Settings nor in nm-connection-editor.
But you can set it through a CLI like this:
nmcli connection modify <Your VPN connection name> vpn.persistent yes
The connection must exist before you do that, of course
As of 18.10 (cannot check in earlier versions) VPN connections in NetworkManager have a setting vpn.persistent
which does just that: reconnects to a VPN on connection loss until you disconnect manually. It is set to "no"
by default and unfortunately isn't exposed neither in Gnome Network Settings nor in nm-connection-editor.
But you can set it through a CLI like this:
nmcli connection modify <Your VPN connection name> vpn.persistent yes
The connection must exist before you do that, of course
answered Dec 20 at 10:37
m0NKey bR4in
312
312
add a comment |
add a comment |
After claiming it was a SMOP (Simple Matter of Programming), I wrote a bash script that monitors for "Link Down", then executes a user script. Less CPU usage, more responsive than the while true....sleep 30
method. See my answer at here. It's about "rotating WiFi connections", but will probably work for you, too
add a comment |
After claiming it was a SMOP (Simple Matter of Programming), I wrote a bash script that monitors for "Link Down", then executes a user script. Less CPU usage, more responsive than the while true....sleep 30
method. See my answer at here. It's about "rotating WiFi connections", but will probably work for you, too
add a comment |
After claiming it was a SMOP (Simple Matter of Programming), I wrote a bash script that monitors for "Link Down", then executes a user script. Less CPU usage, more responsive than the while true....sleep 30
method. See my answer at here. It's about "rotating WiFi connections", but will probably work for you, too
After claiming it was a SMOP (Simple Matter of Programming), I wrote a bash script that monitors for "Link Down", then executes a user script. Less CPU usage, more responsive than the while true....sleep 30
method. See my answer at here. It's about "rotating WiFi connections", but will probably work for you, too
edited Apr 13 '17 at 12:24
Community♦
1
1
answered Sep 28 '15 at 22:48
waltinator
21.9k74169
21.9k74169
add a comment |
add a comment |
this script will work on 16.04 where nmcli con status
no longer works:
#!/bin/bash
CON="purple"
STATUS=`nmcli con show --active | grep purple | cut -f1 -d " "`
if [ -z "$STATUS" ]; then
nmcli con up $CON
fi
A bit shorterSTATUS="$(nmcli con show -f name | grep purple)"
. Or you can simply check if the actual connection is active by doingnmcli con show --active id 'purple'
– smac89
May 29 '17 at 2:38
add a comment |
this script will work on 16.04 where nmcli con status
no longer works:
#!/bin/bash
CON="purple"
STATUS=`nmcli con show --active | grep purple | cut -f1 -d " "`
if [ -z "$STATUS" ]; then
nmcli con up $CON
fi
A bit shorterSTATUS="$(nmcli con show -f name | grep purple)"
. Or you can simply check if the actual connection is active by doingnmcli con show --active id 'purple'
– smac89
May 29 '17 at 2:38
add a comment |
this script will work on 16.04 where nmcli con status
no longer works:
#!/bin/bash
CON="purple"
STATUS=`nmcli con show --active | grep purple | cut -f1 -d " "`
if [ -z "$STATUS" ]; then
nmcli con up $CON
fi
this script will work on 16.04 where nmcli con status
no longer works:
#!/bin/bash
CON="purple"
STATUS=`nmcli con show --active | grep purple | cut -f1 -d " "`
if [ -z "$STATUS" ]; then
nmcli con up $CON
fi
edited Nov 24 '17 at 8:16
derHugo
2,28021429
2,28021429
answered Mar 15 '17 at 6:04
george
1
1
A bit shorterSTATUS="$(nmcli con show -f name | grep purple)"
. Or you can simply check if the actual connection is active by doingnmcli con show --active id 'purple'
– smac89
May 29 '17 at 2:38
add a comment |
A bit shorterSTATUS="$(nmcli con show -f name | grep purple)"
. Or you can simply check if the actual connection is active by doingnmcli con show --active id 'purple'
– smac89
May 29 '17 at 2:38
A bit shorter
STATUS="$(nmcli con show -f name | grep purple)"
. Or you can simply check if the actual connection is active by doing nmcli con show --active id 'purple'
– smac89
May 29 '17 at 2:38
A bit shorter
STATUS="$(nmcli con show -f name | grep purple)"
. Or you can simply check if the actual connection is active by doing nmcli con show --active id 'purple'
– smac89
May 29 '17 at 2:38
add a comment |
I think the complete answer based on other answers goes as follow :
#!/bin/bash +x
while [ "true" ]
do
CON="Your-VPN-Name"
STATUS=`nmcli con show --active | grep $CON | cut -f1 -d " "`
if [ -z "$STATUS" ]; then
echo "Disconnected, trying to reconnect..."
(sleep 1s && nmcli con up $CON)
else
echo "Already connected !"
fi
sleep 30
done
add a comment |
I think the complete answer based on other answers goes as follow :
#!/bin/bash +x
while [ "true" ]
do
CON="Your-VPN-Name"
STATUS=`nmcli con show --active | grep $CON | cut -f1 -d " "`
if [ -z "$STATUS" ]; then
echo "Disconnected, trying to reconnect..."
(sleep 1s && nmcli con up $CON)
else
echo "Already connected !"
fi
sleep 30
done
add a comment |
I think the complete answer based on other answers goes as follow :
#!/bin/bash +x
while [ "true" ]
do
CON="Your-VPN-Name"
STATUS=`nmcli con show --active | grep $CON | cut -f1 -d " "`
if [ -z "$STATUS" ]; then
echo "Disconnected, trying to reconnect..."
(sleep 1s && nmcli con up $CON)
else
echo "Already connected !"
fi
sleep 30
done
I think the complete answer based on other answers goes as follow :
#!/bin/bash +x
while [ "true" ]
do
CON="Your-VPN-Name"
STATUS=`nmcli con show --active | grep $CON | cut -f1 -d " "`
if [ -z "$STATUS" ]; then
echo "Disconnected, trying to reconnect..."
(sleep 1s && nmcli con up $CON)
else
echo "Already connected !"
fi
sleep 30
done
edited May 13 at 15:50
answered May 13 at 15:38
ali mohebbi
11
11
add a comment |
add a comment |
Thanks for contributing an answer to Ask Ubuntu!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f679059%2fauto-reconnect-to-vpn-on-disconnect%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown