CentOS启用iptables防火墙

CentOS在7.0之前貌似都是用的iptables为防火墙的,在7.0以后都是firewall,其实我也不知道为嘛,但是大部分人都是用iptables,so我也用它了。

一、关闭firewall

1 //停止firewall2 sudo systemctl stop firewalld.service3 //禁止firewall开机启动4 sudo systemctl disable firewalld.service

二、当然就是安装iptables防火墙

1.安装

1 //安装2 sudo yum install iptables-services

2.配置

//编辑iptables,如果权限不够打开时使用sudovi /etc/sysconfig/iptables//文件内容# Firewall configuration written by system-config-firewall# Manual customization of this file is not recommended.*filter:INPUT ACCEPT [0:0]:FORWARD ACCEPT [0:0]:OUTPUT ACCEPT [0:0]-A INPUT -m state –state ESTABLISHED,RELATED -j ACCEPT-A INPUT -p icmp -j ACCEPT-A INPUT -i lo -j ACCEPT-A INPUT -m state –state NEW -m tcp -p tcp –dport 22 -j ACCEPT-A INPUT -m state –state NEW -m tcp -p tcp –dport 80 -j ACCEPT-A INPUT -j REJECT –reject-with icmp-host-prohibited-A FORWARD -j REJECT –reject-with icmp-host-prohibitedCOMMIT//保存文件C+C 然后:wq退出->由于受emacs的习惯这里的C就代表Ctrl,so C+C其实就是Ctrl+C,以后基本都会那么写,比较方便。//重启防火墙使配置生效sudo systemctl restart iptables.service//设置防火墙开机启动sudo systemctl enable iptables.service

OK,这时,你的iptables就已经配置好了,如果以后你还想添加端口,那么接着往下看。

3.开放端口

//里面的*要替换成你要开放的端口号/sbin/iptables -I INPUT -p tcp –dport * -j ACCEPT//保存配置/etc/rc.d/init.d/iptables save//查看你更改后的iptables/etc/init.d/iptables status//重启iptablessudo service iptables restart

好了,这些就是一些有关iptables的基本配置了,有超高难度的东西,也希望大家能告诉我一下。

更多iptables相关教程见以下内容:

CentOS 7.0关闭默认防火墙启用iptables防火墙 http://www.68idc.cn/Linux/2015-05/117473.htm

iptables使用范例详解 http://www.68idc.cn/Linux/2014-03/99159.htm

Linux防火墙iptables详细教程 http://www.68idc.cn/Linux/2013-07/87045.htm

iptables的备份、恢复及防火墙脚本的基本使用 http://www.68idc.cn/Linux/2013-08/88535.htm

Linux下防火墙iptables用法规则详解 http://www.68idc.cn/Linux/2012-08/67952.htm

Linux下iptables防火墙设置 http://www.68idc.cn/Linux/2015-10/123843.htm

更多CentOS相关信息见CentOS 专题页面 http://www.68idc.cn/topicnews.aspx?tid=14

如若今生再相见,哪怕流离百世,迷途千年,也愿。

CentOS启用iptables防火墙

相关文章:

你感兴趣的文章:

标签云: