最近在学习linux防火墙,把一些地方记录一下
centos6系统的默认防火墙:
linux –L -v
- 设置默认路由规则
iptables -P INPUT ACCEPT
iptables -P OUTPUT ACCEPT
iptables -P FORWARD ACCEPT
2、对RELATED,ESTABLISHED状态的连接允许通过
iptables -A INPUT -m state –state RELATED,ESTABLISHED -j ACCEPT
3、允许icmp连接通过,如:ping
iptables -A INPUT -p icmp -j ACCEPT
4、允许回环连接通过
iptables -A INPUT -i lo -j ACCEPT
5、允许ssh连接,因为前面已经对已连接或关联性连接通过了,所以这里只设置NEW状态
iptables -A INPUT -p tcp –dport 22 -m state –state NEW -j ACCEPT
6、拒绝其他的icmp主机请求
iptables -A INPUT -j REJECT –reject-with icmp-host-prohibited
我搭建了一个vsftp服务器,想让ftp通过防火墙连接到服务器,要新插入一条防火墙规则
iptables –L –line-nuber
看最后一条的行号
iptables –I INPUT 5 –p tcp –dport 21 –m state –state NEW –j ACCEPT
这样还不够,还要加载系统模块,要不然连接会卡到LIST的地方。
modprobe ip_conntrack_ftp