通过 Openvpn 访问 Samba 共享时出现问题

通过 Openvpn 访问 Samba 共享时出现问题

互联网上有很多帖子涉及此主题,但我仍然无法使其工作。我有以下设置:

  • Samba 客户端:Windows 10 上的笔记本电脑“Quincy”,本地 LAN 192.168.178.100,VPN 10.8.0.50
  • OpenVPN 服务器:Ubuntu 16.04 上的“Coleman”,eth0 192.168.178.2,tun0 10.8.0.1
  • Samba 服务器:Ubuntu 16.04 上的“Cannonball”,eth0 192.168.1768.3

当我在 LAN 内部时,一切正常,但当我在 LAN 外部时,我想通过 VPN 访问我的 Samba 共享,但我无法这样做。Windows 报告无法访问\\\192.168.178.3\user。奇怪的是,当我尝试从笔记本电脑连接时,登录了以下内容/var/log/samba/smbd.samba.log

[2016/10/19 20:37:29.135523,  3] ../source3/lib/access.c:338(allow_access)
Allowed connection from 192.168.178.2 (192.168.178.2)

/var/log/samba/quincy.samba.log 报告称:

[2016/10/19 20:37:46.116302,  3] ../source3/smbd/server_exit.c:252(exit_server_common)
Server exit (failed to receive smb request)

所以我的解释是,Samba 服务器收到了来自 Windows 客户端的访问请求,但没有收到实际的 Samba 请求(例如浏览或访问文件)。更可能的是,Samba 客户端没有收到来自服务器的信息,因此返回了访问错误。

因此,我尝试了论坛和常见问题解答中关于 IP 转发、防火墙设置等几乎所有我能找到的方法,但仍然没有找到解决方案。下面您可以找到配置文件和可以提供更多信息的内容。

我希望有人能帮助我。我对此真的很困惑。

/etc/openvpn/server.conf在192.168.178.2上:

;local a.b.c.d  
port 1194  
;proto tcp  
proto udp  
;dev tap  
dev tun  
;dev-node MyTap  
ca ca.crt  
cert Coleman.crt  
key Coleman.key  # This file should be kept secret  
dh dh2048.pem  
;topology subnet  
server 10.8.0.0 255.255.255.0  
ifconfig-pool-persist ipp.txt  
;server-bridge 10.8.0.4 255.255.255.0 10.8.0.50 10.8.0.100  
;server-bridge  
push "route 192.168.178.0 255.255.255.0"  
;push "route 192.168.20.0 255.255.255.0"  
push "dhcp-options DNS 10.8.0.1"  
;client-config-dir ccd  
;route 192.168.40.128 255.255.255.248  
;client-config-dir ccd  
;route 10.9.0.0 255.255.255.252  
;learn-address ./script  
push "redirect-gateway def1 bypass-dhcp"  
push "dhcp-option DNS 8.8.8.8"      ## Google DNS servers  
push "dhcp-option DNS 8.8.8.4"  
;client-to-client  
;duplicate-cn  
keepalive 10 120  
tls-auth ta.key 0 # This file is secret  
key-direction 0  
;cipher BF-CBC        # Blowfish (default)  
cipher AES-128-CBC   # AES  
auth SHA256  
;cipher DES-EDE3-CBC  # Triple-DES  
comp-lzo  
;max-clients 100  
user nobody  
group nogroup  
persist-key  
persist-tun  
status openvpn-status.log  
;log         openvpn.log  
;log-append  openvpn.log  
verb 3  
;mute 20  

192.168.178.2 上的 UFW 规则:

Naar                       Actie       Van  
----                       -----       ---  
OpenSSH                    ALLOW       Anywhere                  
Postfix                    ALLOW       Anywhere                  
Dovecot IMAP               ALLOW       Anywhere                  
Dovecot Secure IMAP        ALLOW       Anywhere                  
1194/udp                   ALLOW       Anywhere                  
Apache                     ALLOW       Anywhere                  
Apache Full                ALLOW       Anywhere                  
Apache Secure              ALLOW       Anywhere                  
8080                       ALLOW       Anywhere                  
1194                       ALLOW       Anywhere                  
445/tcp                    ALLOW       Anywhere                  
137/udp                    ALLOW       Anywhere                  
138/udp                    ALLOW       Anywhere                  
139/tcp                    ALLOW       Anywhere                  
OpenSSH (v6)               ALLOW       Anywhere (v6)             
Postfix (v6)               ALLOW       Anywhere (v6)             
Dovecot IMAP (v6)          ALLOW       Anywhere (v6)             
Dovecot Secure IMAP (v6)   ALLOW       Anywhere (v6)             
1194/udp (v6)              ALLOW       Anywhere (v6)             
Apache (v6)                ALLOW       Anywhere (v6)             
Apache Full (v6)           ALLOW       Anywhere (v6)             
Apache Secure (v6)         ALLOW       Anywhere (v6)             
8080 (v6)                  ALLOW       Anywhere (v6)             
445/tcp (v6)               ALLOW       Anywhere (v6)             
137/udp (v6)               ALLOW       Anywhere (v6)             
138/udp (v6)               ALLOW       Anywhere (v6)             
139/tcp (v6)               ALLOW       Anywhere (v6)             

/etc/samba/smb.conf在192.168.178.3上:

[global]  
netbios name = Cannonball  
server string = Samba file server  
domain master = yes  
workgroup = BEGONET  
security = user  
hosts allow = 127. 192.168.178.  
hosts deny = 192.168.178.20 
interfaces = 127.0.0.1/8 192.168.178.0/24  
remote announce = 192.168.178.255  
remote browse sync = 192.168.178.255  
log file = /var/log/samba/samba.log  
max log size = 1000  
encrypt passwords = true  
unix password sync = yes  
socket options = TCP_NODELAY SO_RCVBUF=8192 SO_SNDBUF=8192  
name resolve order = wins lmhosts bcast  
wins support = yes  
wins proxy = no  
dns proxy = no  
passdb backend = tdbsam  
passwd program = /usr/bin/passwd '%u'  
passwd chat = *New*password* %n\n *ReType*new*password* %n\n   *passwd*changed*\n  
add user script = /usr/sbin/useradd -d /dev/null -c 'Samba User Account' -s   /dev/null '%u'  
add user to group script = /usr/sbin/useradd -d /dev/null -c 'Samba User   Account' -s /dev/null -g '%g' '%u'  
add group script = /usr/sbin/groupadd '%g'  
delete user script = /usr/sbin/userdel '%u'  
delete user from group script = /usr/sbin/userdel '%u' '%g'  
delete group script = /usr/sbin/groupdel '%g'  
add machine script = /usr/sbin/useradd -d /dev/null -g sambamachines -c   'Samba Machine Account' -s /dev/null -M '%u'  
machine password timeout = 120  
template shell = /dev/null   
smb ports = 139  

[tmp]   
comment = temporary files  
path = /tmp  
read only = yes  

[printers]  
    comment = All Printers    
    browsable = yes  
    path = /var/spool/samba  
    printable = yes  
    guest ok = no  
    read only = yes  
    create mask = 0700 

[print$]  
    comment = Printer Drivers  
    path = /var/lib/samba/printers  
    browsable = yes  
    read only = yes  
    guest ok = no  

[Backups]  
    path = /home/Backups  
    writeable = yes  
    browseable = yes  
    valid users = berry  
    guest ok = no

192.168.178.3 上没有启用防火墙

答案1

在你的 smb.conf 中你应该有接口主持人允许定义如下:

   interfaces = 127.0.0.0/8 192.168.178.0/24 10.8.0.0/24
   hosts allow = 127.0.0.1 192.168.178.1/24 10.8.0.1/24

另外我想补充hosts deny = ALL一下,您不需要从任何其他界面进行访问。

更改后不要忘记重启 Samba 服务service smbd restart

相关内容