How to Setup a L2TP VPN Server on OS X

November 13, 2013 · 49 comments

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 and 10.9.1 Mavericks fix

This step is only required on OS X 10.9 and 10.9.1 (Mavericks). Apple has finally fixed this bug in 10.9.2.

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:

1
2
3
sudo mv /usr/sbin/racoon ~/Desktop/racoon.bak
sudo mv ~/Downloads/racoon /usr/sbin/racoon
sudo killall racoon

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.

1
sudo security add-generic-password -a com.apple.ppp.l2tp -s com.apple.net.racoon -T /usr/sbin/racoon -p "SHARED-SECRET-PHRASE" /Library/Keychains/System.keychain

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.

1
/Library/Preferences/SystemConfiguration/com.apple.RemoteAccessServers.plist

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.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>ActiveServers</key>
    <array>
        <string>com.apple.ppp.l2tp</string>
    </array>
    <key>Servers</key>
    <dict>
        <key>com.apple.ppp.l2tp</key>
        <dict>
            <key>DNS</key>
            <dict>
                <key>OfferedSearchDomains</key>
                <array/>
                <key>OfferedServerAddresses</key>
                <array>
                    <string>10.0.1.1</string>
                    <string>8.8.4.4</string>
                </array>
            </dict>
            <key>IPv4</key>
            <dict>
                <key>ConfigMethod</key>
                <string>Manual</string>
                <key>DestAddressRanges</key>
                <array>
                    <string>10.0.1.250</string>
                    <string>10.0.1.254</string>
                </array>
            </dict>
            <key>Interface</key>
            <dict>
                <key>SubType</key>
                <string>L2TP</string>
                <key>Type</key>
                <string>PPP</string>
            </dict>
            <key>L2TP</key>
            <dict>
                <key>IPSecSharedSecret</key>
                <string>com.apple.ppp.l2tp</string>
                <key>IPSecSharedSecretEncryption</key>
                <string>Keychain</string>
                <key>Transport</key>
                <string>IPSec</string>
            </dict>
            <key>PPP</key>
            <dict>
                <key>AuthenticatorACLPlugins</key>
                <array>
                    <string>DSACL</string>
                </array>
                <key>LCPEchoEnabled</key>
                <integer>1</integer>
                <key>LCPEchoFailure</key>
                <integer>5</integer>
                <key>LCPEchoInterval</key>
                <integer>60</integer>
                <key>Logfile</key>
                <string>/var/log/ppp/vpnd.log</string>
                <key>VerboseLogging</key>
                <integer>1</integer>
            </dict>
            <key>Server</key>
            <dict>
                <key>Logfile</key>
                <string>/var/log/ppp/vpnd.log</string>
                <key>MaximumSessions</key>
                <integer>128</integer>
                <key>VerboseLogging</key>
                <integer>1</integer>
            </dict>
        </dict>
        <key>com.apple.ppp.pptp</key>
        <dict>
            <key>DNS</key>
            <dict>
                <key>OfferedSearchDomains</key>
                <array/>
                <key>OfferedServerAddresses</key>
                <array>
                    <string>10.0.1.1</string>
                    <string>8.8.4.4</string>
                </array>
            </dict>
            <key>IPv4</key>
            <dict>
                <key>ConfigMethod</key>
                <string>Manual</string>
                <key>DestAddressRanges</key>
                <array>
                    <string>10.0.1.250</string>
                    <string>10.0.1.254</string>
                </array>
            </dict>
            <key>Interface</key>
            <dict>
                <key>SubType</key>
                <string>PPTP</string>
                <key>Type</key>
                <string>PPP</string>
            </dict>
            <key>PPP</key>
            <dict>
                <key>AuthenticatorACLPlugins</key>
                <array>
                    <string>DSACL</string>
                </array>
                <key>CCPEnabled</key>
                <integer>1</integer>
                <key>CCPProtocols</key>
                <array>
                    <string>MPPE</string>
                </array>
                <key>LCPEchoEnabled</key>
                <integer>1</integer>
                <key>LCPEchoFailure</key>
                <integer>5</integer>
                <key>LCPEchoInterval</key>
                <integer>60</integer>
                <key>Logfile</key>
                <string>/var/log/ppp/vpnd.log</string>
                <key>MPPEKeySize128</key>
                <integer>0</integer>
                <key>MPPEKeySize40</key>
                <integer>1</integer>
                <key>VerboseLogging</key>
                <integer>1</integer>
            </dict>
            <key>Server</key>
            <dict>
                <key>Logfile</key>
                <string>/var/log/ppp/vpnd.log</string>
                <key>MaximumSessions</key>
                <integer>128</integer>
                <key>VerboseLogging</key>
                <integer>1</integer>
            </dict>
        </dict>
    </dict>
</dict>
</plist>

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.

1
/Library/LaunchDaemons/com.apple.ppp.l2tp.plist
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
 <?xml version=”1.0″ encoding=”UTF-8″?>
<!DOCTYPE plist PUBLIC “-//Apple//DTD PLIST 1.0//EN”
“http://www.apple.com/DTDs/PropertyList-1.0.dtd“>
<plist version=”1.0″>
    <dict>
        <key>Label</key>
        <string>com.apple.ppp.l2tp</string>
        <key>ProgramArguments</key>
        <array>
            <string>/usr/sbin/vpnd</string>
            <string>-x</string>
            <string>-i</string>
            <string>com.apple.ppp.l2tp</string>
        </array>
        <key>OnDemand</key>
        <false/>
    </dict>
</plist>

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.

1
sudo launchctl load -w /Library/LaunchDaemons/com.apple.ppp.l2tp.plist

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

1
sudo launchctl unload -w /Library/LaunchDaemons/com.apple.ppp.l2tp.plist

Troubleshooting

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

{ 48 comments… read them below or add one }

Matt September 1, 2014 at 7:54 pm

I set everything up and it worked. The issue I have (Snow Leopard – I know – untested) is that I can log in with any account and password, even an account that doesn’t exist on the Mac. Any ideas?

Reply

Spike Lightfoot August 27, 2014 at 10:48 pm

Thanks for doing this!!

Reply

Leave a Comment

{ 1 trackback }

Previous post:

Next post: