大网数据广告活动
服务器运维问答

Debian 9: Iptables for Samba and SMTP is nowt working

· 52CE 我爱测

I am currently trying to open the iptables firewall for Samba, but the configurations which I found on different portal are not working. Without firewall everything is working properly. With the firewall enabled I can not see any…

问题原文

原帖链接 · Kaffi · CC BY-SA 3.0

I am currently trying to open the iptables firewall for Samba, but the configurations which I found on different portal are not working. Without firewall everything is working properly. With the firewall enabled I can not see any errors in the logs except in the nmbd.log.

[2017/07/24 15:07:47.107717,  0] ../source3/libsmb/nmblib.c:873(send_udp)
  Packet send failed to 192.168.0.46(137) ERRNO=Operation not permitted
[2017/07/24 15:07:47.107808,  0] ../source3/nmbd/nmbd_packets.c:1026(reply_netbios_packet)
  reply_netbios_packet: send_packet to IP 192.168.0.46 port 137 failed
[2017/07/24 15:10:30.841301,  0] ../source3/libsmb/nmblib.c:873(send_udp)
  Packet send failed to 192.168.0.255(137) ERRNO=Operation not permitted
[2017/07/24 15:10:30.841395,  0] ../source3/nmbd/nmbd_packets.c:179(send_netbios_packet)
  send_netbios_packet: send_packet() to IP 192.168.0.255 port 137 failed
[2017/07/24 15:10:30.841421,  0] ../source3/nmbd/nmbd_namequery.c:245(query_name)
  query_name: Failed to send packet trying to query name WORKGROUP<1d>
[2017/07/24 15:12:34.203550,  0] ../source3/libsmb/nmblib.c:873(send_udp)
  Packet send failed to 192.168.0.255(138) ERRNO=Operation not permitted
[2017/07/24 15:12:34.203669,  0] ../source3/libsmb/nmblib.c:873(send_udp)
  Packet send failed to 192.168.0.255(138) ERRNO=Operation not permitted

All Ports which are needed for samba are listening.

xyz@nuc:~# netstat -tulpn | egrep "samba|smbd|nmbd|winbind"
tcp        0      0 0.0.0.0:139             0.0.0.0:*               LISTEN      517/smbd
tcp        0      0 0.0.0.0:445             0.0.0.0:*               LISTEN      517/smbd
tcp6       0      0 :::139                  :::*                    LISTEN      517/smbd
tcp6       0      0 :::445                  :::*                    LISTEN      517/smbd
udp        0      0 192.168.0.255:137       0.0.0.0:*                           576/nmbd
udp        0      0 192.168.0.2:137         0.0.0.0:*                           576/nmbd
udp        0      0 192.168.0.255:137       0.0.0.0:*                           576/nmbd
udp        0      0 192.168.0.249:137       0.0.0.0:*                           576/nmbd
udp        0      0 0.0.0.0:137             0.0.0.0:*                           576/nmbd
udp        0      0 192.168.0.255:138       0.0.0.0:*                           576/nmbd
udp        0      0 192.168.0.2:138         0.0.0.0:*                           576/nmbd
udp        0      0 192.168.0.255:138       0.0.0.0:*                           576/nmbd
udp        0      0 192.168.0.249:138       0.0.0.0:*                           576/nmbd
udp        0      0 0.0.0.0:138             0.0.0.0:*                           576/nmbd

And the iptables configuration by now:

iptables -F

iptables -P INPUT  DROP
iptables -P OUTPUT  DROP
iptables -P FORWARD  DROP

#Allow traffic on loopback
iptables -A INPUT -i lo -j ACCEPT
iptables -A OUTPUT -o lo -j ACCEPT


#dhcp
iptables -I INPUT -i enp0s25 -p udp --dport 67:68 --sport 67:68 -j ACCEPT

#Incoming ssh connection (server)
iptables -A INPUT -i enp0s25 -p tcp --dport 2222 -m state --state NEW,ESTABLISHED -j ACCEPT
iptables -A OUTPUT -o enp0s25 -p tcp --sport 2222 -m state --state ESTABLISHED -j ACCEPT

#Outgoing ssh connection (client)
iptables -A OUTPUT -o enp0s25 -p tcp --dport 2222 -m state --state NEW,ESTABLISHED -j ACCEPT
iptables -A INPUT -i enp0s25 -p tcp --sport 2222 -m state --state ESTABLISHED -j ACCEPT

##PING INCOMING ICMP
iptables -A INPUT -p icmp --icmp-type 8 -m state --state NEW,ESTABLISHED,RELATED -j ACCEPT
iptables -A OUTPUT -p icmp --icmp-type 0 -m state --state ESTABLISHED,RELATED -j ACCEPT

