Como fazer com que o OpenVPN se conecte automaticamente ao gateway a qualquer momento

3

Recentemente, descobri uma maneira integrada de fazer com que o OpenVPN se conecte automaticamente ao gateway da VPN na inicialização, o que é feito definindo os arquivos .conf do perfil em /etc/default/openvpn como parte do parâmetro AUTOSTART . Bem, funciona como um encanto, mas o que é uma boa maneira de se reconectar ao OpenVPN se a conexão cair?

Eu sou bastante novo no Linux, então minha implementação é basicamente um script basico com do while, que verifica se ele pode pingar o IP do gateway OpenVPN, e se ele não pode sudo 'o openvpn --config /path/to/ovpn reconectar .

Poderia, por favor, aconselhar uma maneira mais confiável de ter a conexão restabelecida automaticamente pelo host?

    
por Maxim V. Pavlov 10.08.2015 / 18:03

1 resposta

6

De "man openvpn":

--ping-restart n Similar to --ping-exit, but trigger a SIGUSR1 restart after n seconds pass without reception of a ping or other packet from remote.

This option is useful in cases where the remote peer has a dynamic IP address and a low-TTL DNS name is used to track the IP address using a service such as http://dyndns.org/ + a dynamic DNS client such as ddclient.

If the peer cannot be reached, a restart will be triggered, causing the hostname used with --remote to be re-resolved (if --resolv-retry is also spec‐ ified).

In server mode, --ping-restart, --inactive, or any other type of internally generated signal will always be applied to individual client instance objects, never to whole server itself. Note also in server mode that any internally generated signal which would normally cause a restart, will cause the deletion of the client instance object instead.

In client mode, the --ping-restart parameter is set to 120 seconds by default. This default will hold until the client pulls a replacement value from the server, based on the --keepalive setting in the server configuration. To disable the 120 second default, set --ping-restart 0 on the client.

See the signals section below for more information on SIGUSR1.

Note that the behavior of SIGUSR1 can be modified by the --persist-tun, --persist-key, --persist-local-ip, and --persist-remote-ip options.

Also note that --ping-exit and --ping-restart are mutually exclusive and cannot be used together.

    
por 10.08.2015 / 20:02