Песочница WSL2 — попытка настроить сценарий для создания правил брандмауэра в Windows 10Linux

Ответить Пред. темаСлед. тема
Anonymous
 Песочница WSL2 — попытка настроить сценарий для создания правил брандмауэра в Windows 10

Сообщение Anonymous »

Я пытаюсь заблокировать WSL2 в своей среде. Я не могу использовать инструменты Intune для управления WSL2, поскольку у меня нет Windows 11. Итак, я создал сценарий для получения IP-адреса интерфейса WSL2, а затем запускаю отдельный сценарий, который создает правила брандмауэра для блокировки всех входящих сообщений. и исходящий трафик.
Я знаю, что Ubuntu использует

Код: Выделить всё

$allowedSites = @(
"archive.ubuntu.com",
"security.ubuntu.com",
"ppa.launchpadcontent.net"
)
Но даже несмотря на то, что эти сайты занесены в белый список, мой экземпляр WSL2 не может получать обновления из этих служб.
Вот полный сценарий правил брандмауэра. .

Код: Выделить всё

# Define the path to the persistent log file
$FilePath = "$env:USERPROFILE\wsl_ip.log"
$logFilePath = $FilePath -replace "\.ad", ""
Write-Host "Modified path: $logFilePath"

# Define the allowed sites for Ubuntu updates
$allowedSites = @(
"archive.ubuntu.com",
"security.ubuntu.com",
"ppa.launchpadcontent.net"
)

# Function to create firewall rule
function Create-FirewallRule {
param(
[string]$ipAddress,
[string[]]$allowedSites
)

# Create a rule to block all inbound traffic for the IP address
New-NetFirewallRule -DisplayName "Block all inbound traffic for WSL IP" `
-Direction Inbound `
-RemoteAddress $ipAddress `
-Action Block `
-Profile Any `
-Description "Blocks all inbound traffic for WSL IP except for allowed sites"

# Create a rule to block all outbound traffic for the IP address
New-NetFirewallRule -DisplayName "Block all outbound traffic for WSL IP" `
-Direction Outbound `
-RemoteAddress $ipAddress `
-Action Block `
-Profile Any `
-Description "Blocks all outbound traffic for WSL IP except for allowed sites"

# Allow outbound traffic to specific sites for Ubuntu updates
foreach ($site in $allowedSites) {
New-NetFirewallRule -DisplayName "Allow outbound traffic to $site" `
-Direction Outbound `
-RemoteAddress $ipAddress `
-RemotePort 80, 443, 21, 53 `
-Protocol TCP `
-Action Allow `
-Profile Any `
-Description "Allows outbound traffic to $site"
}

# Allow inbound traffic from specific sites for Ubuntu updates
foreach ($site in $allowedSites) {
New-NetFirewallRule -DisplayName "Allow inbound traffic from $site" `
-Direction Inbound `
-RemoteAddress $ipAddress `
-RemotePort 80, 443, 21, 53 `
-Protocol TCP `
-Action Allow `
-Profile Any `
-Description "Allows inbound traffic from $site"
}
}

# Read the log file and search for the line containing the IP address
$searchPattern = "ip addr:"
$ipLine = Select-String -Path $logFilePath -Pattern $searchPattern | Select-Object -First 1

# Check if a line was found
if ($ipLine) {
# Extract the IP address from the line
$ipLineText = $ipLine.Line
# Adjust the extraction based on the actual format of the line
$ipAddress = $ipLineText -replace ".*ip addr:\s*", ""

Write-Host "Found IP address: $ipAddress"

# Create the firewall rule using the extracted IP address
Create-FirewallRule -ipAddress $ipAddress -allowedSites $allowedSites
} else {
Write-Host "No line containing IP address found in the log file."

# Print all .log files in the log file path
Write-Host "Listing all .log files in the log file path:"
Get-ChildItem -Path $logFilePath | Where-Object { $_.Extension -eq ".log"  } | ForEach-Object {
Write-Host "File: $_.Name"
# Print the contents of the .log file
Write-Host "Contents of $_.Name:"
Get-Content $_.FullName | ForEach-Object { Write-Host $_ }
Write-Host "End of contents of $_.Name"
}
}
Я пытаюсь обновить эти правила брандмауэра и получаю ошибку имени

