Home>

Windows10 default gateway settings
■ Environment
OS: Windows10
Command prompt batch file

Error message

When you exit with a VPN software, the default gateway set with static IP disappears.
I made an inquiry to the company that produces this software, but it was answered that there was no solution.
■ Solution
Since there are hundreds of people, I want to create and deploy a batch file.
In order to set the default gateway to a batch file, it is necessary to set the IP address + subnet mask + default gateway.
Since the IP address has not disappeared, I think it is necessary to extract the IP address of each PC and set the default gateway.

Applicable source code

I tried to create the following as a beginner, but it didn't work. . I would appreciate your teaching.
■ Command * mask and gateway are described appropriately. All subnet masks are/24
Get REM IP address
for/F "tokens = 15"% i in ('ipconfig ^ | find "IPv4 address"') do @set MYIP =% i
REM IP address setting
netsh interface ipv4 set add name = "Ethernet" source = static addr = "% MYIP%" mask = "255.255.255.0" gateway = "192.168.1.1" gwmetric = 1

  • Answer # 1

    Assuming you are writing as is,

    First.
    % iis input from the command line, and%% iwhen writing to a batch file.

    Second.
    The commandset MYIP = 1.1.1.1setsblank 1.1.1.1to the environment variableMYIP space.
    If you want to set1.1.1.1to the environment variableMYIP,set MYIP = 1.1.1.1.
    (Environment variable names can contain spaces and some symbols)

Trends