场景:在本地虚拟机上使用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防火墙的更多相关文章

  1. CentOS 7.0关闭默认firewall防火墙启用iptables防火墙

    操作系统环境:CentOS Linux release 7.0.1406(Core) 64位CentOS 7.0默认使用的是firewall作为防火墙,这里改为iptables防火墙步骤. 1.关闭f ...

  2. CentOS7关闭默认防火墙启用iptables防火墙

    CentOS 7.0默认使用的是firewall作为防火墙,这里改为iptables防火墙步骤. 1.关闭firewall: systemctl stop firewalld.service #停止f ...

  3. Centos 7 关闭firewall防火墙启用iptables防火墙

    一.关闭firewall防火墙 1.停止firewall systemctl stop firewalld.service 2.禁止firewall开机启动 systemctl disable fir ...

  4. CentOS 7.0关闭默认防火墙启用iptables防火墙

    转自:https://www.cnblogs.com/lixuwu/p/6087023.html 阅读目录 1 配置防火墙,开启80端口.3306端口 2 关闭SELINUX 3 CentOS 配置防 ...

  5. 玩转Linux之- CentOS 7.0,启用iptables防火墙

    原文 玩转Linux之- CentOS 7.0,启用iptables防火墙 CentOS 7.0默认使用的是firewall作为防火墙,这里改为iptables防火墙. 1.关闭firewall:sy ...

  6. CentOS 7.0 关闭firewalld防火墙指令 及更换Iptables防火墙

    CentOS 7.0 关闭firewalld防火墙指令 及更换Iptables防火墙 时间:2014-10-13 19:03:48  作者:哎丫丫  来源:哎丫丫数码网  查看:11761  评论:2 ...

  7. CentOS 7.0,启用iptables防火墙

    CentOS 7.0默认使用的是firewall作为防火墙,这里改为iptables防火墙. 1.关闭firewall: systemctl stop firewalld.service #停止fir ...

  8. CentOS 7.0启用iptables防火墙

    CentOS 7.0默认使用的是firewall作为防火墙,这里改为iptables防火墙. 1.关闭firewall: systemctl stop firewalld.service #停止fir ...

  9. CentOS 7.3 关闭默认防火墙&远程登录

             小编作为一个运维新人,踩坑之路是必不可少的.          这不,新来了一家公司,做云运维工程师,新的环境,网络和之前的都不一样,VMware Workstation虚拟机上的网 ...

随机推荐

  1. Spring学习(18)--- AOP基本概念及特点

    AOP:Aspect Oriented Programing的缩写,意为:面向切面编程,通过预编译方式和运行期动态代理实现程序程序功能的统一维护的一种技术 主要的功能是:日志记录,性能统计,安全控制, ...

  2. 新增article注意事项

    默认情况下在日志复制中如果新增加Article那么需要产生一个包含所有Article的Snapshot.由于产生Snapshot会加锁,同时会产生IO操作,所以对于大的数据库性能影响是很大的. 可以通 ...

  3. lftp的用法

    lftp是Linux下的一个ftp工具,支持ftp, ftps, http, https, hftp, fish, sftp, file, bittorrent等协议(支持https 和 ftps,必 ...

  4. Qt中的View Model模型

    原始日期: 2016-08-17 21:19 Qt中的View主要有三种QListView,QTreeView, QTabelView 而对应的Model是:QStringListModel, QAb ...

  5. python selenium-webdriver 通过cookie登陆(十一)

    上节介绍了浏览器的常用方法,涉及到了cookie的使用,本节介绍一下如何利用cookie进行登陆系统,这里使用到了request模块,我们首先利用request模块,请求登陆地址进行登陆,登陆成功以后 ...

  6. response.sendRedirect页面跳转的方法总结——实习第六天

    今天想到要写这个博客完全是因为今天在这上面摔了一跤,同时也意识到了对于一个学Java的人来讲,知其然并且知其所以然是有多么的重要. 今天报了一个错误,讲的是空指针异常,原因就是在response.se ...

  7. Chrome debug tooltip having scrollbars

    谷歌浏览器debugger,查看变量值,出现滚动条无法查看到具体的值 I had the same problem and found your post. I went as far as rein ...

  8. 后端对数组json_encode,前端遍历输出

    echo json_encode($get_city_lists); <script type="text/javascript"> function get_city ...

  9. iOS9新特性之常见关键字、泛型

    #pragma mark -- nullable nullable:可以为空,只能修饰对象,不能修饰基本数据类型 // 方式一: @property (nonatomic, copy, nullabl ...

  10. 再谈AbstractQueuedSynchronizer:基于AbstractQueuedSynchronizer的并发类实现

    公平模式ReentrantLock实现原理 前面的文章研究了AbstractQueuedSynchronizer的独占锁和共享锁,有了前两篇文章的基础,就可以乘胜追击,看一下基于AbstractQue ...