Код: Выделить всё

Ign:1 https://ppa.launchpadcontent.net/deadsnakes/ppa/ubuntu jammy InRelease
Ign:2 http://archive.ubuntu.com/ubuntu jammy InRelease
Ign:3 http://security.ubuntu.com/ubuntu jammy-security InRelease
Ign:4 http://archive.ubuntu.com/ubuntu jammy-updates InRelease
Ign:3 http://security.ubuntu.com/ubuntu jammy-security InRelease
Ign:1 https://ppa.launchpadcontent.net/deadsnakes/ppa/ubuntu jammy InRelease
Ign:5 http://archive.ubuntu.com/ubuntu jammy-backports InRelease
Ign:3 http://security.ubuntu.com/ubuntu jammy-security InRelease
Ign:1 https://ppa.launchpadcontent.net/deadsnakes/ppa/ubuntu jammy InRelease
Ign:2 http://archive.ubuntu.com/ubuntu jammy InRelease
Err:3 http://security.ubuntu.com/ubuntu jammy-security InRelease
Temporary failure resolving 'security.ubuntu.com'
Err:1 https://ppa.launchpadcontent.net/deadsnakes/ppa/ubuntu jammy InRelease
Temporary failure resolving 'ppa.launchpadcontent.net'
Ign:4 http://archive.ubuntu.com/ubuntu jammy-updates InRelease
Ign:5 http://archive.ubuntu.com/ubuntu jammy-backports InRelease
Ign:2 http://archive.ubuntu.com/ubuntu jammy InRelease
Ign:4 http://archive.ubuntu.com/ubuntu jammy-updates InRelease
Ign:5 http://archive.ubuntu.com/ubuntu jammy-backports InRelease
Err:2 http://archive.ubuntu.com/ubuntu jammy InRelease
Temporary failure resolving 'archive.ubuntu.com'
Err:4 http://archive.ubuntu.com/ubuntu jammy-updates InRelease
Temporary failure resolving 'archive.ubuntu.com'
Err:5 http://archive.ubuntu.com/ubuntu jammy-backports InRelease
Temporary failure resolving 'archive.ubuntu.com'
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
3 packages can be upgraded. Run 'apt list --upgradable' to see them.
W: Failed to fetch http://archive.ubuntu.com/ubuntu/dists/jammy/InRelease  Temporary failure resolving 'archive.ubuntu.com'
W: Failed to fetch http://archive.ubuntu.com/ubuntu/dists/jammy-updates/InRelease  Temporary failure resolving 'archive.ubuntu.com'
W: Failed to fetch http://archive.ubuntu.com/ubuntu/dists/jammy-backports/InRelease  Temporary failure resolving 'archive.ubuntu.com'
W: Failed to fetch http://security.ubuntu.com/ubuntu/dists/jammy-security/InRelease  Temporary failure resolving 'security.ubuntu.com'
W: Failed to fetch https://ppa.launchpadcontent.net/deadsnakes/ppa/ubuntu/dists/jammy/InRelease  Temporary failure resolving 'ppa.launchpadcontent.net'
W: Some index files failed to download. They have been ignored, or old ones used instead.
Но как только я удаляю правила, все работает нормально, поэтому я думаю, что просто неправильно настраиваю правила. Я думаю, что настраиваю правила, чтобы просто блокировать трафик к wsl2, но это не входит в мои намерения.
Я хочу настроить эти правила для конкретного интерфейса, который использует wsl2.

Подробнее здесь: https://stackoverflow.com/questions/783 ... windows-10
Реклама
Ответить Пред. темаСлед. тема

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

  • Похожие темы
    Ответы
    Просмотры
    Последнее сообщение

Вернуться в «Linux»