在 Windows 上限速

最後更新: 2020-08-12

介紹

方法

  • Policy-Based QoS
  • NetQoS

 


Policy-Based QoS

 

Differentiated services code point (DSCP) value to specify the priority of traffic.

OS >= s2008r2

ON DC Domain Only

設定

Group Policy Management Console (GPMC) # gpedit.msc

...

* The QoS policy created by gpedit only creates policies for the "domain" network profile.

 


NetQoS

 

OS: 2012, 2016

PowerShell CLI

  • New-NetQosPolicy
  • Get-NetQosPolicy
  • Remove-NetQosPolicy
  • Set-NetQosPolicy

# Create a QoS policy that matches traffic to a subnet

PS C:\> New-NetQosPolicy -Name "Backup" -IPDstPrefixMatchCondition "192.168.234.0/24" -NetworkProfile Domain -DSCPAction 40

# Create a QoS policy that matches traffic sent to a port

PS C:\> New-NetQosPolicy -Name "HTTPS" -IPPort 443 -IPProtocol TCP -ThrottleRateActionBitsPerSecond 50MB

Name           : HTTPS
Owner          : Group Policy (Machine)
NetworkProfile : All
Precedence     : 127
JobObject      :
IPProtocol     : TCP
IPPort         : 443
ThrottleRate   : 52.429 MBits/sec

# Create a default QoS policy

PS C:\> New-NetQosPolicy -Name "Wildcard" -Default -MinBandwidthWeightAction 30

# Create a QoS policy that matches an application

New-NetQosPolicy -Name "FTP" -AppPathNameMatchCondition "ftp.exe" -ThrottleRateActionBitsPerSecond 1MB -PolicyStore ActiveStore

說明

---

-Name

Specifies the QoS policy name

-NetworkProfile

Specifies the profile, or connection type, of a network

Accepted values: Domain, Public, Private, All (DEFAULT)

-DSCPAction

Specifies the differentiated services code point (DSCP) value.

The acceptable values for this parameter are: 0 through 63.

---

-IPPort N

It can be either source port or destination port.

-IPSrcPortMatchCondition N

-IPDstPortMatchCondition N

---

-Default

Specifies a wildcard filter that can be used to capture all traffic that is not matched by any other filter.

-MinBandwidthWeightAction

Specifies a numerical value for minimum bandwidth that a flow should get relatively.

1 through 100.

---

-PolicyStore

Specifies the location of the policy that is stored.

If a policy is stored in ActiveStore, then the policy does not persist after restart.

The acceptable values for this parameter are:

  • ActiveStore
  • COMPUTERNAME (DEFAULT)
  • GPO:COMPUTERNAME -- GPO:DOMAIN\GPONAME -- LDAP://LDAP-URL

 

Get

PS C:\> Get-NetQoSPolicy

Name           : HTTPS
Owner          : Group Policy (Machine)
NetworkProfile : All
Precedence     : 127
JobObject      :
IPProtocol     : TCP
IPPort         : 443
ThrottleRate   : 52.429 MBits/sec

PS C:\> Get-NetQosPolicy -PolicyStore "ActiveStore"

If ActiveStore is specified as the location, the user will see all the effective QoS policies,

regardless of where the QoS policies are stored.

Remove

PS C:\> Remove-NetQosPolicy -Name "Backup"

Set

PS C:\> Set-NetQosPolicy -Name "Backup" -IPDstPortStart 3501 -IPDstPortEnd 3510

PS C:\> Get-NetQosPolicy -Name "wildcard" | Set-NetQosPolicy -Precedence 250

-Precedence

Specifies the priority of a QoS policy. (0 through 255, default value is 127)

A higher priority policy will override a lower priority policy in case the priorities are conflicting.

 


DSCP value

 

DSCP allows values from 0 to 63 to be specified within the TOS field of an IPv4 packet

By default, Windows traffic has a DSCP value of 0.

DSCP values are defined in RFC 2474.

0        Best Effort (Drop Probability: N/A) # Default
...
46      High Priority (Drop Probability: N/A)
...

RFC 791 precedence values

000 (0)Routine or Best Effort
001 (1)Priority
010 (2)Immediate
011 (3)Flash (mainly used for voice signaling or for video)
100 (4)Flash Override
101 (5)Critical (mainly used for voice RTP)
110 (6)Internet
111 (7)Network