场景:在本地虚拟机上使用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学习(24)--- AOP之 Aspect instantiation models(aspect实例模式)特别说明

    重要: schema-defined aspects只支持singleton model,即 基于配置文件的aspects只支持单例模式

  2. windows端口占用处理工具

    一.描述 笔者在最近使用tomcat时,老是会遇到这种端口占用的问题,便写了这个小的exe,用于解决windows下的端口占用问题. 好吧,其实是我实在记不住CMD下的那几行命令.这玩意的实现比较简单 ...

  3. Redis中的基本数据结构

    Redis基础数据结构 基础数据结构 sds简单动态字符串 数据结构 typedef struct sdstr{ int len // 字符串分配的字节 int free // 未使用的字节数 cha ...

  4. 可能是最详细的 Hexo + GitHub Pages 搭建博客的教程

    前言:博主目前大三,Web 前端爱好者.写博客的好处,不是为了写而写,而是一个记录思想的过程.不要考虑它能带给你什么,而是你自己从中收获了什么. 最近刚好有空,于是就参照网上的各种教程,搭建了一个博客 ...

  5. python+NLTK 自然语言学习处理:环境搭建

    首先在http://nltk.org/install.html去下载相关的程序.需要用到的有python,numpy,pandas, matplotlib. 当安装好所有的程序之后运行nltk.dow ...

  6. 15套java架构师、集群、高可用、高可扩 展、高性能、高并发、性能优化Redis、ActiveMQ、Nginx、Mycat、Netty、Jvm大型分布式项目实战视频教程

    * { font-family: "Microsoft YaHei" !important } h1 { color: #FF0 } 15套java架构师.集群.高可用.高可扩 展 ...

  7. explode和implode的运用

    $kesu_list=DD('Kesu.Kesu')->kesu_list(); foreach($kesu_list[0] as $key=>$val){ $reason_id_list ...

  8. ajax异步加载遮罩层特效

    <!doctype html> <html> <head> <title>遮罩层(正在加载中)</title> <meta chars ...

  9. 【LeetCode】94. Binary Tree Inorder Traversal

    题目: Given a binary tree, return the inorder traversal of its nodes' values. For example:Given binary ...

  10. WPF:动态显示或隐藏Listview的某一列

    这几天做项目,需要做个listview满足能够动态显示或隐藏某些列,由于自己是菜鸟水平,查了两天资料也没有想出解决办法.就在我山穷水尽的时候看到了Mgen的一篇博客,给了我很大启发,所以我也决定把自己 ...