mirror of
https://github.com/fleschutz/PowerShell.git
synced 2024-11-30 11:54:32 +01:00
97 lines
2.9 KiB
Markdown
97 lines
2.9 KiB
Markdown
|
## The *install-unbound-server.ps1* Script
|
||
|
|
||
|
This PowerShell script installs Unbound, a validating, recursive, caching DNS resolver. It needs admin rights.
|
||
|
|
||
|
## Parameters
|
||
|
```powershell
|
||
|
/home/mf/Repos/PowerShell/Scripts/install-unbound-server.ps1 [<CommonParameters>]
|
||
|
|
||
|
[<CommonParameters>]
|
||
|
This script supports the common parameters: Verbose, Debug, ErrorAction, ErrorVariable, WarningAction,
|
||
|
WarningVariable, OutBuffer, PipelineVariable, and OutVariable.
|
||
|
```
|
||
|
|
||
|
## Example
|
||
|
```powershell
|
||
|
PS> ./install-unbound-server
|
||
|
|
||
|
```
|
||
|
|
||
|
## Notes
|
||
|
Author: Markus Fleschutz | License: CC0
|
||
|
|
||
|
## Related Links
|
||
|
https://github.com/fleschutz/PowerShell
|
||
|
|
||
|
## Source Code
|
||
|
```powershell
|
||
|
<#
|
||
|
.SYNOPSIS
|
||
|
Installs Unbound server (needs admin rights)
|
||
|
.DESCRIPTION
|
||
|
This PowerShell script installs Unbound, a validating, recursive, caching DNS resolver. It needs admin rights.
|
||
|
.EXAMPLE
|
||
|
PS> ./install-unbound-server
|
||
|
.LINK
|
||
|
https://github.com/fleschutz/PowerShell
|
||
|
.NOTES
|
||
|
Author: Markus Fleschutz | License: CC0
|
||
|
#>
|
||
|
|
||
|
#Requires -RunAsAdministrator
|
||
|
|
||
|
try {
|
||
|
$StopWatch = [system.diagnostics.stopwatch]::startNew()
|
||
|
|
||
|
"⏳ (1/10) Updating package infos..."
|
||
|
& sudo apt update -y
|
||
|
if ($lastExitCode -ne "0") { throw "'apt update' failed" }
|
||
|
|
||
|
"⏳ (2/10) Installing the Unbound packages..."
|
||
|
& sudo apt install unbound unbound-anchor -y
|
||
|
if ($lastExitCode -ne "0") { throw "'apt install unbound' failed" }
|
||
|
|
||
|
"⏳ (3/10) Setting up Unbound..."
|
||
|
& sudo unbound-control-setup
|
||
|
if ($lastExitCode -ne "0") { throw "'unbound-control-setup' failed" }
|
||
|
|
||
|
"⏳ (4/10) Updating DNSSEC Root Trust Anchors..."
|
||
|
& sudo unbound-anchor
|
||
|
if ($lastExitCode -ne "0") { throw "'unbound-anchor' failed" }
|
||
|
|
||
|
"⏳ (5/10) Checking config file..."
|
||
|
& unbound-checkconf "$PSScriptRoot/../Data/unbound.conf"
|
||
|
if ($lastExitCode -ne "0") { throw "'unbound-checkconf' failed - check the syntax" }
|
||
|
|
||
|
"⏳ (6/10) Copying config file to /etc/unbound/unbound.conf ..."
|
||
|
& sudo cp "$PSScriptRoot/../Data/unbound.conf" /etc/unbound/unbound.conf
|
||
|
if ($lastExitCode -ne "0") { throw "'cp' failed" }
|
||
|
|
||
|
"⏳ (7/10) Stopping default DNS cache daemon systemd-resolved..."
|
||
|
& sudo systemctl stop systemd-resolved
|
||
|
& sudo systemctl disable systemd-resolved
|
||
|
|
||
|
"⏳ (8/10) (Re-)starting Unbound..."
|
||
|
& sudo unbound-control stop
|
||
|
& sudo unbound-control start
|
||
|
if ($lastExitCode -ne "0") { throw "'unbound-control start' failed" }
|
||
|
|
||
|
"⏳ (9/10) Checking status of Unbound..."
|
||
|
& sudo unbound-control status
|
||
|
if ($lastExitCode -ne "0") { throw "'unbound-control status' failed" }
|
||
|
|
||
|
"⏳ (10/10) Training Unbound with 200 popular domain names..."
|
||
|
& "$PSScriptRoot/check-dns.ps1"
|
||
|
if ($lastExitCode -ne "0") { throw "'unbound-control status' failed" }
|
||
|
|
||
|
[int]$Elapsed = $StopWatch.Elapsed.TotalSeconds
|
||
|
"✔️ installed Unbound in $Elapsed sec"
|
||
|
exit 0 # success
|
||
|
} catch {
|
||
|
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
||
|
exit 1
|
||
|
}
|
||
|
```
|
||
|
|
||
|
*Generated by convert-ps2md.ps1 using the comment-based help of install-unbound-server.ps1*
|