Automatic VPN connection and internet kill switch, Ubuntu 18.04












-1














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?










share|improve this question







New contributor




user10445763 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

























    -1














    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?










    share|improve this question







    New contributor




    user10445763 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.























      -1












      -1








      -1







      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?










      share|improve this question







      New contributor




      user10445763 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.











      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






      share|improve this question







      New contributor




      user10445763 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.











      share|improve this question







      New contributor




      user10445763 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      share|improve this question




      share|improve this question






      New contributor




      user10445763 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      asked Dec 30 '18 at 13:59









      user10445763

      1




      1




      New contributor




      user10445763 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.





      New contributor





      user10445763 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.






      user10445763 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.






















          1 Answer
          1






          active

          oldest

          votes


















          0














          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.






          share|improve this answer








          New contributor




          Sebastian is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
          Check out our Code of Conduct.


















          • 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











          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.










          draft saved

          draft discarded


















          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









          0














          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.






          share|improve this answer








          New contributor




          Sebastian is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
          Check out our Code of Conduct.


















          • 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
















          0














          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.






          share|improve this answer








          New contributor




          Sebastian is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
          Check out our Code of Conduct.


















          • 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














          0












          0








          0






          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.






          share|improve this answer








          New contributor




          Sebastian is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
          Check out our Code of Conduct.









          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.







          share|improve this answer








          New contributor




          Sebastian is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
          Check out our Code of Conduct.









          share|improve this answer



          share|improve this answer






          New contributor




          Sebastian is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
          Check out our Code of Conduct.









          answered Dec 30 '18 at 15:34









          Sebastian

          1114




          1114




          New contributor




          Sebastian is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
          Check out our Code of Conduct.





          New contributor





          Sebastian is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
          Check out our Code of Conduct.






          Sebastian is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
          Check out our Code of Conduct.












          • 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












          • 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










          user10445763 is a new contributor. Be nice, and check out our Code of Conduct.










          draft saved

          draft discarded


















          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.




          draft saved


          draft discarded














          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





















































          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







          Popular posts from this blog

          數位音樂下載

          When can things happen in Etherscan, such as the picture below?

          格利澤436b