登录

linux iptables防火墙的配置

外贸资料
0 526

在服务器上端口的开放是有限的,为了更好的避免服务器被攻击,在服务器上必须限制开发的端口。

一般我在用虚拟机的时候,都会直接将防火墙关闭。

一、查看防火墙的配置。
  1. vi /etc/sysconfig/iptables
二、配置防火墙的端口,开放80,22,3306。

将下面的代码直接复制进配置中

  1. # Firewall configuration written by system-config-firewall
  2. # Manual customization of this file is not recommended.
  3. *filter
  4. :INPUT ACCEPT [0:0]
  5. :FORWARD ACCEPT [0:0]
  6. :OUTPUT ACCEPT [0:0]
  7. -A INPUT -m state --state ESTABLISHEDRELATED -j ACCEPT
  8. -A INPUT -p icmp -j ACCEPT
  9. -A INPUT -i lo -j ACCEPT
  10. #http
  11. -A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT
  12. #mysql
  13. -A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT
  14. #ssh
  15. -A INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT
  16. -A INPUT -j REJECT --reject-with icmp-host-prohibited
  17. -A FORWARD -j REJECT --reject-with icmp-host-prohibited
  18. COMMIT
三、重启防火墙,设置随系统启动。
  1. service iptables restart 
  2.  或者
  3. /etc/init.d/iptables restart
  4. 启动
  5. chkconfig iptables on
四、关闭防火墙。
  1. chkconfig iptables off

发表评论

0 个回复

yzw

yzw

217 2017-05-15 加入 上海

(这个人懒得留下签名)

热门标签

热门推荐