(转)CentOS 7.0关闭默认防火墙启用iptables防火墙
场景:在本地虚拟机上使用ftp软件需要进行相应的端口设置,不可避免要访问Cnetos的防火墙,默认firewall操作不方便,所以需要进行相应的替换。
1 配置防火墙,开启80端口、3306端口
1.1 配置iptables
CentOS 7 默认使用firewalld来管理iptables规则,由于防火墙规则变动的情况很少,动不动态变得无所谓了。但是习惯是魔鬼,跟之前不一样,总是感觉不太习惯。
systemctl disable firewalld
yum remove firewalld -y
使用下面的办法来恢复原来的习惯,同时解决iptables开机启动的问题。
yum install iptables-services -y
systemctl enable iptables
这样的话,iptables服务会开机启动,自动从/etc/sysconfig/iptables 文件导入规则。
为了让/etc/init.d/iptables save 这条命令生效,需要这么做
cp /usr/libexec/iptables/iptables.init /etc/init.d/iptables
/etc/init.d/iptables save
而chkconfig iptables 命令会自动重定向到sytemctl enable iptables (并不清楚这这条命令的相关作用)
1.2 防火墙端口配置
在配置防火墙前先备份一下配置文件:
cp /etc/sysconfig/iptables /etc/sysconfig/iptables_vba
编辑防火墙配置文件,添加80和3306两个端口
#编辑防火墙配置文件
vim /etc/sysconfig/iptables
# Firewall configuration written by system-config-firewall Linux学习,http:// linux.it.NET.cn # Manual customization of this file is not recommended. *filter :INPUT ACCEPT [0:0] :FORWARD ACCEPT [0:0] :OUTPUT ACCEPT [0:0] Linux学习,http:// linux.it.Net.cn -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 -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT
-A INPUT -j REJECT --reject-with icmp-host-prohibited
-A FORWARD -j REJECT --reject-with icmp-host-prohibited IT网,http://www.it.net.cn COMMIT IT网,http://www.it.net.cn :wq! #保存退出
备注:这里使用80和8080端口为例。***部分一般添加到“-A INPUT -p tcp -m state --state NEW -m tcp--dport 22 -j ACCEPT”行的上面或者下面,切记不要添加到最后一行,否则防火墙重启后不生效。
systemctl restart iptables.service #最后重启防火墙使配置生效
systemctl enable iptables.service #设置防火墙开机启动
2 关闭SELINUX
除了需要更改系统默认的防火墙以外,我们还需要关闭SELinux,这个步骤是可选的。(如果要安装vsftpd服务时候,就需要执行下面的步骤)
SELinux是一个由美国国家安全局和SCC开发的 Linux的一个扩张强制访问控制安全模块。它可以保护Linux,但是开着SELinux有时候会发生一些莫名其妙的问题。所以在这里还是关掉算了。
vi /etc/selinux/config #SELINUX=enforcing #注释掉 #SELINUXTYPE=targeted #注释掉
SELINUX=disabled #增加
:wq! #保存退出 setenforce #使配置立即生效
3 CentOS 配置防火墙操作实例(启、停、开、闭端口)
注:防火墙的基本操作命令:
查询防火墙状态:
[root@localhost ~]# service iptables status 停止防火墙:
[root@localhost ~]# service iptables stop 启动防火墙:
[root@localhost ~]# service iptables start 重启防火墙:
[root@localhost ~]# service iptables restart 永久关闭防火墙:
[root@localhost ~]# chkconfig iptables off 永久关闭后启用:
[root@localhost ~]# chkconfig iptables on
1、查看防火墙状态
[root@localhost ~]# service iptables status
2、依葫芦画瓢,我们添加8080端口和9990端口
3、保存/etc/sysconfig/iptables文件,并在终端执行
[root@localhost ~]# service iptables restart <回车>
4、从新查看防火墙状态
[root@localhost ~]# service iptables status<回车>
5、时候,服务器的8080和9990端口就可以对外提供服务了。
6、其他端口的开放模式就是类似如此开放模式。
(转)CentOS 7.0关闭默认防火墙启用iptables防火墙的更多相关文章
- CentOS 7.0关闭默认firewall防火墙启用iptables防火墙
操作系统环境:CentOS Linux release 7.0.1406(Core) 64位CentOS 7.0默认使用的是firewall作为防火墙,这里改为iptables防火墙步骤. 1.关闭f ...
- CentOS7关闭默认防火墙启用iptables防火墙
CentOS 7.0默认使用的是firewall作为防火墙,这里改为iptables防火墙步骤. 1.关闭firewall: systemctl stop firewalld.service #停止f ...
- Centos 7 关闭firewall防火墙启用iptables防火墙
一.关闭firewall防火墙 1.停止firewall systemctl stop firewalld.service 2.禁止firewall开机启动 systemctl disable fir ...
- CentOS 7.0关闭默认防火墙启用iptables防火墙
转自:https://www.cnblogs.com/lixuwu/p/6087023.html 阅读目录 1 配置防火墙,开启80端口.3306端口 2 关闭SELINUX 3 CentOS 配置防 ...
- 玩转Linux之- CentOS 7.0,启用iptables防火墙
原文 玩转Linux之- CentOS 7.0,启用iptables防火墙 CentOS 7.0默认使用的是firewall作为防火墙,这里改为iptables防火墙. 1.关闭firewall:sy ...
- CentOS 7.0 关闭firewalld防火墙指令 及更换Iptables防火墙
CentOS 7.0 关闭firewalld防火墙指令 及更换Iptables防火墙 时间:2014-10-13 19:03:48 作者:哎丫丫 来源:哎丫丫数码网 查看:11761 评论:2 ...
- CentOS 7.0,启用iptables防火墙
CentOS 7.0默认使用的是firewall作为防火墙,这里改为iptables防火墙. 1.关闭firewall: systemctl stop firewalld.service #停止fir ...
- CentOS 7.0启用iptables防火墙
CentOS 7.0默认使用的是firewall作为防火墙,这里改为iptables防火墙. 1.关闭firewall: systemctl stop firewalld.service #停止fir ...
- CentOS 7.3 关闭默认防火墙&远程登录
小编作为一个运维新人,踩坑之路是必不可少的. 这不,新来了一家公司,做云运维工程师,新的环境,网络和之前的都不一样,VMware Workstation虚拟机上的网 ...
随机推荐
- 初学unslider
1.关于unslider下载 官方提供的下载页面是http://www.bootcss.com/p/unslider/,但总是进不了下载页面,所以我就查看主页的源码,找到unslider.min.js ...
- SQL Server 实现Split函数
添加一个表值函数. CREATE function [dbo].[fnSplit] ( ), --要分割的字符串 ) --字符串之间的分隔符 ) ,), TempName )) as begin de ...
- tr的用法
一.tr的基本功能 功能:转换.挤压或删除字符串,从标准输入接收输入,输出到标准输出基本用法:tr [options] string1 [string2] 二.例子 1.转换 $ echo " ...
- 在 Mac OS 上编译 FFmpeg
本文转自:在 Mac OS 上编译 FFmpeg | www.samirchen.com 安装 Xcode 和 Command Line Tools 从 App Store 上安装 Xcode,并确保 ...
- document.getElementById("searchForm").submit is not a function
document.getElementById("searchForm").submit is not a function在用userForm.submit() 提交表单的时候, ...
- kafka 源代码分析之Message(v0.10)
这里主要更新一下kafka 0.10.0版本的message消息格式的变化. message 的格式在0.10.0的版本里发生了一些变化(相对于0.8.2.1的版本)这里把0.10.0的message ...
- Kanzi 倒影效果制作
在kanzi中,倒影效果会经常用到,比如多媒体中. 先来看一下最终的实现效果: 在这个效果中,我们的需求是,倒影图与原图一致,透明度和可见范围可以调节. 下面说一下实现的步骤: 1.创建工程后,Roo ...
- Server from URL
在你做网页时,如果网页需要运行ActiveX或脚本,并且他们位于客户端以外的地方, 那么可以添加这个注释语句,IE当然不会不理他, IE会按照他指出的URL去找脚本的位置. 这句话的作用是让Inter ...
- 没有在xml中引入 相关的配置文件
错误信息如下 严重: Servlet.service() for servlet AutoReplyServlet threw exception org.apache.ibatis.except ...
- 投票系统 & js脚本简单刷票
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...