How to Setup a L2TP VPN Server on OS X

This is a fast guide on configuring OS X to act as an L2TP VPN Server. This can be accomplished with Apple’s Server App, but if you don’t mind running a few Terminal commands and adding a couple configuration files manually, you can save yourself $20 and go out to eat instead.

This guide also includes a workaround for a known bug in the general release of OS X 10.9 Mavericks in its implementation of racoon that prevents remote clients from being able to connect to your VPN server.

Preamble

Estimated Time Required: 10-15 minutes
Tested on: OS X 10.8 Mountain Lion, OS X 10.9 Mavericks

Setup port forwarding

If your future server is behind a router, you’ll most likely need to setup port forwarding for the following ports:

  • UDP 500 for ISAKMP/IKE
  • UDP 1701 for L2TP
  • UDP 4500 for IPsec NAT Traversal
  • Optional: TCP 1723 for PPTP

Apple has more information on common ports used.

OS X 10.9 Mavericks fix

This step is only required on OS X 10.9 Mavericks

In OS X Mavericks, there was a change to the /usr/sbin/racoon program which breaks L2TP access from remote clients when traversing NAT. This is a known bug and I have filed a bug report with Apple. This also breaks Apple’s own Server App since it simply automates what we’re doing manually here. There are two known solutions.

Solution 1: Use a modified variation of the official fix . This modified installer does not check for the existence of the Apple Server.app. Download the modified package MavericksVPNUpdateServerAppLess.pkg.

Also checkout the official Apple KB article on this problem and their fix for users who have the Server.app installed on their systems.

Solution 2: Replace /usr/sbin/racoon with a version from Mountain Lion. If you don’t have your own backup available, you can download my backup of racoon from Mountain Lion. Simply unzip, move the executable into /usr/sbin, and reboot your Mac [or kill and restart racoon].

For example:

Add a shared secret to your keychain

Run the following command in Terminal after replacing SHARED-SECRET-PHRASE with your own secret phrase. When you login to your VPN server from a client, both an account password and secret phrase will be needed.

Configure Apple’s vpnd Service

Download Example configuration files (and racoon binary from Mountain Lion)

Modify the configuration file com.apple.RemoteAccessServers.plist below and save it to the following location. Set ownership to root:wheel and chmod 644.

You need to modify the following lines with your own information:

  • Lines 19-20 under “OfferedServerAddresses”

    These two lines should be changed to the DNS domains you want your VPN clients to use. In this example, I’m providing my local router (10.0.1.1) and a Google DNS domain as a secondary (8.8.4.4).

  • Lines 29-30 under “DestAddressRanges”

    These two lines specify the start and end IP address range that will be given to clients when they login. In this example, my clients are given an IP address between 10.0.1.250 and 10.0.1.254. Ideally, you should choose a range that is outside of the range that your router will assign so that you avoid IP address conflicts. For example, my router is configured with a DHCP range of 10.0.1.2 to 10.0.249.

This configuration file also enables PPTP in addition to L2TP. If you wish to enable this as well, modify lines 84-85 and 94-95.

Create a Launchd profile

Take the com.apple.ppp.l2tp.plist plist configuration file below and save it to the following location. Set ownership to root:wheel and chmod 644.

Launchd Loading and Unloading

This command will load the launchd configuration and start the vpnd service. The VPN service will automatically start when you reboot your computer.

This command will unload the launchd configuration and stop the vpnd service. This will also stop VPN services from starting when you reboot.

Troubleshooting

If things just aren’t working, take a look in Console to see what errors vpnd is reporting.

95 comments… add one
  • Giorgos Mar 6, 2021 Link Reply

    Hello,
    I try to use this guide to run VPN on my 2020 Mac mini with Big Sur.
    Does it work on Big Sur?
    When I start the .plist file, I see in the console the following error: (I erased the timestamps)

    Loading plugin /System/Library/SystemConfiguration/PPPController.bundle/Contents/PlugIns/L2TP.ppp
    Unable to load plugin (error = -1)
    Initialization of vpnd plugin failed

    Any ideas?

    • Jon Stacey Mar 6, 2021 Link Reply

      I haven’t tried this on Bug Sur so it adjustments might be needed. However, I suggest looking into WireGuard instead. It’s the future of VPN.

      • Giorgos Mar 6, 2021 Link Reply

        Since I have a few users connecting to my current VPN (old iMac), I want to keep those settings in all clients.
        I will give another try on an clean install in a vm on my macbook to see if there is some kind of problem with the installation on the mac mini m1.
        I will report back.

        • Giorgos Mar 6, 2021 Link

          Unfortunately same errors on my 2015 macbook pro with Big Sur.
          Maybe something changed with Big Sur or maybe even earlier.
          Thanks Jon.

  • Aaron Jan 4, 2021 Link Reply

    This was super helpful… even years later! Took me hours of researching to finally fix the issues I was having, mostly related to improper setup. That said, there are a couple updates that need to occur, namely the com.apple.ppp.l2tp.plist script is out of date. Apple tried to update this on their MacOS Server Mitigation pdf released in 2018, but had some typos. Refer to this stackexchange for updated instructions. https://apple.stackexchange.com/questions/342129/server-app-how-to-fix-re-enable-broken-vpn-after-update-to-mojave

  • John Dec 30, 2018 Link Reply

    VPN is still working great. But I’m wondering if vpnd has any type of status command? I would like to be able to load a list of all current VPN connections. Ideally with their authentication user, the hosts external IP address, and the age of the connection. Their internal VPN IP address might also be useful. Man vpnd comes up unhelpful.

  • John Mar 13, 2018 Link Reply

    Just set this up on an Xserve running 10.11. Worked perfectly. I set up a new user account on the machine for use just with vpn connections. That user and the vpn shared secret are both absurdly long random string. Connects from native VPN client in OS X perfectly, like a charm.

Leave a Comment

Time limit is exhausted. Please reload CAPTCHA.