banner
李大仁博客

李大仁博客

天地虽大,但有一念向善,心存良知,虽凡夫俗子,皆可为圣贤。

[Linux]CentOS防火墙iptables的配置

iptables 是与 Linux 内核集成的 IP 信息包过滤系统,其自带防火墙功能,我们在配置完服务器的角色功能后,需要修改 iptables 的配置。 配置 CentOS 和 Ubuntu 等 Linux 服务器时需要对服务器的 iptables 进行配置,以下是 iptables 常见的几种配置方法。

1. 查看当前所有的 iptables 配置

iptables -L -n

2. 添加允许 INPUT 访问规则,以下时常见服务的端口设置,如果需要拒绝访问,则将 ACCEPT 改为 DROP 即可

#SSH
iptables -A INPUT -p tcp --dport 22 -j ACCEPT
#HTTP
iptables -A INPUT -p tcp --dport 80 -j ACCEPT
iptables -A INPUT -p tcp --dport 8080 -j ACCEPT
#HTTPS
iptables -A INPUT -p tcp --dport 443 -j ACCEPT
#POP3
iptables -A INPUT -p tcp --dport 110 -j ACCEPT
#SMTP
iptables -A INPUT -p tcp --dport 25 -j ACCEPT
#FTP
iptables -A INPUT -p tcp --dport 21 -j ACCEPT
iptables -A INPUT -p tcp --dport 20 -j ACCEPT
#DNS
iptables -A INPUT -p tcp --dport 53 -j ACCEPT

3. 添加使用 IP 限制 INPUT 访问规则,这里拿 SSH 为例,192.168.0.100 为允许的 IP

#DELETE
iptables -D INPUT -p tcp --dport 22 -j ACCEPT
#ADD
iptables -A INPUT -s 192.168.0.100 -p tcp --dport 22 -j ACCEPT

4. 保存 iptables 的设置,修改完规则后记得保存

/etc/rc.d/init.d/iptables save

5. 重启 iptables

service iptables restart

6. 开启 / 关闭 开机启动

chkconfig iptables on
chkconfig iptables off

参考地址: http://www.cnblogs.com/JemBai/archive/2009/03/19/1416364.html http://linux.chinaunix.net/techdoc/net/2007/12/17/974490.shtml

Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.