• 5
name
name Punditsdkoslkdosdkoskdo

Rotate remote server in openvpn config

In my config, I have chosen a remote server for hide.io:

# cat /etc/openvpn/anonvpn.conf |grep remote
remote nl.hide.me 3478

It seems like some servers are somehow overloaded.

I have a script that checks if openvpn is still running:

if ! pgrep "openvpn" > /dev/null; then 
  /usr/sbin/service openvpn restart
  echo "["$(date "+%Y-%m-%d %H:%M:%S")"] openvpn restarted">> /var/log/openvpn.log
fi

How can I add a rotation to the server whenever openvpn went down?

Do something like this

server=$(cat /etc/openvpn/anonvpn.conf |grep remote|cut -d" " -f2)
nextserver=$(grep -A1 $server /etc/openvpn/list.txt|grep -v $server)

if [ -z "$nextserver" ]; then
    nextserver=$(head -n1 /etc/openvpn/list.txt)
fi
sed -i "s!$server!$nextserver!" /etc/openvpn/anonvpn.conf

create the file /etc/openvpn/list.txt with your list of servers

  • 2
Reply Report

Warm tip !!!

This article is reproduced from Stack Exchange / Stack Overflow, please click

Trending Tags