Use powershell config network

来源:互联网 发布:怎么网络推广 编辑:程序博客网 时间:2024/04/30 08:31

1、打开Powershell 或在CMD下进入netsh/powershell
2、在netsh interface ip/ipv4 add/delete 设置有线网络或以太网IP,dns,route
3、查看网卡network Adapter 状态

实例1,Powershell 添加静态IP:

#参考命令PS C:\Windows\system32> <strong>netsh interface ipv4 Usage: add address [name=]<string>             [[address=]<IPv4 address>[/<integer> [[mask=]<IPv4 mask>]]                  [[type=]unicast|anycast]]             [[gateway=]<IPv4 address> [gwmetric=]<integer>]             [[validlifetime=]<integer>|infinite]             [[preferredlifetime=]<integer>|infinite]             [[subinterface=]<string>]             [[store=]active|persistent]             [[skipassource=]true|false]Examples:       add address "Wired Ethernet Connection" 10.0.0.2  255.0.0.0       add address "Wired Ethernet Connection" gateway=10.0.0.3 gwmetric=2       The first command adds a static IP address of 10.0.0.2 with a subnet       mask of 255.0.0.0 to the Wired Ethernet Connection interface. The second       command adds the IP address of 10.0.0.3 as a second default gateway       for this interface with a gateway metric of 2.#具体应用:PS C:\Windows\system32><strong> netsh interface ipv4 add address "AP"  192.168.1.1#检查配置PS C:\Windows\system32> netsh interface ip show addConfiguration for interface "AP"    DHCP enabled:                         No    <strong>IP Address:                       192.168.1.1   </strong>    Subnet Prefix:                        192.168.1.0/24 (mask 255.255.255.0)    IP Address:                           192.168.99.11    Subnet Prefix:                        192.168.99.0/24 (mask 255.255.255.0)    InterfaceMetric:                      20

实例2,删除添加的IP地址:

#参考命令PS C:\Windows\system32> <strong>netsh interface ipv4 deleteUsage: delete address [name=]<string> [[address=]<IPv4 address>]             [[gateway=]<IPv4 address>|all]             [[store=]active|persistent]Examples:       delete address "Wired Ethernet Connection" addr=10.0.0.1 gateway=all#具体应用:PS C:\Windows\system32> netsh interface ipv4 add neighbors "LAN"  "192.168.99.253" "00-19-be-70-ab-fd"PS C:\Windows\system32> netsh interface ipv4 add neighbors "LAN"  "192.168.99.223" "00-19-be-70-ab-df"#检查配置PS C:\Windows\system32> netsh interface ipv4 show neighborsInterface 1: Loopback Pseudo-Interface 1Internet Address                              Physical Address   Type--------------------------------------------  -----------------  -----------224.0.0.22                                                       Permanent239.255.255.250                                                  PermanentInterface 20: VirtualBox Host-Only NetworkInternet Address                              Physical Address   Type--------------------------------------------  -----------------  -----------192.168.56.255                                ff-ff-ff-ff-ff-ff  Permanent224.0.0.22                                    01-00-5e-00-00-16  Permanent224.0.0.252                                   01-00-5e-00-00-fc  Permanent239.77.124.213                                01-00-5e-4d-7c-d5  Permanent239.255.255.250                               01-00-5e-7f-ff-fa  PermanentInterface 15: LANInternet Address                              Physical Address   Type--------------------------------------------  -----------------  -----------192.168.99.12                                 8c-89-a5-f8-0e-32  Reachable192.168.99.20                                 00-00-00-00-00-00  Unreachable192.168.99.40                                 00-00-00-00-00-00  Unreachable192.168.99.54                                 00-00-00-00-00-00  Unreachable192.168.99.57                                 00-00-00-00-00-00  Unreachable192.168.99.73                                 00-00-00-00-00-00  Unreachable192.168.99.74                                 00-00-00-00-00-00  Unreachable192.168.99.80                                 00-00-00-00-00-00  Unreachable                    

实例3,添加和删除DNSServer

