CentOS7的firewall和安装iptables
前言:CentOS7 的防火墙默认使用是firewall,而我们通常使用iptables;
本文记录了firewall基础的命令和iptables的安装和使用。
firewall部分:
part1 : 服务命令
systemctl start firewalld#启动
systemctl status firewalld #查看运行状态
systemctl stop firewalld.service #停止firewall
systemctl disable firewalld.service #禁用:禁止firewall开机启动
firewall-cmd --state #
firewall-cmd--reload 重启
part2 : 端口命令:
添加
firewall-cmd --zone=public --add-port=80/tcp --permanent (--permanent永久生效,没有此参数重启后失效)
重新载入
firewall-cmd --reload
查看
firewall-cmd --zone= public --query-port=80/tcp
删除
firewall-cmd --zone= public --remove-port=80/tcp --permanent
part3:示例
示例:firewall端口操作完之后需要重启服务生效
- [root@iZ2zeczh9tfpmxmijw5qppZ ~]# firewall-cmd --zone=public --query-port=3307/tcp
- no
- [root@iZ2zeczh9tfpmxmijw5qppZ ~]# firewall-cmd --zone=public --add-port=3307/tcp --permanent
- success
- [root@iZ2zeczh9tfpmxmijw5qppZ ~]# firewall-cmd --zone=public --query-port=3307/tcp
- no
- [root@iZ2zeczh9tfpmxmijw5qppZ ~]# firewall-cmd --reload
- success
- [root@iZ2zeczh9tfpmxmijw5qppZ ~]# firewall-cmd --zone=public --query-port=3307/tcp
- yes
示例:mysql开放远程端口
- [root@iZ2zeczh9tfpmxmijw5qppZ ~]# firewall-cmd --zone=public --add-port=3306/tcp --permanent
- success
- [root@iZ2zeczh9tfpmxmijw5qppZ ~]# firewall-cmd --reload
- success
- [root@iZ2zeczh9tfpmxmijw5qppZ ~]# firewall-cmd --state
- running
- [root@iZ2zeczh9tfpmxmijw5qppZ ~]#
- [root@iZ2zeczh9tfpmxmijw5qppZ ~]# firewall-cmd --zone=public --query-port=3306/tcp
- yes
- [root@iZ2zeczh9tfpmxmijw5qppZ ~]#
iptables部分
part1 : 服务命令
systemctl start iptables #启动
systemctl status iptables #查看运行状态
systemctl restart iptables.service #停止iptables
systemctl stop iptables.service #停止iptables
systemctl disable iptables.service #禁用:禁止iptables开机启动
systemctl enable iptables.service #
part2 : 安装
step1 : 查看是否安装
- [root@iZ2zeczh9tfpmxmijw5qppZ ~]# systemctl status iptables
- Unit iptables.service could not be found.
- [root@iZ2zeczh9tfpmxmijw5qppZ ~]#
没有相关服务
step2 : yum install
- [root@iZ2zeczh9tfpmxmijw5qppZ ~]# yum install iptables-services
- Loaded plugins: fastestmirror
- base | 3.6 kB 00:00:00
- epel | 4.3 kB 00:00:00
- extras | 3.4 kB 00:00:00
- mysql-connectors-community | 2.5 kB 00:00:00
- mysql-tools-community | 2.5 kB 00:00:00
- mysql56-community | 2.5 kB 00:00:00
- updates | 3.4 kB 00:00:00
- updates/7/x86_64/primary_db | 6.4 MB 00:00:06
- Loading mirror speeds from cached hostfile
- * base: mirrors.aliyuncs.com
- * epel: mirrors.aliyuncs.com
- * extras: mirrors.aliyuncs.com
- * updates: mirrors.aliyuncs.com
- Resolving Dependencies
- --> Running transaction check
- ---> Package iptables-services.x86_64 0:1.4.21-17.el7 will be installed
- --> Finished Dependency Resolution
- Dependencies Resolved
- ========================================================================================================================================
- Package Arch Version Repository Size
- ========================================================================================================================================
- Installing:
- iptables-services x86_64 1.4.21-17.el7 base 50 k
- Transaction Summary
- ========================================================================================================================================
- Install 1 Package
- Total download size: 50 k
- Installed size: 24 k
- Is this ok [y/d/N]: Y
- Downloading packages:
- iptables-services-1.4.21-17.el7.x86_64.rpm | 50 kB 00:00:00
- Running transaction check
- Running transaction test
- Transaction test succeeded
- Running transaction
- Installing : iptables-services-1.4.21-17.el7.x86_64 1/1
- warning: /etc/sysconfig/iptables created as /etc/sysconfig/iptables.rpmnew
- Verifying : iptables-services-1.4.21-17.el7.x86_64 1/1
- Installed:
- iptables-services.x86_64 0:1.4.21-17.el7
- Complete!
- [root@iZ2zeczh9tfpmxmijw5qppZ ~]#
安装成功!
step3 : check
- [root@iZ2zeczh9tfpmxmijw5qppZ ~]# systemctl status iptables
- iptables.service - IPv4 firewall with iptables
- Loaded: loaded (/usr/lib/systemd/system/iptables.service; disabled; vendor preset: disabled)
- Active: inactive (dead)
- [root@iZ2zeczh9tfpmxmijw5qppZ ~]#
step4 : start
- [root@iZ2zeczh9tfpmxmijw5qppZ ~]# systemctl start iptables
- [root@iZ2zeczh9tfpmxmijw5qppZ ~]# systemctl enable iptables.service
- Created symlink from /etc/systemd/system/basic.target.wants/iptables.service to /usr/lib/systemd/system/iptables.service.
- [root@iZ2zeczh9tfpmxmijw5qppZ ~]#
- [root@iZ2zeczh9tfpmxmijw5qppZ ~]# systemctl status iptables
- iptables.service - IPv4 firewall with iptables
- Loaded: loaded (/usr/lib/systemd/system/iptables.service; enabled; vendor preset: disabled)
- Active: active (exited) since Wed 2017-06-21 15:44:41 CST; 1min 17s ago
- Main PID: 506 (code=exited, status=0/SUCCESS)
- Jun 21 15:44:41 iZ2zeczh9tfpmxmijw5qppZ systemd[1]: Starting IPv4 firewall with iptables...
- Jun 21 15:44:41 iZ2zeczh9tfpmxmijw5qppZ iptables.init[506]: iptables: Applying firewall rules: [ OK ]
- Jun 21 15:44:41 iZ2zeczh9tfpmxmijw5qppZ systemd[1]: Started IPv4 firewall with iptables.
- [root@iZ2zeczh9tfpmxmijw5qppZ ~]#
step5 : 修改配置文件
vi /etc/sysconfig/iptables
systemctl restart iptables.service #重启防火墙使配置生效
step6 : 关闭SELINUX
vi/etc/selinux/config
#SELINUX=enforcing #注释掉
#SELINUXTYPE=targeted #注释掉
SELINUX=disabled #增加
:wq! #保存退出
setenforce 0 #使配置立即生效
备注:
SELINUX不关闭时,iptables不读取配置文件,一般采取关闭SELINUX的方式避免这种冲突
CentOS7的firewall和安装iptables的更多相关文章
- Linux学习之八--关闭firewall防火墙安装iptables并配置
CentOS 7之后默认使用的是firewall作为防火墙,这里改为iptables防火墙,并开启80端口.3306端口. 1.关闭firewall: systemctl stop firewalld ...
- [CENTOS7] [IPTABLES] 卸载Firewall Id安装 IPTABLES及防火墙设置
卸载Firewall ID,重装IPTABLES:先停止服务 systemctl stop firewalldsystemctl mask firewalld yum install iptabl ...
- CentOS7将firewall切换为iptables防火墙
- CentOS7.3下的一个iptables配置
centos7.3默认使用的防火墙应该是firewall,而不是iptables.而我们xxmj服务器使用的是iptables防火墙.所以,在配置防火墙之前,我们需要先关闭firewall,安装ipt ...
- centos7 关闭firewall安装iptables并配置
一.配置防火墙,开启80端口.3306端口 CentOS 7.0默认使用的是firewall作为防火墙,这里改为iptables防火墙. 1.关闭firewall: systemctl stop fi ...
- Centos7下安装iptables防火墙
说明:centos7默认使用的firewalld防火墙,由于习惯使用iptables做防火墙,所以在安装好centos7系统后,会将默认的firewall关闭,并另安装iptables进行防火墙规则设 ...
- CentOS7安装iptables防火墙
CentOS7默认的防火墙不是iptables,而是firewalle. 安装iptable iptable-service #先检查是否安装了iptables service iptables st ...
- CentOS之——CentOS7安装iptables防火墙
转载请注明出处:http://blog.csdn.net/l1028386804/article/details/50779761 CentOS7默认的防火墙不是iptables,而是firewall ...
- centos7上安装iptables
centos7上安装iptables的步骤 注意:CentOS7默认的防火墙不是iptables,而是firewalle. 安装iptable iptable-service #安装iptables ...
随机推荐
- 文档比较比对工具Beyond Compare
Beyond Compare 可以比较文件夹或文件
- 阿里云上部署了zabbix,突然无法收到报警邮件的解决办法
在阿里云上部署了zabbix,一直能正常接收到zbx发来的报警邮件(报警邮箱是163的),不知是什么原因,突然无法接收到报警邮件了. 但在服务器上手动执行echo "hello"| ...
- windows查找端口占用/ 终结端口占用 ------------windows小技巧
前沿 我是一名小程序员,经常通过一些类似tomcat,jettry 等服务器工具 调试项目.有时候莫名其妙的就会出现 程序关闭不正常的情况!去查端口又死活找不到!最后只能重启电脑 后面,在网上查了一些 ...
- 递归和静态static
function sum($n){ if($==1){ return 1; } return $n+sum($n-1); } echo sum(100); ---------------------- ...
- hbase系列之:独立模式部署hbase
一.概述 在上一篇博文中,我简要介绍了hbase的部分基础概念,如果想初步了解hbase的理论,可以参看上一篇博文 hbase系列之:初识hbase .本博文主要介绍独立模式下部署hbase及hbas ...
- JQuery的选择器对控件ID含有特殊字符的解决方法-涨姿势了!
1.jquery类库在我们实际项目中用的很多,大家经常需要根据控件的id,获取对应的html元素. 但是:当id含有特殊字符的时候,是不能选中的. 2. 自己简单的测试了下,jquery的id选择器只 ...
- 20155233 2016-2017-2 《Java程序设计》第7周学习总结
20155233 2016-2017-2 <Java程序设计>第7周学习总结 学习目标 了解Lambda语法 了解方法引用 了解Fucntional与Stream API 掌握Date与C ...
- iOS程序启动过程笔记
CHENYILONG Blog 笔记 一.iOS程序的完整启动过程(有storyboard)1.先执行main函数,main内部会调用UIApplicationMain函数 2.UIApplicati ...
- 49、多线程创建的三种方式之继承Thread类
继承Thread类创建线程 在java里面,开发者可以创建线程,这样在程序执行过程中,如果CPU空闲了,就会执行线程中的内容. 使用Thread创建线程的步骤: 1.自定义一个类,继承java.lan ...
- Linux基础-yum软件包管理
任务目标:自定义yum仓库:createrepo,自定义repo文件,使用yum命令安装httpd软件包,卸载httpd软件包:yum –y remove 软件名 ,使用yum安装组件'KDE 桌面' ...