• 5
name
name Punditsdkoslkdosdkoskdo

Porting openVPN config to Alpine Linux

I got an openVPN config file from my vpn provider. It worked great on Ubuntu, but on alpine, I got an error.

The following lines fail:

up /etc/openvpn/update-resolv-conf
down /etc/openvpn/update-resolv-conf

/etc/openvpn/update-resolv-conf does not exists on alpine Linux but /etc/openvpn/up.sh and /etc/openvpn/down.sh do.

the log contains the following output:

Options error: --up script fails with '/etc/openvpn/update-resolv-conf': No such file or directory (errno=2)
Options error: Please correct this error.
Use --help for more information.
    • Hi @Peter. Would you please add the error messages that you got! what do you mean by The following lines fail:? Failed where? and how you identified that these lines had failed? More clarifications will help us understand your problem much better, as a result give you an accurate answer ;-)
      • 1
    • @Goro the command returns grep: /etc/resolvconf/resolv.conf.d/*: No such file or directory but i do have /etc/resolv.conf

It seems like the OpenVPN for Alpine Linux package does not include all the necessary scripts. If you know the address of the DNS servers your VPN provider uses, then you can use this simple workaround. You can also use a public DNS server such as Cloudflare DNS (1.1.1.1):

  1. Enter the command: sudo nano /etc/openvpn/update-resolv-conf. The Nano text editor should open.
  2. The file should be empty. Paste the following into the file:

    #!/bin/bash
    if [ -e /etc/resolv.conf.old ]; then
        mv /etc/resolv.conf.old /etc/resolv.conf
        chmod 777 /etc/resolv.conf
        exit
    fi
    mv /etc/resolv.conf /etc/resolv.conf.old
    cp /etc/resolv.conf.new /etc/resolv.conf
    chmod 777 /etc/resolv.conf
    
  3. Press Ctrl+X, then Y, then press Enter to save the file.

  4. Enter the command: sudo nano /etc/resolv.conf.new, then type nameserver [address of VPN's DNS server].
  5. Press Ctrl+X, then Y, then press Enter to save the file.

That should make a new copy of resolv.conf (resolv.conf.new), and copy it to resolv.conf when the VPN activates, then copy back the old resolv.conf when the VPN ends.

  • 2
Reply Report
    • (1)?When does your /etc/openvpn/update-resolv-conf script run?? What runs it?? (2)?Do you really believe that it’s a good idea to leave the /etc/resolv.conf file world-writable?? (3)?When you say “type?nameserver?…”, do you mean type n?a?m?e?s?e?r?v?e?r, or do you mean type the IP address of your name?server??(You should use code formatting only for literal text, and not descriptions or placeholders.)
    • I'll just say, this similar to what I use on my setup so it may not be exactly what you want. The update-resolv-conf script runs whenever the .ovpn config file calls it (the lines 'up /etc/openvpn/update-resolv-conf' and 'down /etc/openvpn/update-resolv-conf'). In this case, it runs when the tunnel is established and terminated. I have changed my answer to make resolv.conf 755. When I say "type 'nameserver'", I mean type the word 'nameserver' and then '[SPACE]' and then type the DNS server's address.

Warm tip !!!

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

Trending Tags