Jump to content

Featured Replies

Posted

🔒 How to Connect to a VPN Using Windows CMD (Command Prompt) – Step-by-Step Guide

Most people use the built-in VPN settings in Windows through the graphical interface. But if you love working from the command line or want a quicker way to connect, Command Prompt (CMD) gives you powerful control over your VPN connections.

In this guide, you'll learn how to set up and connect to a VPN using just CMD on Windows.

🧰 What You Need Before Starting

  • Windows 10 or 11

  • VPN credentials (server address, username, password)

  • An existing VPN profile (PPTP, L2TP, SSTP, or IKEv2)

You must have administrator access to create and manage VPN connections via CMD.

🛠 Step 1: Create a VPN Connection Using CMD

  1. Open Command Prompt as Administrator

    Press Win + S, type cmd, right-click on it, and select Run as administrator.

  2. Run the following command to create a VPN connection:

rasphone -a

This opens the Network Connection Wizard. You can manually enter the VPN details like server address, VPN type (PPTP, L2TP, etc.), and credentials.

Alternatively, you can automate this using PowerShell or netsh, but rasphone -a is the easiest interactive method.

💻 Step 2: Connect to the VPN via CMD

Once you’ve saved your VPN profile (e.g., called MyVPN), connect using this command:

rasdial "MyVPN" username password

Replace:

  • MyVPN with your VPN profile name

  • username and password with your actual login details

✅ Example:

rasdial "MyVPN" john_doe mypass123

🔌 Step 3: Disconnect the VPN

To disconnect your VPN:

rasdial "MyVPN" /disconnect

🧠 Extra Tips

  • Use rasdial without arguments to check active connections:

rasdial
  • If you get an error, check that your VPN profile is named exactly as you typed it.

  • If your VPN needs a pre-shared key (for L2TP), you’ll need to set that up manually in the Windows GUI first.

Using CMD to manage your VPN on Windows gives you quick access, automation potential, and a lightweight way to connect or disconnect. Great for sysadmins, developers, or anyone who loves efficiency.

Create an account or sign in to comment