hwdsl2 / setup-ipsec-vpn

Scripts to build your own IPsec VPN server, with IPsec/L2TP, Cisco IPsec and IKEv2
Other
25.25k stars 6.32k forks source link

Automatic reconnecting not working in mobile networks (working in Wifi networks) #1507

Closed BenLender closed 10 months ago

BenLender commented 10 months ago

Checklist

Describe the issue VPN on demand does not work on mobile networks anymore.

To Reproduce

  1. Setup ikev2 vpn on raspberry pi according to guide: https://github.com/hwdsl2/setup-ipsec-vpn/
  2. Setup mobile clients using .mobileconfig files
  3. Activate VPN on demand option in iOS GUI

Expected behavior When the VPN connection is lost, the mobile device reconnects no matter the network it is in. Actual behavior: the mobile device reconntects flawlessly in wifi networks. The mobile device does not connect when not in a wifi network. While in a mobile network, as soon as "vpn on demand" is deactivated manually activing the vpn connecting becomes possible.

Logs Check logs and VPN status, and add error logs to help explain the problem, if applicable.

Server (please complete the following information)

Client (please complete the following information)

Additional context not applicable

hwdsl2 commented 10 months ago

@BenLender Hello! The default VPN On Demand configuration in this project disconnects the VPN while on mobile networks, so this is normal. In the most common use case, people expect the VPN to connect on Wi-Fi networks but not mobile networks.

To change this behavior for your use case:

  1. Edit /opt/src/ikev2.sh on your VPN server. Find this section:
          <dict>
            <key>InterfaceTypeMatch</key>
            <string>Cellular</string>
            <key>Action</key>
            <string>Disconnect</string>
          </dict>

    and replace "Disconnect" with "Connect", i.e.

          <dict>
            <key>InterfaceTypeMatch</key>
            <string>Cellular</string>
            <key>Action</key>
            <string>Connect</string>
          </dict>
  2. Save the file, then run sudo ikev2.sh to export updated client configuration files for your iPhone.
  3. Remove the previously imported VPN profile from your iPhone, then import the new .mobileconfig file from step 2.
BenLender commented 10 months ago

@hwdsl2 Thank you very much!