…生活與工作…個人的生活雜記….

Windows ipconfig use netsh windows 切換IP

「windows」的圖片搜尋結果

為了不要每次在那切來切去,紀錄一下netsh用法,也可以做成批次檔執行(需Administrator權限)

IPv4 Pre-fix

set address [name=]InterfaceName [source=]{dhcp | static [addr=]IPAddress [mask=]SubnetMask [gateway=]{none | DefaultGateway[[gwmetric=]GatewayMetric]}}

Parameters

[ name =] InterfaceName
Required. Specifies the name of the interface for which you want to configure address and gateway information. The InterfaceNameparameter must match the name of the interface as specified in Network Connections. If InterfaceName contains spaces, use quotation marks around the text (for example, "Interface Name").
[ source=]{ dhcp| static[ addr=] IPAddress[ mask=] SubnetMask[ gateway=]{ none| DefaultGateway[[ gwmetric=] GatewayMetric]}}
Required. Specifies whether the IP address to configure originates from a Dynamic Host Configuration Protocol (DHCP) server or is static. If the address is static, IPAddress specifies the address to configure, and SubnetMask specifies the subnet mask for the IP address being configured. If the address is static, you must also specify whether you want to leave the current default gateway (if any) in place or configure one for the address. If you configure a default gateway, DefaultGateway specifies the IP address of the default gateway to be configured, and GatewayMetric specifies the metric for the default gateway to be configured.
/?
Displays help at the command prompt.

Example:

netsh interface ip set address "區域連線" static 192.168.1.2 255.255.255.0 192.168.1.1
netsh interface ip set dns "區域連線" static 168.95.1.1

IPv4 DHCP

Example:

netsh interface IP Set Address "區域連線" DHCP
netsh interface IP Set dns "區域連線" DHCP

IPv4 Static Route

set route [prefix=]IPv4Address/Integer [[interface=]String] [[nexthop=]IPv4Address] [[siteprefixlength=]Integer] [[metric=]Integer] [publish=]{no | yes immortal}] [[validlifetime=]{Integer infinite}] [[preferredlifetime=]{Integer | infinite}] [[store=]{active | persistent}]

Parameters

[ prefix=] IPv6Address/Integer
Required. Specifies the prefix (IPv6Address) and prefix length (Integer) of the route to modify.
[[ interface=] String]
Specifies an interface name or index.
[[ nexthop=] IPv6Address]
Specifies the gateway address, if the prefix is not on-link.
[[ siteprefixlength=] Integer]
Specifies the prefix length for the entire site, if the prefix is not on-link.
[[ metric=] Integer]
Specifies the route metric.
[[ publish=]{ no| yes| immortal}]
Specifies whether routes are advertised (yes), advertised with an infinite lifetime (immortal), or not advertised (no) in Route Advertisements. The default selection is no.
[[ validlifetime=]{ Integer| infinite}]
Specifies the lifetime over which the route is valid. The default value is infinite.
[[ preferredlifetime=]{ Integer| infinite}]
Specifies the lifetime over which the route is preferred. The default value is infinite.
[[ store=]{ active| persistent}]
Specifies whether the change lasts only until the next boot (active) or is persistent (persistent). The default selection is persistent.

Example:

set route 10.2.0.0/16 "Internet" 10.0.0.1 0 2 yes 5000 5000 store=active

IPv6 Pre-fix

set address [[interface=]String] [address=]IPv6Address [[type=]{unicast anycast}] [[validlifetime=]{Integer | infinite}] [[preferredlifetime=]{Integer | infinite}] [[store=]{active | persistent}]

Parameters

[[ interface=] String]
Specifies an interface name or index.
[ address=] IPv6Address
Required. Specifies the IPv6 address to modify.
[[ type=]{ unicast| anycast}]
Specifies whether the address is marked as a unicast address (unicast) or as an anycast address (anycast). The default selection is unicast.
[[ validlifetime=]{ Integer| infinite}]
Specifies the lifetime over which the address is valid. The default value is infinite.
[[ preferredlifetime=]{ Integer| infinite}]
Specifies the lifetime over which the address is preferred. The default value is infinite.
[[ store=]{ active| persistent}]
Specifies whether the change lasts only until the next boot (active) or is persistent (persistent). The default selection is persistent.

set route [prefix=]IPv6Address/Integer [[interface=]String] [[nexthop=]IPv6Address] [[siteprefixlength=]Integer] [[metric=]Integer] [publish=]{no | yes immortal}] [[validlifetime=]{Integer infinite}] [[preferredlifetime=]{Integer | infinite}] [[store=]{active | persistent}]

Parameters

[ prefix=] IPv6Address/Integer
Required. Specifies the prefix (IPv6Address) and prefix length (Integer) of the route to modify.
[[ interface=] String]
Specifies an interface name or index.
[[ nexthop=] IPv6Address]
Specifies the gateway address, if the prefix is not on-link.
[[ siteprefixlength=] Integer]
Specifies the prefix length for the entire site, if the prefix is not on-link.
[[ metric=] Integer]
Specifies the route metric.
[[ publish=]{ no| yes| immortal}]
Specifies whether routes are advertised (yes), advertised with an infinite lifetime (immortal), or not advertised (no) in Route Advertisements. The default selection is no.
[[ validlifetime=]{ Integer| infinite}]
Specifies the lifetime over which the route is valid. The default value is infinite.
[[ preferredlifetime=]{ Integer| infinite}]
Specifies the lifetime over which the route is preferred. The default value is infinite.
[[ store=]{ active| persistent}]
Specifies whether the change lasts only until the next boot (active) or is persistent (persistent). The default selection is persistent.

set dnsserver [name=]InterfaceName [source=]{dhcp static }[addr=]{IP Address | none} [register=]{none primary both}

參數

[ name=] 介面名稱
         需要。指定要為其設置DNS資訊的介面的名稱。介面名稱參數必須與網絡連接中指定的介面名稱相同。 如果介面名稱包含空格,請在周圍使用引號(例如,"介面名稱")。
[ source=]{ dhcp| static }
         需要。指定DNS服務器的IP地址是通過DHCP配置還是靜態的。
[ addr=]{ IP Address| none }
         如果IP地址是靜態的,則IP地址指定要配置的DNS服務器的IP地址,而無則指定應​​刪除DNS配置。
[ register=]{ none| primary| both }
         無指定是否禁用動態更新。 Primary(主要)僅在主要DNS後綴下註冊計算機名稱。兩者都在主要DNS後綴和特定於連接的後綴下註冊計算機名稱。
/?
         顯示本參數說明

範例:

netsh interface ipv6 set address "區域連線" 2001::2111
netsh interface ipv6 set route ::/0 "區域連線" 2001::1
netsh interface ipv6 set dnsserver "區域連線" static 2001:4860:4860::8888 primary