Skip to content

About

Automatically reconnects a macOS VPN(IPSec/IKEv2)when the connection drops or on system startup

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Repository files navigation

vpn-automator

Automatically reconnects a macOS VPN when the connection drops or on system startup.

한국어 문서: README.KOR.md


Who is this for?

This tool is for macOS users whose VPN is configured directly in System Settings → VPN using the IPSec (Cisco) or IKEv2 protocol — rather than through a dedicated third-party VPN app.

Many VPN services — especially corporate or regional VPN providers — do not offer a standalone macOS app and instead require users to add the connection manually via System Settings. Unlike dedicated VPN apps, macOS's built-in VPN client has no auto-reconnect feature. If the connection drops, you have to go back into System Settings and manually toggle the switch every time.

This tool fills that gap by watching the VPN connection in the background and reconnecting automatically whenever it drops.

You likely need this if:

  • Your VPN appears under System Settings → VPN (not as a separate app in /Applications)
  • The VPN type is IPSec or IKEv2
  • You find yourself manually reconnecting the VPN after sleep, network changes, or system restart

You probably don't need this if:

  • You use a VPN app (e.g. Wireguard, OpenVPN-based apps) that already handles reconnection on its own

How it works

  • Runs as a LaunchAgent in the background after login
  • Checks VPN status every 30 seconds via the ipsec0 network interface
  • If the VPN is disconnected, it reconnects automatically using AppleScript to toggle the VPN switch in System Settings
  • Logs events (connect / disconnect) to ~/Library/Logs/vpn-automator.log

Requirements

  • macOS (tested on macOS 26)
  • A VPN configured in System Settings → VPN (IPSec / IKEv2 type)

Installation

git clone https://github.com/ebadac/vpn-automator.git
cd vpn-automator
bash install.sh

During installation you will be prompted to enter the VPN name exactly as it appears in System Settings → VPN.

Note: On first reconnect attempt, macOS may ask you to grant Accessibility permission to Terminal. Go to System Settings → Privacy & Security → Accessibility and allow Terminal.

Uninstallation

bash uninstall.sh

File structure

vpn-automator/
├── vpn-monitor.sh              # Main monitoring daemon (runs in background)
├── connect-vpn.applescript     # AppleScript to click the VPN switch
├── com.user.vpnautomator.plist # LaunchAgent template
├── install.sh                  # Installer
├── uninstall.sh                # Uninstaller
├── .gitignore
└── README.md

config.env is generated by install.sh and stores your VPN name. It is excluded from version control.

Useful commands

# Watch logs in real time
tail -f ~/Library/Logs/vpn-automator.log

# Check service status
launchctl list com.user.vpnautomator

# Stop auto-connect
launchctl unload ~/Library/LaunchAgents/com.user.vpnautomator.plist

# Start auto-connect
launchctl load -w ~/Library/LaunchAgents/com.user.vpnautomator.plist

License

MIT

About

Automatically reconnects a macOS VPN(IPSec/IKEv2)when the connection drops or on system startup

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages