您当前的位置: 首页 > 慢生活 > 程序人生 网站首页程序人生
windows通过端口转发实现连接阿里云、腾讯云等远端服务器smb文件共享服务
发布时间:2021-12-05 21:21:11编辑:雪饮阅读()
前几天老大问了我一个问题,为什么他在服务器里面配置了smb文件共享服务,windows远程连接不了。当时我没有帮他排查到,事后我想想是不是安全组之类的,他服务器可能是阿里云或腾讯云之类的,可能就是安全组影响了。
后来有空了我用我阿里云服务器放行了对应端口,smb服务默认端口有139和445两个。
那么我将这两个端口都放行了,可是还是不行,后来查资料说是服务器提供商那边貌似把这两个端口屏蔽了,毕竟这东西不是特别安全的。
那么我接下来就是自定义smb对外端口了。
服务端配置
那我将对外服务端口只配置一个,且这个端口为8484:
[root@izj6c2jeancylo0ppo4vz5z ~]# cat /etc/samba/smb.conf
# See smb.conf.example for a more detailed config file or
# read the smb.conf manpage.
# Run 'testparm' to verify the config is correct after
# you modified it.
[global]
# workgroup = SAMBA
workgroup = WORKGROUP
security = user
map to guest = Bad User
# passdb backend = tdbsam
# printing = cups
# printcap name = cups
# load printers = yes
# cups options = raw
smb ports=8484
[homes]
comment = Home Directories
valid users = %S, %D%w%S
browseable = No
read only = No
inherit acls = Yes
[printers]
comment = All Printers
path = /var/tmp
printable = Yes
create mask = 0600
browseable = No
[print$]
comment = Printer Drivers
path = /var/lib/samba/drivers
write list = @printadmin root
force group = @printadmin
create mask = 0664
directory mask = 0775
[disk]
comment = this is the info
path= /
writable = yes
public = yes
guest ok = yes
browseable = yes
配置好后记得将该自定义端口8484端口放行。
并重启smb服务。
windows通过端口转发实现连接非局域网的文件共享
然后接下来就是windows这边也要配置的,因为windows默认只运行局域网内文件共享访问,且访问端口不支持自定义,固定是445和139好像。
那么这里查了资料是需要走端口转发的。
在cmd(管理员权限执行)中运行如下命令:
netsh interface portproxy add v4tov4 listenaddress=127.0.0.1 listenport=445 connectaddress=112.96.239.41 connectport=8484
然后需要重启windows才能生效。
这里的意思是访问127.0.0.1并以445端口向外访问时候,则转发到112.96.239.41的8484端口。
而后者ip就是我服务器公网ip,后者端口就是我服务器上面开启的文件共享服务对外访问的端口。
那么接下来可以直接访问127.0.0.1就能看到我们的远端smb的8484端口的文件共享了。
关键字词:windows,端口转发,端口,转发,smb,文件共享
上一篇:workerman的http服务-请求-获取请求queryString
下一篇:windos通过端口转发实现自定义smb(cifs)连接端口连接远端服务器smb文件共享服务(多个服务器连接地址的配置)