|
发表于 2024-11-16 15:52:54
|
显示全部楼层
本帖最后由 岱岳之上的天 于 2024-11-16 16:31 编辑
服务器使用iptables操作达到端口白名单的目的,以及不要使用过时的协议就可以了。
端口白名单可以靠修改iptables规则来实现,我帮你修改了一份,你看着改:
dport 22 表示已经开放了ssh端口,如果有其他需要开放的端口直接复制规则修改就行,不懂的可以首先上网查,很简单的。
v4
- *filter
- :INPUT ACCEPT [0:0]
- :FORWARD ACCEPT [0:0]
- :OUTPUT ACCEPT [0:0]
- -A INPUT -i lo -j ACCEPT
- -A INPUT -i tailscale0 -j ACCEPT
- -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
- -A INPUT -p tcp --dport 22 -j ACCEPT
- -A INPUT -m state --state INVALID -j DROP
- -A INPUT -p tcp -j DROP
- -A INPUT -p udp -j DROP
- -A INPUT -p icmp --icmp-type 8 -j DROP
- -A INPUT -p icmp --icmp-type 11 -j DROP
- -A INPUT -p icmp --icmp-type 13 -j DROP
- -A INPUT -p icmp --icmp-type 30 -j DROP
- -A INPUT -p icmp --icmp-type 42 -j DROP
- -A INPUT -p icmp -j ACCEPT
- -A OUTPUT -p tcp --tcp-flags ALL RST,ACK -j DROP
- -A OUTPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
- -A OUTPUT -m state --state INVALID -j DROP
- -A OUTPUT -p icmp --icmp-type 3 -j DROP
- -A OUTPUT -p icmp --icmp-type 3/0 -j DROP
- -A OUTPUT -p icmp --icmp-type 3/1 -j DROP
- -A OUTPUT -p icmp --icmp-type 3/2 -j DROP
- -A OUTPUT -p icmp --icmp-type 3/3 -j DROP
- -A OUTPUT -p icmp --icmp-type 3/6 -j DROP
- -A OUTPUT -p icmp --icmp-type 3/7 -j DROP
- -A OUTPUT -p icmp --icmp-type 3/8 -j DROP
- -A OUTPUT -p icmp --icmp-type 3/9 -j DROP
- -A OUTPUT -p icmp --icmp-type 3/10 -j DROP
- -A OUTPUT -p icmp --icmp-type 3/11 -j DROP
- -A OUTPUT -p icmp --icmp-type 3/12 -j DROP
- -A OUTPUT -p icmp --icmp-type 3/13 -j DROP
- -A OUTPUT -p icmp --icmp-type 3/14 -j DROP
- -A OUTPUT -p icmp --icmp-type 3/15 -j DROP
- -A OUTPUT -p icmp --icmp-type 11 -j DROP
- -A OUTPUT -p icmp --icmp-type 11/0 -j DROP
- -A OUTPUT -p icmp --icmp-type 11/1 -j DROP
- -A OUTPUT -p icmp --icmp-type 14 -j DROP
- COMMIT
- *nat
- :PREROUTING ACCEPT [0:0]
- :INPUT ACCEPT [0:0]
- :POSTROUTING ACCEPT [0:0]
- :OUTPUT ACCEPT [0:0]
- -A POSTROUTING -o eth0 -j MASQUERADE
- COMMIT
复制代码
v6
- *filter
- :INPUT ACCEPT [0:0]
- :FORWARD ACCEPT [0:0]
- :OUTPUT ACCEPT [0:0]
- -A INPUT -i lo -j ACCEPT
- -A INPUT -i tailscale0 -j ACCEPT
- -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
- -A INPUT -p tcp --dport 22 -j ACCEPT
- -A INPUT -m state --state INVALID -j DROP
- -A INPUT -p tcp -j DROP
- -A INPUT -p udp -j DROP
- -A INPUT -p icmpv6 --icmpv6-type 128 -j DROP
- -A INPUT -p icmpv6 -j ACCEPT
- -A OUTPUT -p tcp --tcp-flags ALL RST,ACK -j DROP
- -A OUTPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
- -A OUTPUT -m state --state INVALID -j DROP
- -A OUTPUT -p icmpv6 --icmpv6-type 1 -j DROP
- -A OUTPUT -p icmpv6 --icmpv6-type 1/0 -j DROP
- -A OUTPUT -p icmpv6 --icmpv6-type 1/3 -j DROP
- -A OUTPUT -p icmpv6 --icmpv6-type 1/4 -j DROP
- -A OUTPUT -p icmpv6 --icmpv6-type 3 -j DROP
- -A OUTPUT -p icmpv6 --icmpv6-type 3/0 -j DROP
- -A OUTPUT -p icmpv6 --icmpv6-type 3/1 -j DROP
- -A OUTPUT -p icmpv6 --icmpv6-type 4/1 -j DROP
- COMMIT
- *nat
- :PREROUTING ACCEPT [0:0]
- :INPUT ACCEPT [0:0]
- :POSTROUTING ACCEPT [0:0]
- :OUTPUT ACCEPT [0:0]
- -A POSTROUTING -o eth0 -j MASQUERADE
- COMMIT
复制代码 |
|