Windows juhend: Kuidas seadistada võrguühendusi Powershelli abil

From ICO wiki
Revision as of 12:53, 19 October 2012 by Hkaukver (talk | contribs)
Jump to navigationJump to search

JUHEND ON POOLELI

Sissejuhatus

Powershell on Microsofti poolt arendatud käsurea skriptimiskeel ja keskkond peaasjalikult administreerimisülesannete teostamiseks. Powershell sisaldab praegu üle 2300 sisemise käsu ehk cmdlet'i, andes niiviisi erinevate ülesannete automatiseerimiseks väga head võimalused. Käesolev juhend kehtib Windows 8 ja Powershell 3.0 kohta, ning põhirõhk on kaabliga etherneti ühenduste seadistamisel. Powershelli versiooni on kirjas muutujas $Host.Version.

Major ja Minor näitavad Powershelli versiooni.


Võrguühendustega seotud käsud

Infot olemasolevate käskude kohta annab käsk Get-Command mille argumendiks võib olla käsu nime osa

PS C:\> Get-Command *net*

CommandType     Name                                               ModuleName
-----------     ----                                               ----------
Function        Add-NetIPHttpsCertBinding                          NetworkTransition
Function        Add-NetLbfoTeamMember                              NetLbfo
Function        Add-NetLbfoTeamNic                                 NetLbfo
Function        Add-NetSwitchTeamMember                            NetSwitchTeam
Function        Copy-NetFirewallRule                               NetSecurity
Function        Copy-NetIPsecMainModeCryptoSet                     NetSecurity
Function        Copy-NetIPsecMainModeRule                          NetSecurity
Function        Copy-NetIPsecPhase1AuthSet                         NetSecurity
Function        Copy-NetIPsecPhase2AuthSet                         NetSecurity
Function        Copy-NetIPsecQuickModeCryptoSet                    NetSecurity
Function        Copy-NetIPsecRule                                  NetSecurity
Function        Disable-NetAdapter                                 NetAdapter
Function        Disable-NetAdapterBinding                          NetAdapter
Function        Disable-NetAdapterChecksumOffload                  NetAdapter
........        ................                                   ..............
Function        Set-NetRoute                                       NetTCPIP
Function        Set-NetTCPSetting                                  NetTCPIP
Function        Set-NetTeredoConfiguration                         NetworkTransition
Function        Set-NetUDPSetting                                  NetTCPIP
Function        Show-NetFirewallRule                               NetSecurity
Function        Show-NetIPsecRule                                  NetSecurity
Function        Sync-NetIPsecRule                                  NetSecurity
Function        Update-NetIPsecRule                                NetSecurity
Cmdlet          New-NetIPsecAuthProposal                           NetSecurity
Cmdlet          New-NetIPsecMainModeCryptoProposal                 NetSecurity
Cmdlet          New-NetIPsecQuickModeCryptoProposal                NetSecurity
Application     CheckNetIsolation.exe
Application     gatherNetworkInfo.vbs
Application     inetcpl.cpl
Application     net.exe
Application     net1.exe
Application     netbtugc.exe
Application     netcfg.exe
Application     netiougc.exe
Application     Netplwiz.exe
Application     netsh.exe
Application     NETSTAT.EXE

Abiinfot konkreetse käsu kohta annab Get-Help

PS C:\> Get-Help Get-NetAdapter

NAME
    Get-NetAdapter

SYNOPSIS
    Gets the basic network adapter properties.
.................................................................

    To see the examples, type: "get-help Get-Help -examples".
    For more information, type: "get-help Get-Help -detailed".
    For technical information, type: "get-help Get-Help -full".
    For online help, type: "get-help Get-Help -online"


Võrguseadistamise tegevused

Võrguseadmete info

Enne kui saame seadistama asuda on vaja infot millised võrguseadmed meil kasutada on. Lühikese loetelu annab Get-Adapter.

PS C:\> Get-NetAdapter

Name                      InterfaceDescription                    ifIndex Status       MacAddress             LinkSpeed
----                      --------------------                    ------- ------       ----------             ---------
Ethernet 3                Intel(R) PRO/1000 MT Desktop Adapter #3      16 Disconnected 08-00-27-D8-97-EE          0 bps
Ethernet 2                Intel(R) PRO/1000 MT Desktop Adapter #2      15 Up           08-00-27-43-7D-59         1 Gbps
Ethernet                  Intel(R) PRO/1000 MT Desktop Adapter         12 Up           08-00-27-8F-EC-5E         1 Gbps


IP seadistuse info annab Get-NetIPConfiguration

PS C:\> Get-NetIPConfiguration


InterfaceAlias       : Ethernet 2
InterfaceIndex       : 15
InterfaceDescription : Intel(R) PRO/1000 MT Desktop Adapter #2
NetProfile.Name      : Unidentified network
IPv4Address          : 169.254.191.114
IPv6DefaultGateway   :
IPv4DefaultGateway   :
DNSServer            : fec0:0:0:ffff::1
                       fec0:0:0:ffff::2
                       fec0:0:0:ffff::3

InterfaceAlias       : Ethernet
InterfaceIndex       : 12
InterfaceDescription : Intel(R) PRO/1000 MT Desktop Adapter
NetProfile.Name      : Network  2
IPv4Address          : 10.0.2.15
IPv6DefaultGateway   :
IPv4DefaultGateway   : 10.0.2.2
DNSServer            : 10.59.1.1

InterfaceAlias       : Ethernet 3
InterfaceIndex       : 16
InterfaceDescription : Intel(R) PRO/1000 MT Desktop Adapter #3
NetAdapter.Status    : Disconnected


Võrguseadme sisse ja välja lülitamine

Võrguseadmeid lülitavad käsud Enable-NetAdapter ja Disable-NetAdapter. Mõlemale käsule võib argumendina järgi anda võrguseadme nime. Kui seda ei tehta, siis küsitakse seda interaktiivselt.

PS C:\> Disable-NetAdapter "Ethernet 2"

Confirm
Are you sure you want to perform this action?
Disable-NetAdapter 'Ethernet 2'
[Y] Yes  [A] Yes to All  [N] No  [L] No to All  [S] Suspend  [?] Help (default is "Y"): Y
PS C:\> Enable-NetAdapter

cmdlet Enable-NetAdapter at command pipeline position 1
Supply values for the following parameters:
Name[0]: ethernet 2
Name[1]:
PS C:\>


Võrguseadme IP määramine

Võrguseadmele määrab staatilise IP aadressi koos lisaparameetritega New-NetIPAddress.

PS C:\> New-NetIPAddress -InterfaceAlias "Ethernet 2" -IPAddress 192.168.100.100 -DefaultGateway 192.168.100.1 -PrefixLength 24
  • InterfaceAlias' on võrguseadme nimi. Kui nimi sisaldab tühikuid, siis tuleb nimi panna jutumärkide vahele.
  • IPAddress on määratav IP aadress
  • DefaultGateway on võrgusegmendi lüüs
  • PrefixLength on võrgumask bittides (0-32), sisevõrkudes üsna tihti 24.