如何在Windows上与其他端口共享一个SMB网络共享 我试图通过Internet上的Windows上安装一个SMB网络共享,但是我遇到了几个问题。 首先,我的设置是在我本地网络中运行桑巴的Raspberry Pi和所有内容...

问题描述 投票:0回答:2
Windows无法连接到使用其他端口的共享445。

那么,如何使用或多或少的本机Windows工具和脚本来解决此问题?

我找到了一个解决方法,可以将SMB分享在Windows上,而不是默认端口1045。 首先,我在Windows上设置了WSL Ubuntu,并安装了CIFS-UTIL:

sudo apt install cifs-utils 

然后我编写了以下脚本,该脚本在安装网络通过WSL上共享之后创建了一个快捷方式:

# PowerShell script to mount SMB share to WSL, then mount local SMB share to WSL using net use # Variables $wslDistro = "Ubuntu" # Change this to your WSL distro (e.g., Ubuntu, Debian) $wslMountPoint = "/mnt/smb_share" # WSL mount point $smbServerIP = "somedynamic.dns.army" # SMB server IP address (can be local or remote) $smbShare = "NAS" # SMB share name $wslUsername = "NAS" # WSL SMB username $wslPassword = "strongpassword" # WSL SMB password # Mount the SMB share inside WSL with the specified file and directory modes Write-Host "Starting WSL session and mounting SMB share..." Start-Job -ScriptBlock { param( $wslDistro, $wslMountPoint, $smbServerIP, $smbShare, $wslUsername, $wslPassword ) wsl.exe --user root -d $wslDistro -e bash -c "sudo mkdir -p $wslMountPoint; sudo ls -al $wslMountPoint; sudo umount $wslMountPoint; sudo mount -t cifs //$smbServerIP/$smbShare $wslMountPoint -o username='$wslUsername',password='$wslPassword',port=1045,file_mode=0777,dir_mode=0777; chmod 777 $wslMountPoint; while true; do sleep 3600; done" } -ArgumentList $wslDistro, $wslMountPoint, $smbServerIP, $smbShare, $wslUsername, $wslPassword sleep 4 # Mount the local SMB share in Windows using net use Write-Host "Mapping local SMB share to Windows Shortcut..." $shortcutPath = "$env:USERPROFILE\Desktop\NAS-Drive" if (!(Test-Path $shortcutPath)) { New-Item -ItemType SymbolicLink -Path "$shortcutPath" -Target "\\wsl$\Ubuntu$wslMountPoint" } Write-Host "SMB share mounted in WSL, and local SMB share linked to Windows at $shortcutPath"

windows powershell windows-subsystem-for-linux portforwarding smb
2个回答
0
投票

我发现我的解决方案具有非常不稳定的连接,我写了一个小应用程序,可以解决这个问题:

Smbrowser1.0.zip


0
投票
最新问题
© www.soinside.com 2019 - 2025. All rights reserved.