Automatic VPN connection and internet kill switch, Ubuntu 18.04
I am trying to write a script which automatically connects to vpn (purevpn)(it automatically connects to the fastest available server, therefore i can't allow a specific IP for ufw because it always connects to different Servers/ IPs) and also enables an internet kill switch. Heres my script:
!/bin/bash
sudo ufw disable
disconnect and reconnect to vpn
purevpn -d
purevpn -c
sudo ufw --force reset
sudo ufw default deny incoming
sudo ufw default deny outgoing
sudo ufw allow out on tun0 from any to any
sudo ufw enable
(The fat lines are actually comments in the script)
Unfortunately the script doesn't always work. Sometimes it works fine, meaning that it connects to vpn and enables the kill switch so I can browse but once I disconnect from vpn sites can't load - as it's wanted. However sometimes after running the script when I then afterwards try to google something it shows that it's loading (anticklockwise circle in chrome) but never shows any progress. I can't quite find a regularity in when it works and when not. Any ideas?
vpn
New contributor
add a comment |
I am trying to write a script which automatically connects to vpn (purevpn)(it automatically connects to the fastest available server, therefore i can't allow a specific IP for ufw because it always connects to different Servers/ IPs) and also enables an internet kill switch. Heres my script:
!/bin/bash
sudo ufw disable
disconnect and reconnect to vpn
purevpn -d
purevpn -c
sudo ufw --force reset
sudo ufw default deny incoming
sudo ufw default deny outgoing
sudo ufw allow out on tun0 from any to any
sudo ufw enable
(The fat lines are actually comments in the script)
Unfortunately the script doesn't always work. Sometimes it works fine, meaning that it connects to vpn and enables the kill switch so I can browse but once I disconnect from vpn sites can't load - as it's wanted. However sometimes after running the script when I then afterwards try to google something it shows that it's loading (anticklockwise circle in chrome) but never shows any progress. I can't quite find a regularity in when it works and when not. Any ideas?
vpn
New contributor
add a comment |
I am trying to write a script which automatically connects to vpn (purevpn)(it automatically connects to the fastest available server, therefore i can't allow a specific IP for ufw because it always connects to different Servers/ IPs) and also enables an internet kill switch. Heres my script:
!/bin/bash
sudo ufw disable
disconnect and reconnect to vpn
purevpn -d
purevpn -c
sudo ufw --force reset
sudo ufw default deny incoming
sudo ufw default deny outgoing
sudo ufw allow out on tun0 from any to any
sudo ufw enable
(The fat lines are actually comments in the script)
Unfortunately the script doesn't always work. Sometimes it works fine, meaning that it connects to vpn and enables the kill switch so I can browse but once I disconnect from vpn sites can't load - as it's wanted. However sometimes after running the script when I then afterwards try to google something it shows that it's loading (anticklockwise circle in chrome) but never shows any progress. I can't quite find a regularity in when it works and when not. Any ideas?
vpn
New contributor
I am trying to write a script which automatically connects to vpn (purevpn)(it automatically connects to the fastest available server, therefore i can't allow a specific IP for ufw because it always connects to different Servers/ IPs) and also enables an internet kill switch. Heres my script:
!/bin/bash
sudo ufw disable
disconnect and reconnect to vpn
purevpn -d
purevpn -c
sudo ufw --force reset
sudo ufw default deny incoming
sudo ufw default deny outgoing
sudo ufw allow out on tun0 from any to any
sudo ufw enable
(The fat lines are actually comments in the script)
Unfortunately the script doesn't always work. Sometimes it works fine, meaning that it connects to vpn and enables the kill switch so I can browse but once I disconnect from vpn sites can't load - as it's wanted. However sometimes after running the script when I then afterwards try to google something it shows that it's loading (anticklockwise circle in chrome) but never shows any progress. I can't quite find a regularity in when it works and when not. Any ideas?
vpn
vpn
New contributor
New contributor
New contributor
asked Dec 30 '18 at 13:59
user10445763
1
1
New contributor
New contributor
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
You may have to add a line like
sudo ufw allow out from any to 1.2.3.4
to your script just before the "enable", where "1.2.3.4" is the IP of the VPN server you're connected to. At least that's how the script I'm using works. Unfortunately that does not make it independent from the server you're currently connected to, but I don't see a way around that.
New contributor
I think my original source for the script is here: gist.github.com/Necklaces/18b68e80bf929ef99312b2d90d0cded2 which may also explain why it sometimes works and sometimes not.
– Sebastian
Dec 30 '18 at 15:40
Thanks, I'll try that later. Maybe I can find a way to store the IP of the server I'm connected to somewhere to then let it automatically be filled into your line. I'll give an update later.
– user10445763
Dec 30 '18 at 15:55
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
});
}
});
user10445763 is a new contributor. Be nice, and check out our Code of Conduct.
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%2f1105601%2fautomatic-vpn-connection-and-internet-kill-switch-ubuntu-18-04%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
You may have to add a line like
sudo ufw allow out from any to 1.2.3.4
to your script just before the "enable", where "1.2.3.4" is the IP of the VPN server you're connected to. At least that's how the script I'm using works. Unfortunately that does not make it independent from the server you're currently connected to, but I don't see a way around that.
New contributor
I think my original source for the script is here: gist.github.com/Necklaces/18b68e80bf929ef99312b2d90d0cded2 which may also explain why it sometimes works and sometimes not.
– Sebastian
Dec 30 '18 at 15:40
Thanks, I'll try that later. Maybe I can find a way to store the IP of the server I'm connected to somewhere to then let it automatically be filled into your line. I'll give an update later.
– user10445763
Dec 30 '18 at 15:55
add a comment |
You may have to add a line like
sudo ufw allow out from any to 1.2.3.4
to your script just before the "enable", where "1.2.3.4" is the IP of the VPN server you're connected to. At least that's how the script I'm using works. Unfortunately that does not make it independent from the server you're currently connected to, but I don't see a way around that.
New contributor
I think my original source for the script is here: gist.github.com/Necklaces/18b68e80bf929ef99312b2d90d0cded2 which may also explain why it sometimes works and sometimes not.
– Sebastian
Dec 30 '18 at 15:40
Thanks, I'll try that later. Maybe I can find a way to store the IP of the server I'm connected to somewhere to then let it automatically be filled into your line. I'll give an update later.
– user10445763
Dec 30 '18 at 15:55
add a comment |
You may have to add a line like
sudo ufw allow out from any to 1.2.3.4
to your script just before the "enable", where "1.2.3.4" is the IP of the VPN server you're connected to. At least that's how the script I'm using works. Unfortunately that does not make it independent from the server you're currently connected to, but I don't see a way around that.
New contributor
You may have to add a line like
sudo ufw allow out from any to 1.2.3.4
to your script just before the "enable", where "1.2.3.4" is the IP of the VPN server you're connected to. At least that's how the script I'm using works. Unfortunately that does not make it independent from the server you're currently connected to, but I don't see a way around that.
New contributor
New contributor
answered Dec 30 '18 at 15:34
Sebastian
1114
1114
New contributor
New contributor
I think my original source for the script is here: gist.github.com/Necklaces/18b68e80bf929ef99312b2d90d0cded2 which may also explain why it sometimes works and sometimes not.
– Sebastian
Dec 30 '18 at 15:40
Thanks, I'll try that later. Maybe I can find a way to store the IP of the server I'm connected to somewhere to then let it automatically be filled into your line. I'll give an update later.
– user10445763
Dec 30 '18 at 15:55
add a comment |
I think my original source for the script is here: gist.github.com/Necklaces/18b68e80bf929ef99312b2d90d0cded2 which may also explain why it sometimes works and sometimes not.
– Sebastian
Dec 30 '18 at 15:40
Thanks, I'll try that later. Maybe I can find a way to store the IP of the server I'm connected to somewhere to then let it automatically be filled into your line. I'll give an update later.
– user10445763
Dec 30 '18 at 15:55
I think my original source for the script is here: gist.github.com/Necklaces/18b68e80bf929ef99312b2d90d0cded2 which may also explain why it sometimes works and sometimes not.
– Sebastian
Dec 30 '18 at 15:40
I think my original source for the script is here: gist.github.com/Necklaces/18b68e80bf929ef99312b2d90d0cded2 which may also explain why it sometimes works and sometimes not.
– Sebastian
Dec 30 '18 at 15:40
Thanks, I'll try that later. Maybe I can find a way to store the IP of the server I'm connected to somewhere to then let it automatically be filled into your line. I'll give an update later.
– user10445763
Dec 30 '18 at 15:55
Thanks, I'll try that later. Maybe I can find a way to store the IP of the server I'm connected to somewhere to then let it automatically be filled into your line. I'll give an update later.
– user10445763
Dec 30 '18 at 15:55
add a comment |
user10445763 is a new contributor. Be nice, and check out our Code of Conduct.
user10445763 is a new contributor. Be nice, and check out our Code of Conduct.
user10445763 is a new contributor. Be nice, and check out our Code of Conduct.
user10445763 is a new contributor. Be nice, and check out our Code of Conduct.
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%2f1105601%2fautomatic-vpn-connection-and-internet-kill-switch-ubuntu-18-04%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