Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Establish a VPN connection in cmd

Tags:

windows

cmd

vpn

How can I create a VPN connection with an arbitrary server using an arbitrary protocol in Windows cmd?

like image 798
user1892542 Avatar asked Jan 30 '13 21:01

user1892542


People also ask

How do I find my VPN IP address using CMD?

You can also find your private IP address by running “ipconfig/all” in Command Prompt – this works on all modern versions of Windows. If you're using Wi-Fi to connect to the local network, you'll be able to find your private IP address under the “Wireless LAN adapter Local Area Connection” section.


2 Answers

I know this is a very old thread but I was looking for a solution to the same problem and I came across this before eventually finding the answer and I wanted to just post it here so somebody else in my shoes would have a shorter trek across the internet.

****Note that you probably have to run cmd.exe as an administrator for this to work**

So here we go, open up the prompt (as an adminstrator) and go to your System32 directory. Then run

C:\Windows\System32>cd ras

Now you'll be in the ras directory. Now it's time to create a temporary file with our connection info that we will then append onto the rasphone.pbk file that will allow us to use the rasdial command.

So to create our temp file run:

C:\Windows\System32\ras>copy con temp.txt

Now it will let you type the contents of the file, which should look like this:

[CONNECTION NAME] MEDIA=rastapi Port=VPN2-0 Device=WAN Miniport (IKEv2) DEVICE=vpn PhoneNumber=vpn.server.address.com 

So replace CONNECTION NAME and vpn.server.address.com with the desired connection name and the vpn server address you want.

Make a new line and press Ctrl+Z to finish and save.

Now we will append this onto the rasphone.pbk file that may or may not exist depending on if you already have network connections configured or not. To do this we will run the following command:

C:\Windows\System32\ras>type temp.txt >> rasphone.pbk

This will append the contents of temp.txt to the end of rasphone.pbk, or if rasphone.pbk doesn't exist it will be created. Now we might as well delete our temp file:

C:\Windows\System32\ras>del temp.txt

Now we can connect to our newly configured VPN server with the following command:

C:\Windows\System32\ras>rasdial "CONNECTION NAME" myUsername myPassword

When we want to disconnect we can run:

C:\Windows\System32\ras>rasdial /DISCONNECT

That should cover it! I've included a direct copy and past from the command line of me setting up a connection for and connecting to a canadian vpn server with this method:

Microsoft Windows [Version 6.2.9200] (c) 2012 Microsoft Corporation. All rights reserved.  C:\Windows\system32>cd ras  C:\Windows\System32\ras>copy con temp.txt [Canada VPN Connection] MEDIA=rastapi Port=VPN2-0 Device=WAN Miniport (IKEv2) DEVICE=vpn PhoneNumber=ca.justfreevpn.com ^Z         1 file(s) copied.  C:\Windows\System32\ras>type temp.txt >> rasphone.pbk  C:\Windows\System32\ras>del temp.txt  C:\Windows\System32\ras>rasdial "Canada VPN Connection" justfreevpn 2932 Connecting to Canada VPN Connection... Verifying username and password... Connecting to Canada VPN Connection... Connecting to Canada VPN Connection... Verifying username and password... Registering your computer on the network... Successfully connected to Canada VPN Connection. Command completed successfully.  C:\Windows\System32\ras>rasdial /DISCONNECT Command completed successfully.  C:\Windows\System32\ras> 

Hope this helps.

like image 128
John Dorian Avatar answered Sep 20 '22 17:09

John Dorian


Have you looked into rasdial?

Just incase anyone wanted to do this and finds this in the future, you can use rasdial.exe from command prompt to connect to a VPN network

ie rasdial "VPN NETWORK NAME" "Username" *

it will then prompt for a password, else you can use "username" "password", this is however less secure

http://www.msfn.org/board/topic/113128-connect-to-vpn-from-cmdexe-vista/?p=747265

like image 21
LNendza Avatar answered Sep 18 '22 17:09

LNendza