netsh cli

最後更新: 2018-09-12

目錄

  • To show a list of the network interfaces
  • enable nic
  • rename nic
  • 改 DHCP, IP, DNS
  • 重設 TCP/IP
  • portproxy
  • routing

 


To show a list of the network interfaces

 

# 獲得 Idx, MTU, State, Name

netsh interface ipv4 show interfaces    # 縮寫 "netsh int ip show int"

Idx     Met         MTU          State                Name
---  ----------  ----------  ------------  ---------------------------
  1          75  4294967295  connected     Loopback Pseudo-Interface 1
 15          25        1500  connected     wan

# Admin State

netsh interface show interface

Admin State    State          Type             Interface Name
-------------------------------------------------------------------------
Enabled        Connected      Dedicated        wan

ipconfig | findstr "adapter"

Ethernet adapter wan:

 


Enable NIC

 

netsh interface set interface "lan2" enable

 


Rename NIC

 

netsh interface set interface name = "Local Area Connection 5" newname = "iSCSI1"

 


改 DHCP, IP, DNS

 

Show interfaces name with index

netsh interface ipv4 show interfaces

Show Setting

netsh interface ipv4 show config [NIC_Name]

i.e.

netsh interface ipv4 show config wan

Configuration for interface "wan"
    DHCP enabled:                         No
    IP Address:                           192.168.18.179
    Subnet Prefix:                        192.168.18.0/24 (mask 255.255.255.0)
    IP Address:                           192.168.88.177
    Subnet Prefix:                        192.168.88.0/24 (mask 255.255.255.0)
    Default Gateway:                      192.168.88.1
    Gateway Metric:                       256
    InterfaceMetric:                      25
    Statically Configured DNS Servers:    8.8.8.8
                                          8.8.4.4
    Register with which suffix:           Primary only
    Statically Configured WINS Servers:   None

Set Static IP

 * 要用 dhcp service 才可以 set 到 IP

netsh interface ipv4 set address name="YOUR INTERFACE NAME" static IP MASK GATEWAY

Or

netsh interface ipv4 set address INDEX static IP MASK GATEWAY

i.e.

netsh interface ipv4 set address wan static 192.168.88.123 255.255.255.0 192.168.88.1

OR

netsh interface ipv4 set address 12 static 192.168.88.123 255.255.255.0 192.168.88.1

(!!)

# 相當於拎走 NIC 上的 IP

netsh interface ipv4 set address wan

Set DHCP

net start dhcp

netsh interface ipv4 set address wan source=dhcp

To change DNS:

netsh interface ipv4 set dns ID static DNS_SERVER_IP

Or

netsh interface ipv4 set dns name="NIC_NAME" static DNS_SERVER_IP

i.e.

netsh int ip set dns 11 static 192.168.0.1

Troubleshoot

rpc server is unavailable

net start dhcp

 


重設 TCP/IP

 

Windows XP:

netsh winsock reset c:\resetlog.txt

c:\resetlog.txt  <-- log file

Win7:

netsh int ip reset resetlog.txt

此指令會修正:

* SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\

* SYSTEM\CurrentControlSet\Services\DHCP\Parameters\

 


portproxy

 

OS: Win7, S2008

** 功能類似 rinetd
** 來源網路位址會係 Server IP !!!

Usage

# add

netsh interface portproxy add v4tov4 listenport=33389 listenaddress=WANIP1 connectport=443 connectaddress=WANIP2

# 當 Server 有多個 WANIP 時, 才要用 "listenaddress=WANIP"

netsh interface portproxy add v4tov4 listenport=22 connectport=22 connectaddress=w.w.w.w

# show

netsh interface portproxy show all

接聽 ipv4:             連線到 ipv4:

位址            連接埠      位址            連接埠
--------------- ----------  --------------- ----------
192.168.88.122  33389       192.168.88.122  3389

# reset

# 重設 portproxy 設定狀態(還原 Default)

netsh interface portproxy reset

 


routing

 

routing 係要安裝 Service 先有

 

OS: S2008

netsh routing ip nat add portmapping external tcp 0.0.0.0 33389 192.168.0.2 3389

 


 

 

 

 

Creative Commons license icon Creative Commons license icon