PowerShell RemoteAccess module (2/5)
Part 2 of the RemoteAccess module: site-to-site (S2S) VPN interfaces and their Connect/Disconnect/Clear cmdlets, BGP route flap dampening, the Enable-/Disable- cmdlets, and the read-only Get-Bgp*, Get-DA* and Get-RemoteAccess* cmdlets. The lab shows the BGP ideas live with FRRouting.
256.1 Why is it used?
- An S2S tunnel joins a branch network to head office permanently, without users clicking connect.
- Admins must be able to drop a user session or bounce a tunnel quickly.
- Flap dampening stops one unstable route from flooding the network with BGP updates.
- Get- cmdlets are the read-only health checks for BGP, DirectAccess and RRAS.
- Office PC: Count 0 for the module; IPsec needs kernel modules, so S2S/SSTP come from the docs and the lab is BGP only.
256.2 How it works
- Step 1
1.Head office RRAS 131.107.0.10 runs Add-VpnS2SInterface EDGE1
- Step 2
2.IKEv2 (UDP 500) goes over the internet to branch gateway EDGE1 131.107.0.20
- Step 3
3.Tunnel is Connected
- Step 4
4.Corp LAN 10.1.0.0/16 data enters the encrypted tunnel at RRAS
- Step 5
5.It crosses the internet and goes via EDGE1 to branch PCs in 10.2.0.0/24
- Step 1
1.router1 (AS 65001) and router2 (AS 65002) exchange OPEN + KEEPALIVE
- Step 2
2.router1 sends UPDATE 10.255.1.0/24, 10.255.11.0/24
- Step 3
3.10.255.11.0/24 is withdrawn and re-announced again and again (route flap)
- Step 4
4.router2 has dampening on: every flap adds a penalty
- Step 5
5.After 3 flaps the penalty crosses the suppress limit: *d 10.255.11.0/24 (damped)
- Step 6
6.Penalty decays (half-life); below the reuse limit or after Clear the route is used again
256.3 Add-VpnS2SInterface
- The biggest cmdlet (58 options); -Name and -Destination required.
- -Protocol IKEv2|SSTP|L2TP|Automatic; -AuthenticationMethod PSKOnly|EAP|MachineCertificates|MSCHAPv2 with -SharedSecret.
- -IPv4Subnet subnet:metric: traffic uses this interface only if no other interface has the same route with a lower metric.
- -Persistent, -RoutingDomain, -GreTunnel/-GreKey are for the multi-tenant gateway.
- IPsec policy via -CustomPolicy: -EncryptionMethod, -IntegrityCheckMethod, -DHGroup, -PfsGroup, -SALifeTimeSeconds.
- Dialing: -NumberOfTries 0 = infinite retry, -RetryIntervalSeconds, -IdleDisconnectSeconds, -NetworkOutageTimeSeconds 3..900.
Add-VpnS2SInterface -Name "EDGE1" 131.107.0.20 -Protocol IKEv2 ` -AuthenticationMethod PSKOnly -SharedSecret "ABC" ` -IPv4Subnet 10.2.0.0/24:100 Add-VpnS2SInterface -RoutingDomain Rd_001 -Name "Blue-Tunnel-2" ` -Protocol IKEv2 -Destination 100.0.0.7 -AuthenticationMethod PSKOnly ` -SharedSecret 111_aaa -Persistent -IPv4Subnet 172.23.90.4/32:100 -PassThruRoutingDomain Name Destination AdminStatus ConnectionState IPv4Subnet------------- ---- ----------- ----------- --------------- ----------Rd_001 Blue-Tunnel-2 {100.0.0.7} True Disconnected {172.23.90.4/32:100} # Example 5 with traffic selectors | fl * (trimmed)ConnectionState : ConnectedMMSALifeTime : 28800NetworkOutageTime : 15NumberOfTries : 3Protocol : Ikev2RetryInterval : 60SADataSizeForRenegotiation : 33553408SALifeTime : 3600256.4 Tunnel and session control
| Cmdlet | What it does |
|---|---|
| Connect-VpnS2SInterface -Name | Connects a disconnected S2S interface |
| Disconnect-VpnS2SInterface -Name | Takes the tunnel down, config stays (-Force skips prompt) |
| Clear-VpnS2SInterfaceStatistics | Resets counters, returns True |
| Add-VpnSstpProxyRule -Rule | Maps a tenant ID to a gateway IP (rules from New-VpnSstpProxyRule) |
| Disconnect-VpnUser | Ends one remote user's session by -HostIPAddress or -UserName |
| Clear-RemoteAccessInboxAccountingStore | Deletes accounting data between dates; no dates = whole store after confirm |
| Enable-/Disable-RemoteAccessRoutingDomain | Turn VPN/routing on/off per tenant: -Type Vpn|VpnS2S|RoutingOnly|All |
Disconnect-VpnUser -HostIPAddress 10.1.1.11Disconnect-VpnS2SInterface -Name 2-edge1 -PassThruConnect-VpnS2SInterface -Name 2-edge1 -PassThruClear-VpnS2SInterfaceStatistics -Name 2-edge1 -PassThru $Rule1 = New-VpnSstpProxyRule -TenantID "Contoso" -Gateway "100.10.10.10"Add-VpnSstpProxyRule -Rule $Rule1, $Rule2 Clear-RemoteAccessInboxAccountingStoreEnable-RemoteAccessRoutingDomain -Name Rd_01 -Type AllDisable-RemoteAccessRoutingDomain -RoutingDomain Rd_01 -Type VPNPS C:\> Connect-VpnS2SInterface -Name 2-edge1 -PassThruName Destination AdminStatus ConnectionState IPv4Subnet---- ----------- ----------- --------------- ----------2-edge1 {131.107.0.20} True Connected {10.2.0.0/24:1}PS C:\> Clear-VpnS2SInterfaceStatistics -Name 2-edge1 -PassThruTruePS C:\>Clear-RemoteAccessInboxAccountingStoreConfirmEmptying the store will delete the accounting data in accordance with the specified settings. Do you want to continue?InboxAccountingStatus : EnabledStoreLimit : 12mStoreFreeBytesInPercentage : 99.70551256.5 Flap dampening and Get-Bgp* cmdlets
- Enable-BgpRouteFlapDampening: asks to enable with the default config (-Force skips).
- Get-BgpRouteFlapDampening shows the engine config; Clear- resets flap info for given -Prefix; Disable- turns it off.
- Get-BgpRouter (BgpIdentifier, LocalASN), Get-BgpPeer (IP, ASN, ConnectivityStatus), Get-BgpStatistics (Open/Update/KeepAlive counters).
- Get-BgpRouteInformation -Type All|Best|Damped|Suppressed: learned routes; very useful with dampening.
- Get-BgpCustomRoute, Get-BgpRouteAggregate, Get-BgpRoutingPolicy (-Name / -PolicyType); -RoutingDomain / -AllRoutingDomains for multi-tenant.
Enable-BgpRouteFlapDampening -RoutingDomain "Contoso"Get-BgpRouteFlapDampening -RoutingDomain "Contoso"Clear-BgpRouteFlapDampening -Prefix 172.168.10.0/24, 10.10.1.128/25 -ForceDisable-BgpRouteFlapDampening -RoutingDomain "Contoso" -Force Get-BgpRouterGet-BgpPeer "TenantSite17" | Format-ListGet-BgpStatisticsGet-BgpRouteInformation -Type DampedGet-BgpRoutingPolicy -PolicyType ModifyAttributePS C:\> Enable-BgpRouteFlapDampening -RoutingDomain "Contoso"Route Flap Dampening engine is not configured. Do you want to enable dampening using the default configuration?(Y/N) YesPS C:\> Get-BgpStatisticsPeerName : Tenant-01OpenMessage: SentCount : 4KeepAliveMessage: SentCount : 1277 ReceivedCount : 1273PS C:\> Get-BgpRoutingPolicy -PolicyType ModifyAttributePolicyName : RTPolicy04PolicyType : ModifyAttributeMatchClauses : MatchPrefix : {10.1.4.0/24}SetClauses : NewLocalPref : 400256.6 DirectAccess and RemoteAccess Enable/Disable/Get
| Cmdlet | Shows / does |
|---|---|
| Enable-DAMultiSite / Disable-DAMultiSite | Multi-site deployment + first entry point (-GslbFqdn, -GslbIP, -EnterpriseName) |
| Enable-DAOtpAuthentication / Disable- | OTP login with RADIUS + CA; Disable keeps settings, status Disabled |
| Get-DAServer / Get-DAClient | Server properties / client groups + GPO |
| Get-DAClientDnsConfiguration | NRPT (Name Resolution Policy Table) entries |
| Get-DAAppServer / Get-DAEntryPoint / Get-DAEntryPointDC | App server groups / one entry point / entry point + its DC |
| Get-DAMgmtServer -Type Manual|Sccm|DC|All | Management servers |
| Get-DANetworkLocationServer -CheckReachability | Is the NLS reachable? |
| Get-RemoteAccess / -Accounting / -Configuration | DA + VPN + S2S status, accounting, config |
| Get-RemoteAccessConnectionStatistics (+Summary) | Live sessions, history to CSV with dates; totals |
Enable-DAMultiSite -EntryPointName "Entry Point 1" -PassThru -ForceDisable-DAOtpAuthentication -PassThru -ForceGet-DAEntrypoint -Name "Entry Point 2"Get-DAEntryPointDCGet-DAMgmtServer -Type DCGet-RemoteAccessConnectionStatistics -StartDateTime $startDate ` -EndDateTime $endDate | Export-Csv -Path "data.csv"Get-RemoteAccessConnectionStatisticsSummary -ComputerName edge1.corp.contoso.comPS C:\>Disable-DAOtpAuthentication -PassThru -ForceOtpStatus : DisabledCertificateTemplateName : DAOTPLogonPS C:\>Get-DAEntrypoint -Name "Entry Point 2"EntryPointName GslbIp Servers-------------- ------ -------Entry Point 2 0.0.0.0 {da2.domain1.corp.contoso.com}PS C:\>Get-DAEntryPointDCEntryPointName : Entry Point 1DomainControllerName : dc1.domain1.corp.contoso.comPS C:\> Get-DAMgmtServer -Type DCDC1.corp.contoso.comPS C:\>Get- RemoteAccessConnectionStatisticsSummary -ComputerName edge1.corp.contoso.comTotalConnections : 0MaxConcurrentConnections : 10TotalCumulativeConnections : 703TotalBytesInOut : 4518124768256.7 Lab: BGP Get-, dampening and shutdown with FRRouting
| FRR command | Windows idea |
|---|---|
| show bgp summary | Get-BgpPeer |
| show ip bgp | Get-BgpRouteInformation |
| show running-config (router bgp) | Get-BgpRouter |
| show bgp neighbors (Message statistics) | Get-BgpStatistics |
| bgp dampening / clear ip bgp dampening / no bgp dampening | Enable- / Clear- / Disable-BgpRouteFlapDampening |
| neighbor ... shutdown / no neighbor ... shutdown | Disconnect- / Connect-VpnS2SInterface (idea) |
# router1 AS 65001 (frr/router1.conf)ip route 10.255.1.0/24 blackholeip route 10.255.11.0/24 blackholerouter bgp 65001 bgp router-id 192.168.156.11 no bgp ebgp-requires-policy timers bgp 3 9 neighbor 192.168.156.12 remote-as 65002 address-family ipv4 unicast network 10.255.1.0/24 network 10.255.11.0/24# router2 AS 65002: network 10.255.2.0/24[router2]$ vtysh -c 'show bgp summary'BGP router identifier 192.168.156.12, local AS number 65002 VRF default vrf-id 0Neighbor V AS MsgRcvd MsgSent TblVer InQ OutQ Up/Down State/PfxRcd PfxSnt Desc192.168.156.11 4 65001 10 10 3 0 0 00:00:17 2 3 router1[router2]$ vtysh -c 'show ip bgp' Network Next Hop Metric LocPrf Weight Path *> 10.255.1.0/24 192.168.156.11 0 0 65001 i *> 10.255.2.0/24 0.0.0.0 0 32768 i *> 10.255.11.0/24 192.168.156.11 0 0 65001 i[router2]$ vtysh -c 'show bgp neighbors 192.168.156.11' | sed -n '/BGP state/p;/Message statistics/,/Total:/p' BGP state = Established, up for 00:00:24 Sent Rcvd Opens: 1 1 Notifications: 0 0 Updates: 3 3 Keepalives: 8 8 Total: 12 12- Defaults of bgp dampening: half-life 15 min, reuse 750, suppress 2000.
- 3 flaps of 10.255.11.0/24 on router1 -> status d (damped), reuse about 30 minutes.
# router2: Enable-BgpRouteFlapDampening ideavtysh -c 'configure terminal' -c 'router bgp 65002' \ -c 'address-family ipv4 unicast' -c 'bgp dampening'# router1: lab-only route flaps 3 timesfor i in 1 2 3; do vtysh ... -c 'no network 10.255.11.0/24'; sleep 3 vtysh ... -c 'network 10.255.11.0/24'; sleep 3donevtysh -c 'show ip bgp dampening flap-statistics'vtysh -c 'clear ip bgp dampening'# neighbor shutdown / no shutdownvtysh -c 'configure terminal' -c 'router bgp 65002' \ -c 'neighbor 192.168.156.11 shutdown'[router2]$ vtysh -c 'show ip bgp dampening flap-statistics' Network From Flaps Duration Reuse Path *d 10.255.11.0/24 192.168.156.11 3 00:00:33 00:29:39 65001 i[router2]$ vtysh -c 'show ip bgp dampening dampened-paths' Network From Reuse Path *d 10.255.11.0/24 192.168.156.11 00:29:39 65001 i[router2]$ vtysh -c 'clear ip bgp dampening'[router2]$ vtysh -c 'show ip bgp dampening dampened-paths'[router2]$ vtysh -c 'show bgp summary'Neighbor V AS MsgRcvd MsgSent TblVer InQ OutQ Up/Down State/PfxRcd PfxSnt Desc192.168.156.11 4 65001 48 48 11 0 0 00:00:13 2 3 router1 Last reset 00:00:27, Admin. shutdown (n/a)256.8 Common mistakes
- Thinking Disconnect-VpnS2SInterface deletes the tunnel: config stays and Connect brings it back; deleting is Remove-VpnS2SInterface.
- Running Clear-RemoteAccessInboxAccountingStore without dates: the whole store is emptied.
- Tuning dampening too aggressively: stable routes also get delayed.
- Setting a high metric in -IPv4Subnet and wondering why traffic uses another interface.
256.9 Interview tips
- Flap dampening: each flap adds a penalty; above the suppress limit the route is damped; it decays with the half-life and returns below the reuse limit.
- A route shows under Get-BgpRouteInformation -Type Damped: it flapped; wait for reuse or Clear-BgpRouteFlapDampening.
- S2S needs -Name, -Destination, protocol, auth and the remote subnets (-IPv4Subnet subnet:metric).
- Defaults worth quoting: SALifeTime 3600 s, MMSALifeTime 28800 s.