iptables -A OUTPUT -p icmp --icmp-type 8 -m state --state NEW,ESTABLISHED,RELATED -j ACCEPT
iptables -A INPUT -p icmp --icmp-type 0 -m state --state ESTABLISHED,RELATED -j ACCEPT


##SMTP##
#iptables -A OUTPUT -p tcp --sport 25 -m conntrack --ctstate ESTABLISHED -j ACCEPT
#iptables -A OUTPUT -p tcp --dport 25 -j ACCEPT
#iptables -A INPUT -p tcp --sport 25 -m state --state ESTABLISHED -j ACCEPT
iptables -A INPUT -p tcp --dport 25 -j ACCEPT
iptables -A INPUT -p tcp --dport 587 -j ACCEPT
iptables -A INPUT -p tcp --dport 465 -j ACCEPT



##SMB

iptables -A INPUT -i enp0s25  -p udp --dport 137:138 -m state --state NEW,ESTABLISHED -j ACCEPT
iptables -A OUTPUT -o enp0s25  -p udp --sport 137:138 -m state --state ESTABLISHED -j ACCEPT
iptables -A INPUT -i enp0s25  -p tcp --dport 139 -m state --state NEW,ESTABLISHED -j ACCEPT
iptables -A OUTPUT -o enp0s25  -p tcp --sport 139 -m state --state ESTABLISHED -j ACCEPT
iptables -A OUTPUT -o enp0s25  -p udp --sport 445 -m state --state ESTABLISHED -j ACCEPT




#iptables -A OUTPUT -m state --state NEW,ESTABLISHED -p udp --dport 137 -j ACCEPT
#iptables -A OUTPUT -m state --state NEW,ESTABLISHED -p udp --dport 138 -j ACCEPT
#iptables -A OUTPUT -m state --state NEW,ESTABLISHED -p tcp --dport 139 -j ACCEPT
#iptables -A OUTPUT -m state --state NEW,ESTABLISHED -p tcp --dport 445 -j ACCEPT

#iptables -A INPUT -p udp -m udp --dport 137 -j ACCEPT
#iptables -A INPUT -p udp -m udp --dport 138 -j ACCEPT
#iptables -A INPUT -m state --state NEW -m tcp -p tcp --dport 139 -j ACCEPT
#iptables -A INPUT -m state --state NEW -m tcp -p tcp --dport 445 -j ACCEPT


#iptables -A INPUT -p tcp -m multiport --dport 139,445 -j ACCEPT
#iptables -A INPUT -p udp -m multiport --dport 137,138 -j ACCEPT
#iptables -A OUTPUT -p tcp -m multiport --dport 139,445 -j ACCEPT
#iptables -A OUTPUT -p udp -m multiport --dport 137,138 -j ACCEPT

#iptables -A INPUT -p udp -m udp --dport 137 -j ACCEPT
#iptables -A INPUT -p udp -m udp --dport 138 -j ACCEPT
#iptables -A INPUT -m state --state NEW -m tcp -p tcp --dport 139 -j ACCEPT
#iptables -A INPUT -m state --state NEW -m tcp -p tcp --dport 445 -j ACCEPT



#Allow apt-get requests (HTTP)
iptables -A OUTPUT -p tcp --dport 80 --sport 32768:61000 -m state --state NEW,ESTABLISHED -j ACCEPT
iptables -A INPUT -p tcp --sport 80 --dport 32768:61000 -m state --state ESTABLISHED -j ACCEPT
iptables -A OUTPUT -p udp --dport 53 --sport 32768:61000 -m state --state NEW,ESTABLISHED -j ACCEPT
iptables -A INPUT -p udp --sport 53 --dport 32768:61000 -m state --state ESTABLISHED -j ACCEPT


iptables -A INPUT -m limit --limit 5/min -j LOG --log-prefix "iptables denied: " --log-level 7

Can somebody give me a hint, how I can set up it the iptables for SMTP and samba correctly?

Best regards

Kaffi

已采纳解答

原帖链接 · Khaled · CC BY-SA 3.0

The following line shown in the error log means the machine could NOT send UDP packet destined to port 137 (dropped by firewall). So, you need to add an ACCEPT rule for UDP to allow this port.

[2017/07/24 15:07:47.107717,  0] ../source3/libsmb/nmblib.c:873(send_udp)
  Packet send failed to 192.168.0.46(137) ERRNO=Operation not permitted

Similarly, you have an error for UDP port 138. These are NetBios ports. Add rules like these:

iptables -A OUTPUT -p udp --dport 137 -j ACCEPT
iptables -A OUTPUT -p udp --dport 138 -j ACCEPT

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2017-07-24)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。