#参考命令Usage: set neighbors [interface=]<string> [address=]<IPv4 address>]             [neighbor=]<string>             [[store=]active|persistent]Parameters:       Tag              Value       interface      - Interface name or index.       address        - Network address of neighbor.       neighbor       - Link layer address of neighbor       store          - One of the following values:                        active: Address will disappear on next boot.                        persistent: Address will be persistent.                                    This is the default.Example:       set neighbors "Private" "10.1.1.1" "12-34-56-78-9a-bc"#具体应用:PS C:\Windows\system32> netsh interface ipv4 add neighbors "LAN"  "192.168.99.253" "00-19-be-70-ab-fd"PS C:\Windows\system32> netsh interface ipv4 add neighbors "LAN"  "192.168.99.223" "00-19-be-70-ab-df"#检查配置PS C:\Windows\system32> netsh interface ipv4 show neighborsInterface 1: Loopback Pseudo-Interface 1Internet Address                              Physical Address   Type--------------------------------------------  -----------------  -----------224.0.0.22                                                       Permanent239.255.255.250                                                  PermanentInterface 20: VirtualBox Host-Only NetworkInternet Address                              Physical Address   Type--------------------------------------------  -----------------  -----------192.168.56.255                                ff-ff-ff-ff-ff-ff  Permanent239.255.255.250                               01-00-5e-7f-ff-fa  PermanentInterface 15: LANInternet Address                              Physical Address   Type--------------------------------------------  -----------------  -----------192.168.99.12                                 8c-89-a5-f8-0e-32  Reachable192.168.99.198                                00-00-00-00-00-00  Unreachable192.168.99.223                                00-19-be-70-ab-df  Permanent192.168.99.253                                00-19-be-70-ab-fd  Permanent192.168.99.255                                ff-ff-ff-ff-ff-ff  Permanent                  Internet Address                              Physical Address   Type--------------------------------------------  -----------------  -----------10.6.161.1                                    38-22-d6-08-9a-32  Reachable10.6.161.67                                   00-1e-68-04-72-d8  Stale10.6.161.71                                   00-19-be-a3-06-f0  Stale10.6.161.255                                  ff-ff-ff-ff-ff-ff  Permanent

删除ARP
netsh interface ipv4 delete neighbors “LAN” “192.168.99.253” “00-19-be-70-ab-fd”

实例,添加和删除Route

#参考命令Usage: add route [prefix=]<IPv4 address>/<integer> [interface=]<string>             [[nexthop=]<IPv4 address>] [[siteprefixlength=]<integer>]             [[metric=]<integer>] [[publish=]no|age|yes]             [[validlifetime=]<integer>|infinite]             [[preferredlifetime=]<integer>|infinite]             [[store=]active|persistent]Parameters:       Tag                 Value       prefix            - Prefix for which to add a route.       interface         - Interface name or index.       nexthop           - Gateway address, if prefix is not on-link.       siteprefixlength  - Prefix length for the entire site, if on-link.       metric            - Route metric.       publish           - One of the following values:                           no: Not advertised in Route Advertisements.                               This is the default.                           age: Advertised in Route Advertisements                                with a finite lifetime.                           yes: Advertised in Route Advertisements                               with an infinite lifetime.       validlifetime     - Lifetime over which the route is valid.                           The default value is infinite.       preferredlifetime - Lifetime over which the route is preferred.                           The default is equal to the valid lifetime.       store             - One of the following values:                           active: Change only lasts until next boot.                           persistent: Change is persistent. This is                                       the default.Remarks: Adds a route for a given prefix.Example:       add route 10.2.0.0/16 "Internet" 10.0.0.1#具体应用:PS C:\Windows\system32> netsh interface ip add route 192.168.88.0/24 "LAN" 192.168.99.1Ok.#检查配置PS C:\Windows\system32> netsh interface ip show  routePublish  Type      Met  Prefix                    Idx  Gateway/Interface Name-------  --------  ---  ------------------------  ---  ------------------------No       Manual    1    0.0.0.0/0                  16  10.6.161.1No       System    256  10.6.161.0/24              16  EthernetNo       System    256  10.6.161.108/32            16  EthernetNo       System    256  10.6.161.255/32            16  EthernetNo       System    256  127.0.0.0/8                 1  Loopback Pseudo-Interface 1No       System    256  127.0.0.1/32                1  Loopback Pseudo-Interface 1No       System    256  127.255.255.255/32          1  Loopback Pseudo-Interface 1No       System    256  192.168.56.0/24            20  VirtualBox Host-Only NetworkNo       System    256  192.168.56.1/32            20  VirtualBox Host-Only NetworkNo       System    256  192.168.56.255/32          20  VirtualBox Host-Only NetworkNo       Manual    256  192.168.88.0/24            15  192.168.99.1No       System    256  192.168.99.0/24            15  LAN

删除Route
PS C:\Windows\system32> netsh interface ip delete route 192.168.88.0/24 “LAN” 192.168.99.1
Ok.

原创粉丝点击