Configure IP Address and DNS from Command Line

本文介绍了一个简单的批处理脚本,该脚本可以用于快速切换Windows系统的本地连接IP地址,适用于需要频繁在局域网和独立端口间切换IP的场景。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

之前在使用电脑的时候经常遇到需要手动修改ip地址来实现在局域网和独立端口之间切换的问题,在windows下面这个过程显得比较繁琐,在linux下面我们可以通过新建一个vpn链接来实现过个本地链接,在windows下面不能实现这样的功能,所以便产生了用bat脚本来一键修改本地连接ip地址的想法。

基本信息如下:

@echo off 
cls 
color 4A 
title ip_change
echo IP地址更改小工具 
set IP=115.156.219.37
set MASK=255.255.255.224 
set GATEWAY=115.156.219.62
set NAME="本地连接" 


set IP1=192.168.0.37
set MASK1=255.255.255.0 
set GATEWAY1=192.168.0.1
set NAME1="本地连接" 


echo. 
echo 独立端口 请按 1 
echo. 
echo 局域网 请按 2 


set /p KEY= [您的选择是:] 
if %KEY% == 1 goto ONE 
if %KEY% == 2 goto TWO 


:ONE 
echo 正在更改成独立端口...... 
netsh interface ip set address %NAME% static %IP% %MASK% %GATEWAY% 
netsh interface ip add dns %NAME%  202.112.20.131
netsh interface ip add dns %NAME%  202.114.0.242 index=2
echo 更改结束 
exit


:TWO
echo 正在更改成局域网ip
netsh interface ip set address %NAME1% static %IP1% %MASK1% %GATEWAY1% 
netsh interface ip add dns %NAME1%  202.112.20.131
netsh interface ip add dns %NAME1%  202.114.0.242 index=2
echo 更改结束 
exit

====================================分割线=================================================

下面就是netsh用于修改ip信息的相关命令的介绍。

The IP address of your computer can be set from the command prompt by running the following commands at an administrative level prompt:

netsh interface ip set address name="Local Area Connection" static 123.123.123.123 255.255.255.0 123.123.123.1 1

Local Area Connection is the name of the adapter you want to modify. In single NIC systems it is normally called Local Area Connection.

123.123.123.123 is the IP address you want to set. 

255.255.255.0 is the subnet mask. 

123.123.123.1 is the gateway.

1 is the gateway metric. You can leave this as 1 for almost all cases.  

If you want to enable DHCP you can run:

netsh interface ip set address name="Local Area Connection" dhcp

There are two commands for DNS since administrators typically configure a primary and secondary DNS server. 

For the primary DNS run:

netsh interface ip set dns name="Local Area Connection" static 208.67.222.222

For the secondary run:

netsh interface ip add dns name="Local Area Connection" 208.67.220.220 index=2

If you want to configure the computer to use DNS from DHCP run:

netsh interface ip set dnsservers name="Local Area Connection" source=dhcp

When you are finished with all of your IP and DNS changes run ipconfig -all to review the new settings. 

‘’‘PS C:\Users\TY> step-ca --db-options '{"Truncate":true}' C:/Users/TY/.step/config/ca.json Incorrect Usage. flag provided but not defined: -db-options NAME step-ca -- an online certificate authority for secure automated certificate management USAGE step-ca [config] [--context=name] [--password-file=file] [--ssh-host-password-file=file] [--ssh-user-password-file=file] [--issuer-password-file=file] [--resolver=addr] [--help] [--version] DESCRIPTION step-ca runs the Step Online Certificate Authority (Step CA) using the given configuration. See the README.md for more detailed configuration documentation. POSITIONAL ARGUMENTS config File that configures the operation of the Step CA; this file is generated when you initialize the Step CA using 'step ca init' OPTIONS --password-file=file path to the file containing the password to decrypt the intermediate private key. --ssh-host-password-file=file path to the file containing the password to decrypt the private key used to sign SSH host certificates. If the flag is not passed it will default to --password-file. --ssh-user-password-file=file path to the file containing the password to decrypt the private key used to sign SSH user certificates. If the flag is not passed it will default to --password-file. --issuer-password-file=file path to the file containing the password to decrypt the certificate issuer private key used in the RA mode. --resolver=value address of a DNS resolver to be used instead of the default. --token=value token used to enable the linked ca. --quiet disable startup information --context=name the name of the authority's context. --acme-http-port=port the port used on http-01 challenges. It can be changed for testing purposes. Requires --insecure flag. --acme-tls-port=port the port used on tls-alpn-01 challenges. It can be changed for testing purposes. Requires --insecure flag. --acme-strict-fqdn enable strict DNS resolution using a fully qualified domain name. --pidfile=file the path to the file to write the process ID. --insecure enable insecure flags. --help, -h show help --version, -v print the version EXIT CODES This command will run indefinitely on success and return >0 if any error occurs. EXAMPLES These examples assume that you have already initialized your PKI by running 'step ca init'. If you have not completed this step please see the 'Getting Started' section of the README. Run the Step CA and prompt for password: $ step-ca $STEPPATH/config/ca.json Run the Step CA and read the password from a file - this is useful for automating deployment: $ step-ca $STEPPATH/config/ca.json --password-file ./password.txt Run the Step CA for the context selected with step and a custom password file: $ step context select ssh $ step-ca --password-file ./password.txt Run the Step CA for the context named mybiz and prompt for password: $ step-ca --context=mybiz Run the Step CA for the context named mybiz and an alternate ca.json file: $ step-ca --context=mybiz other-ca.json Run the Step CA for the context named mybiz and read the password from a file - this is useful for automating deployment: $ step-ca --context=mybiz --password-file ./password.txt COMMANDS help, h display help for the specified command or command group version display the current version of the cli export export the current configuration of step-ca onboard configure and run step-ca from the onboarding guide ONLINE This documentation is available online at https://smallstep.com/docs/certificates VERSION Smallstep CA/0.28.3-rc2 (windows/amd64) COPYRIGHT (c) 2018-2025 Smallstep Labs, Inc. FEEDBACK 😍 🍻 The step-ca utility is not instrumented for usage statistics. It does not phone home. But your feedback is extremely valuable. Any information you can provide regarding how you’re using step-ca helps. Please send us a sentence or two, good or bad: feedback@smallstep.com or https://github.com/smallstep/certificates/discussions. flag provided but not defined: -db-options’‘’你看看这个是不是成功修复了
最新发布
07-10
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值