秩序很重要。

秩序很重要。

我正在尝试在运行 dd-wrt ​​v24 的教堂 WRT54GL 上设置防火墙。我找不到很多关于设置防火墙的优秀指南,而且似乎没有关于这些路由器的最新指南。

基本上,我想设置防火墙来阻止非必要端口上的所有传入流量,限制某些本地计算机访问文件服务器,并阻止一些传出端口。

我尝试过使用 fwbuilder(防火墙生成器),但没成功。我可以将更改提交到防火墙,但似乎无法让它们真正发挥作用。

有谁可以帮忙吗?

答案1

我无法给你一个确切的答案,但以下内容应该有所帮助并给你一个大致的想法。

如果本地客户端位于同一网络(即位于同一 IP 网络和同一物理段中),则可能无法阻止它们访问文件服务器,因为数据包不需要通过路由器在它们之间传输。如果它们确实需要通过路由器,那么我已包含一条我认为会有所帮助的规则。

我不熟悉 wrt 发行版,所以我不确定应该把这些规则放在哪里。

秩序很重要。

#Add these rules once
iptables -A FORWARD -j INPUT
iptables -A INPUT -i lo -j ACCEPT
iptables -A INPUT -p icmp --icmp-type any -j ACCEPT
iptables -A INPUT -p 50 -j ACCEPT
iptables -A INPUT -p 51 -j ACCEPT
iptables -A INPUT -p udp --dport 5353 -d 224.0.0.251 -j ACCEPT
iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT

#for each incoming tcp service you want to allow add one of these:
iptables -A INPUT -m state --state NEW -m tcp -p tcp --dport <allowed_port> -j ACCEPT

#for each incoming udp service you want to allow add one of these:
iptables -A INPUT -m state --state NEW -m udp -p udp --dport <allowed_port> -j ACCEPT

#for each local client that should not have fileserver access add one of these:
iptables -A INPUT -s <banned_local_ip> -d <filesrever> -j REJECT

#add these once
iptables -A INPUT -j REJECT --reject-with icmp-host-prohibited

# if you only wanted to block the outgoing access for a given local IP to an 
# external service then you add one of these for each local client and external
# service combination
iptables -A OUTPUT -s <local_banned_IP> --dport <disallowed_port> -j REJECT
    
#for each outgoing service you want to block to all local host add one of these:
# this will block the service for every host on the network 
iptables -A OUTPUT --dport <disallowed_port> -j REJECT


#add this once to allow all other outgoing    
iptables -A OUTPUT -j ALLOW

如果文件服务器是 Linux 主机,则只需在文件服务器上放置 iptables 规则即可拒绝您不想访问的本地主机。

答案2

这个被认为是“iptables圣经”,它将满足您的所有需求。

正如它所说,如果你无法理解其中的任何内容,这可能是由于缺乏一般的网络知识,你可以使用这本书,被认为是改进的“网络圣经”。

答案3

这个问题和答案需要对 iptables 有中/高级的理解。我无法给出“开箱即用”的解决方案,但我可以给出几行来自防火墙的示例,用于在 wrt54gl 上使用 openwrt 的几乎开放的 wifi。

在此示例中,列出的端口被允许,其他端口被阻止:

不要盲目粘贴!否则你可能会被锁定:

#iptables -A forwarding_rule -i br-lan -p tcp -m multiport --dports port,port,port -j ACCEPT
#iptables -A forwarding_rule -i br-lan -j DROP

这些行来自/etc/firewall.userwifi 路由器上的文件。

请在更改内容前进行备份!
请做好重写固件的准备!
请在 ssh 或 http 上留一个后门,以防这些不起作用。

相关内容