PowerShell/docs/install-unbound-server.md

103 lines
3.0 KiB
Markdown
Raw Normal View History

2024-01-25 13:37:12 +01:00
Script: *install-unbound-server.ps1*
========================
2023-05-26 12:20:18 +02:00
This PowerShell script installs Unbound, a validating, recursive, caching DNS resolver. It needs admin rights.
2023-07-29 10:04:38 +02:00
Parameters
----------
2023-05-26 12:20:18 +02:00
```powershell
2023-07-29 10:15:44 +02:00
PS> ./install-unbound-server.ps1 [<CommonParameters>]
2023-05-26 12:20:18 +02:00
[<CommonParameters>]
This script supports the common parameters: Verbose, Debug, ErrorAction, ErrorVariable, WarningAction,
WarningVariable, OutBuffer, PipelineVariable, and OutVariable.
```
2023-07-29 10:04:38 +02:00
Example
-------
2023-05-26 12:20:18 +02:00
```powershell
2023-08-06 21:36:33 +02:00
PS> ./install-unbound-server.ps1
2023-05-26 12:20:18 +02:00
```
2023-07-29 10:04:38 +02:00
Notes
-----
2023-05-26 12:20:18 +02:00
Author: Markus Fleschutz | License: CC0
2023-07-29 10:04:38 +02:00
Related Links
-------------
2023-05-26 12:20:18 +02:00
https://github.com/fleschutz/PowerShell
2023-07-29 10:04:38 +02:00
Script Content
--------------
2023-05-26 12:20:18 +02:00
```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
2023-08-06 21:36:33 +02:00
PS> ./install-unbound-server.ps1
2023-05-26 12:20:18 +02:00
.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..."
2023-12-07 20:24:45 +01:00
& unbound-checkconf "$PSScriptRoot/../data/unbound.conf"
2023-05-26 12:20:18 +02:00
if ($lastExitCode -ne "0") { throw "'unbound-checkconf' failed - check the syntax" }
"⏳ (6/10) Copying config file to /etc/unbound/unbound.conf ..."
2023-12-07 20:24:45 +01:00
& sudo cp "$PSScriptRoot/../data/unbound.conf" /etc/unbound/unbound.conf
2023-05-26 12:20:18 +02:00
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" }
2023-09-20 17:05:11 +02:00
"⏳ (10/10) Training Unbound with 100 popular domain names..."
2023-05-26 12:20:18 +02:00
& "$PSScriptRoot/check-dns.ps1"
if ($lastExitCode -ne "0") { throw "'unbound-control status' failed" }
[int]$Elapsed = $StopWatch.Elapsed.TotalSeconds
2023-09-20 17:05:11 +02:00
"✔️ Installed Unbound in $Elapsed sec"
2023-05-26 12:20:18 +02:00
exit 0 # success
} catch {
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
exit 1
}
```
2024-01-25 13:37:12 +01:00
*(generated by convert-ps2md.ps1 using the comment-based help of install-unbound-server.ps1 as of 01/25/2024 13:36:51)*