Skip to main content
added 21 characters in body
Source Link
pLumo
  • 23.2k
  • 2
  • 43
  • 70
  • Use full path in set command
  • run screen in detached mode
  • use a case ... esac construct to make a start/stop script.

Maybe something like this:

#!/bin/bash

start(){
  status # Print IP before connection
  set -- /etc/openvpn/ovpn_tcp/*.nordvpn.com.tcp.ovpn
  shift $(( RANDOM % $# ))
  screen -S vpn -dm openvpn "$1" # connect
  sleep 5 # wait for connection
  status # Print IP after connection
}
stop(){
  screen -S vpn -X quit
  pkill -f ovpn
}
status(){
  printf 'IP: %s\n' "$(curl -s ifconfig.co)"
}

case "$1" in
start)
    if screen -ls | grep -w vpn; then
      echo "Vpn already connected";
      status
    else
      start
    fi
    ;;
stop)
    stop
    ;;
*)
    status
    ;;
esac
    

and then you can add this as an alias:

alias vpn='bash /etc/openvpn/ovpn_tcp/go'

Usage:

# Start connection
vpn start

# Stop connection
vpn stop

# get status
vpn

As an alternative to an alias, you can put the script in your ~/bin, make it executable and add that directory to your $PATH.

  • Use full path in set command
  • run screen in detached mode
  • use a case ... esac construct to make a start/stop script.

Maybe something like this:

#!/bin/bash

start(){
  status # Print IP before connection
  set -- /etc/openvpn/ovpn_tcp/*.nordvpn.com.tcp.ovpn
  shift $(( RANDOM % $# ))
  screen -S vpn -dm openvpn "$1" # connect
  sleep 5 # wait for connection
  status # Print IP after connection
}
stop(){
  screen -S vpn -X quit
}
status(){
  printf 'IP: %s\n' "$(curl -s ifconfig.co)"
}

case "$1" in
start)
    if screen -ls | grep -w vpn; then
      echo "Vpn already connected";
      status
    else
      start
    fi
    ;;
stop)
    stop
    ;;
*)
    status
    ;;
esac
    

and then you can add this as an alias:

alias vpn='bash /etc/openvpn/ovpn_tcp/go'

Usage:

# Start connection
vpn start

# Stop connection
vpn stop

# get status
vpn

As an alternative to an alias, you can put the script in your ~/bin, make it executable and add that directory to your $PATH.

  • Use full path in set command
  • run screen in detached mode
  • use a case ... esac construct to make a start/stop script.

Maybe something like this:

#!/bin/bash

start(){
  status # Print IP before connection
  set -- /etc/openvpn/ovpn_tcp/*.nordvpn.com.tcp.ovpn
  shift $(( RANDOM % $# ))
  screen -S vpn -dm openvpn "$1" # connect
  sleep 5 # wait for connection
  status # Print IP after connection
}
stop(){
  screen -S vpn -X quit
  pkill -f ovpn
}
status(){
  printf 'IP: %s\n' "$(curl -s ifconfig.co)"
}

case "$1" in
start)
    if screen -ls | grep -w vpn; then
      echo "Vpn already connected";
      status
    else
      start
    fi
    ;;
stop)
    stop
    ;;
*)
    status
    ;;
esac
    

and then you can add this as an alias:

alias vpn='bash /etc/openvpn/ovpn_tcp/go'

Usage:

# Start connection
vpn start

# Stop connection
vpn stop

# get status
vpn

As an alternative to an alias, you can put the script in your ~/bin, make it executable and add that directory to your $PATH.

added 30 characters in body
Source Link
pLumo
  • 23.2k
  • 2
  • 43
  • 70
  • Use full path in set command
  • run screen in detached mode
  • use a case ... esac construct to make a start/stop script.

Maybe something like this:

#!/bin/bash

start(){
  status # Print IP before connection
  set -- /etc/openvpn/ovpn_tcp/*.nordvpn.com.tcp.ovpn
  shift $(( RANDOM % $# ))
  screen -S vpn -dm openvpn "$1" # connect
  sleep 5 # wait for connection
  status # Print IP after connection
}
stop(){
  screen -S vpn -X quit
}
status(){
  printf 'IP: %s\n' "$(curl -s ifconfig.co)"
}

case "$1" in
start)
    if screen -ls | grep -w vpn; then
      echo "Vpn already connected";
      status
    else
      start
    fi
    ;;
stop)
    stop
    ;;
*)
    status
    ;;
esac
    

and then you can add this as an alias:

alias vpn='bash /etc/openvpn/ovpn_tcp/go'

Usage:

# Start connection
vpn start

# Stop connection
vpn stop

# get status
vpn

As an alternative to an alias, you can put the script in your ~/bin, make it executable and add that directory to your $PATH.

  • Use full path in set command
  • run screen in detached mode
  • use a case ... esac construct to make a start/stop script.
#!/bin/bash

start(){
  status # Print IP before connection
  set -- /etc/openvpn/ovpn_tcp/*.nordvpn.com.tcp.ovpn
  shift $(( RANDOM % $# ))
  screen -S vpn -dm openvpn "$1" # connect
  sleep 5 # wait for connection
  status # Print IP after connection
}
stop(){
  screen -S vpn -X quit
}
status(){
  printf 'IP: %s\n' "$(curl -s ifconfig.co)"
}

case "$1" in
start)
    if screen -ls | grep -w vpn; then
      echo "Vpn already connected";
      status
    else
      start
    fi
    ;;
stop)
    stop
    ;;
*)
    status
    ;;
esac
    

and then you can add this as an alias:

alias vpn='bash /etc/openvpn/ovpn_tcp/go'

Usage:

# Start connection
vpn start

# Stop connection
vpn stop

# get status
vpn

As an alternative to an alias, you can put the script in your ~/bin, make it executable and add that directory to your $PATH.

  • Use full path in set command
  • run screen in detached mode
  • use a case ... esac construct to make a start/stop script.

Maybe something like this:

#!/bin/bash

start(){
  status # Print IP before connection
  set -- /etc/openvpn/ovpn_tcp/*.nordvpn.com.tcp.ovpn
  shift $(( RANDOM % $# ))
  screen -S vpn -dm openvpn "$1" # connect
  sleep 5 # wait for connection
  status # Print IP after connection
}
stop(){
  screen -S vpn -X quit
}
status(){
  printf 'IP: %s\n' "$(curl -s ifconfig.co)"
}

case "$1" in
start)
    if screen -ls | grep -w vpn; then
      echo "Vpn already connected";
      status
    else
      start
    fi
    ;;
stop)
    stop
    ;;
*)
    status
    ;;
esac
    

and then you can add this as an alias:

alias vpn='bash /etc/openvpn/ovpn_tcp/go'

Usage:

# Start connection
vpn start

# Stop connection
vpn stop

# get status
vpn

As an alternative to an alias, you can put the script in your ~/bin, make it executable and add that directory to your $PATH.

added 36 characters in body
Source Link
pLumo
  • 23.2k
  • 2
  • 43
  • 70
  • Use full path in set command
  • run screen in detached mode
  • use a case ... esac construct to make a start/stop script.
#!/bin/bash

start(){
  status # Print IP before connection
  set -- /etc/openvpn/ovpn_tcp/*.nordvpn.com.tcp.ovpn
  shift $(( RANDOM % $# ))
  screen -S vpn -dm openvpn "$1" # connect
  sleep 5 # wait for connection
  status # Print IP after connection
}
stop(){
  screen -S vpn -X quit
}
status(){
  printf 'IP: %s\n' "$(curl -s ifconfig.co)"
}

case "$1" in
start)
    if screen -ls | grep -w vpn; then
      echo "Vpn already connected";
      status
    else
      start
    fi
    ;;
stop)
    stop
    ;;
*)
    status
    ;;
esac
    

and then you can add this as an alias:

alias vpn='bash /etc/openvpn/ovpn_tcp/go'

Usage:

# Start connection
vpn start

# Stop connection
vpn stop

# get status
vpn

As an alternative to an alias, you can put the script in your ~/bin, make it executable and add that directory to your $PATH.

  • Use full path in set command
  • run screen in detached mode
  • use a case ... esac construct to make a start/stop script.
#!/bin/bash

start(){
  set -- /etc/openvpn/ovpn_tcp/*.nordvpn.com.tcp.ovpn
  shift $(( RANDOM % $# ))
  screen -S vpn -dm openvpn "$1"
}
stop(){
  screen -S vpn -X quit
}
status(){
  curl ifconfig.co
}

case "$1" in
start)
    if screen -ls | grep -w vpn; then
      echo "Vpn already connected";
      status
    else
      start
    fi
    ;;
stop)
    stop
    ;;
*)
    status
    ;;
esac
    

and then you can add this as an alias:

alias vpn='bash /etc/openvpn/ovpn_tcp/go'

Usage:

# Start connection
vpn start

# Stop connection
vpn stop

# get status
vpn

As an alternative to an alias, you can put the script in your ~/bin, make it executable and add that directory to your $PATH.

  • Use full path in set command
  • run screen in detached mode
  • use a case ... esac construct to make a start/stop script.
#!/bin/bash

start(){
  status # Print IP before connection
  set -- /etc/openvpn/ovpn_tcp/*.nordvpn.com.tcp.ovpn
  shift $(( RANDOM % $# ))
  screen -S vpn -dm openvpn "$1" # connect
  sleep 5 # wait for connection
  status # Print IP after connection
}
stop(){
  screen -S vpn -X quit
}
status(){
  printf 'IP: %s\n' "$(curl -s ifconfig.co)"
}

case "$1" in
start)
    if screen -ls | grep -w vpn; then
      echo "Vpn already connected";
      status
    else
      start
    fi
    ;;
stop)
    stop
    ;;
*)
    status
    ;;
esac
    

and then you can add this as an alias:

alias vpn='bash /etc/openvpn/ovpn_tcp/go'

Usage:

# Start connection
vpn start

# Stop connection
vpn stop

# get status
vpn

As an alternative to an alias, you can put the script in your ~/bin, make it executable and add that directory to your $PATH.

added 36 characters in body
Source Link
pLumo
  • 23.2k
  • 2
  • 43
  • 70
Loading
added 157 characters in body
Source Link
pLumo
  • 23.2k
  • 2
  • 43
  • 70
Loading
Source Link
pLumo
  • 23.2k
  • 2
  • 43
  • 70
Loading