1
2
3
4
iptables -I INPUT -i lo -j ACCEPT
iptables -I INPUT -p tcp -m state --state NEW -m tcp --dport 22 -j ACCEPT #允许远程向本机22号端口发起连接
iptables -I INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT #允许任何本机发起请求返回的数据
iptables -A INPUT -j REJECT #默认拒绝任何主机

之后添加允许的规则使用iptables -I 插入到以上规则之前

参考: http://www.zsythink.net/archives/category/%e8%bf%90%e7%bb%b4%e7%9b%b8%e5%85%b3/iptables/

https://www.frozentux.net/iptables-tutorial/iptables-tutorial.html#TRAVERSINGGENERAL