Saturday, July 10, 2021

Configure VPN client in Windows through PowerShell

 

We use PPTP, L2TP, L2TP/IPsec with Pre-shared Key type Dial-Up or Remote Access VPN in our Windows commuter. To Configure casually we use Network & Internet settings or Network and Sharing Center as adding a new adapter.

For Remote Access VPN keeping login credentials complex as much as possible is certainly a good practice. That is the thumb rule for VPN administration part but while a user need to configure it in his Windows PC/Laptop the complex credentials become a hurdles to create and type in GUI.

 In that case, using PowerShell is great. Command Line editing/modify in Notepad and a single shot to Powershell will do all. Here it is...

For PPTP or L2TP:

Open a Notepad first and then modify following command with your information.

Add-VpnConnection -Name "Test-PPTP" -ServerAddress "118.179.210.210" -TunnelType "Pptp" -RememberCredential -Force | rasdial.exe "Test-PPTP" "test" "1234"

Value Modification:

-Name = Give your desired VPN Name

-Server Address= Give your IP or Domain Name of Remote access Server

-TunnelType= Pptp/L2tp as required

In RAS (Remote Access Server) Dial rasdial.exe the first "" is -Name of the VPN. It need to be as equal given by you already. The second "" is VPN User and third "" is VPN Password.

Let's do a practical for clear understand.


In a MikroTik we create following VPN. VPN information is as followed.

VPN Type: PPTP

VPN Server IP: 118.179.210.210

VPN User: test

VPN Password: 1234

Now we run the command in Powershell.

After that our VPN is configured and already dialed for connect and successfully connected.

We connected it by "RASDIAL", it can not store the VPN User & Password info for future use and also users in future will use it from GUI.

So, lets disconnect this connected VPN now. Then click the Advanced options.



Then click Edit to edit the VPN info.

We just need to retype the Password as it is encrypted. Typing 1234 as given on information. Finally, click Save.

Thus, our VPN is ready for future use in GUI.

For L2TP/IPsec with Pre-shared key:

It is as same as all procedure like PPTP/L2TP just in command there is a modification.

Add-VpnConnection -Name "Test-L2TP" -ServerAddress "118.179.111.2" -TunnelType "L2tp" -L2tpPsk "Test2Hack" -RememberCredential -Force | rasdial.exe "Test-L2TP" "test" "1234"

As the VPN with Pre-shared key so in command -L2tpPsk added.

Value Modification:

-L2tpPsk = Give your desired Pre-shared Key.

Rest all are same to configure as demonstrated for PPTP/L2TP.









No comments:

Post a Comment

BGP Peer Open-Sent issue in MikroTik and a Solution by BGP monitor

The “Open-Sent” state in BGP (Border Gateway Protocol) indicates that the router has sent an OPEN message and is waiting for an OPEN message...