CentOS 7下iptables配置添加修改规则端口方法(转)
简介:
Linux CentOS 7默认没有安装iptables,默认的防火墙是firewalld,云吞铺子分享CentOS 7系统下iptables安装、iptables规则配置(放行或者禁用端口)教程方法: 以下大致步骤为:先关闭firewalld防火墙,然后按照iptables,最后配置添加或者禁用端口规则,详细如下: 检查firewalld并禁用 安装iptables之前先检查下当前CentOS 7系统下的firewalld防火墙状态,如果是开启状态,需要先关闭firewalld防火墙。
Linux CentOS 7默认没有安装iptables,默认的防火墙是firewalld,云吞铺子分享CentOS 7系统下iptables安装、iptables规则配置(放行或者禁用端口)教程方法:
以下大致步骤为:先关闭firewalld防火墙,然后按照iptables,最后配置添加或者禁用端口规则,详细如下:
检查firewalld并禁用
安装iptables之前先检查下当前CentOS 7系统下的firewalld防火墙状态,如果是开启状态,需要先关闭firewalld防火墙。
先查看firewalld状态
查看firewalld状态,命令:
systemctl status firewalld

开启状态:显示绿色的“active (running)”,则代表开启;
关闭状态:显示“inactive (dead)”,代表关闭。
再关闭firewalld
如果firewalld是开启状态,需要执行命令:
systemctl stop firewalld
,关闭firewalld即可。
一:安装iptables
安装命令:iptables:yum install -y iptables-services
二:启动iptables
启动命令:systemctl start iptables
三:查看当前iptables状态
运行iptables启动命令后,可以查看下iptables是否启动成功,确保iptables启动成功
查看状态:systemctl status iptables
如果提示绿色的“active (exited)”,则iptables已经启动成功。
四:查看iptables默认规则
查看默认规则命令:iptables -L
安装iptables后,可以查看下当前系统下的iptables规则,熟悉一下。
五:备份iptables规则
安全起见,可以先备份下当前的iptables规则,然后再修改/添加规则
备份命令:cp -a /etc/sysconfig/iptables /etc/sysconfig/iptables.bak
六:添加或修改规则(放行或禁用端口)
云吞铺子以放行80号端口为例:
- 1、添加以下规则可以放行80端口命令:
iptables -I INPUT -p tcp --dport 80 -m state --state NEW -j ACCEPT
- 2、查看规则是否生效,命令:
iptables -L
- 3、生效后保存添加的规则,命令:
iptables-save > /etc/sysconfig/iptables
- 4、设置iptables开启启动,命令:
systemctl enable iptables.service
以上为CentOS 7系统下iptables安装、配置规则和启用的方法,前面啰嗦比较多,重点在第六步,设置完毕后重启服务器(命令:systemctl reboot)或者直接 service iptables restart也可以
七:查看服务器监听的端口
netstat -tulpen
[root@Server-45lvhb ~]# netstat -tulpen
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State User Inode PID/Program name
tcp 0 0 127.0.0.1:6379 0.0.0.0:* LISTEN 996 15186 739/redis-server 12
tcp 0 0 192.168.88.50:8300 0.0.0.0:* LISTEN 10002 21662 1556/consul
tcp 0 0 192.168.88.50:8301 0.0.0.0:* LISTEN 10002 21844 1556/consul
tcp 0 0 0.0.0.0:53229 0.0.0.0:* LISTEN 0 20668 1782/nginx: master
tcp 0 0 127.0.0.1:7373 0.0.0.0:* LISTEN 10000 20234 1544/serf
tcp 0 0 192.168.88.50:8302 0.0.0.0:* LISTEN 10002 21842 1556/consul
tcp 0 0 0.0.0.0:53230 0.0.0.0:* LISTEN 0 20667 1782/nginx: master
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 0 20664 1782/nginx: master
tcp 0 0 0.0.0.0:4369 0.0.0.0:* LISTEN 10003 17892169 118561/epmd
tcp 0 0 0.0.0.0:53333 0.0.0.0:* LISTEN 0 20666 1782/nginx: master
tcp 0 0 0.0.0.0:4822 0.0.0.0:* LISTEN 10007 15252 744/guacd
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 0 15244 854/sshd
tcp 0 0 0.0.0.0:15672 0.0.0.0:* LISTEN 10003 17893803 118622/beam.smp
tcp 0 0 0.0.0.0:9272 0.0.0.0:* LISTEN 10000 9024899 108110/python
tcp 0 0 0.0.0.0:443 0.0.0.0:* LISTEN 0 20665 1782/nginx: master
tcp 0 0 0.0.0.0:8100 0.0.0.0:* LISTEN 10000 9024140 4848/python2
tcp 0 0 0.0.0.0:25672 0.0.0.0:* LISTEN 10003 17893780 118622/beam.smp
tcp 0 0 0.0.0.0:8200 0.0.0.0:* LISTEN 10000 21738 496/python3
tcp6 0 0 :::3306 :::* LISTEN 10009 13126221 111048/mysqld
tcp6 0 0 127.0.0.1:8010 :::* LISTEN 0 17264 777/java
tcp6 0 0 :::9100 :::* LISTEN 0 15263 751/node_exporter
tcp6 0 0 :::9999 :::* LISTEN 10006 23294 4038/java
tcp6 0 0 :::9200 :::* LISTEN 997 25037 1505/java
tcp6 0 0 :::4369 :::* LISTEN 10003 17892170 118561/epmd
tcp6 0 0 :::8081 :::* LISTEN 0 16149 777/java
tcp6 0 0 :::9300 :::* LISTEN 997 25000 1505/java
tcp6 0 0 :::8500 :::* LISTEN 10002 21854 1556/consul
tcp6 0 0 :::22 :::* LISTEN 0 15246 854/sshd
tcp6 0 0 :::3000 :::* LISTEN 10005 9024870 108090/grafana-serv
tcp6 0 0 :::8600 :::* LISTEN 10002 21852 1556/consul
tcp6 0 0 :::3005 :::* LISTEN 10000 21475 4148/java
tcp6 0 0 :::9089 :::* LISTEN 10004 21615 1545/prometheus
tcp6 0 0 :::9090 :::* LISTEN 10004 19191 1546/prometheus
tcp6 0 0 :::9474 :::* LISTEN 10000 20230 1544/serf
tcp6 0 0 :::9091 :::* LISTEN 10004 21562 1500/pushgateway
tcp6 0 0 :::33060 :::* LISTEN 10009 13126981 111048/mysqld
tcp6 0 0 :::9093 :::* LISTEN 10004 20640 1498/alertmanager
tcp6 0 0 127.0.0.1:8006 :::* LISTEN 0 23819 777/java
tcp6 0 0 :::9094 :::* LISTEN 10004 20219 1498/alertmanager
tcp6 0 0 :::5671 :::* LISTEN 10003 17892198 118622/beam.smp
tcp6 0 0 :::5672 :::* LISTEN 10003 17892195 118622/beam.smp
udp 0 0 192.168.88.50:8301 0.0.0.0:* 10002 21845 1556/consul
udp 0 0 192.168.88.50:8302 0.0.0.0:* 10002 21843 1556/consul
udp6 0 0 :::8600 :::* 10002 21851 1556/consul
udp6 0 0 :::9094 :::* 10004 20220 1498/alertmanager
udp6 0 0 :::9474 :::* 10000 20231 1544/serf
八:查看远程的端口是否能ping通
telnet 192.168.88.50 15672
CentOS 7下iptables配置添加修改规则端口方法(转)的更多相关文章
- linux下IPTABLES配置详解 (防火墙命令)
linux下IPTABLES配置详解 -A RH-Firewall-1-INPUT -p tcp -m state --state NEW -m tcp --dport 24000 -j ACCEPT ...
- CentOS 7下搭建配置SVN服务器
CentOS 7下搭建配置SVN服务器 1. 安装 CentOS通过yum安装subversion. $ sudo yum install subversion subversion安装在/bin目录 ...
- Android Linux自带iptables配置IP访问规则
利用Linux自带iptables配置IP访问规则,即可做到防火墙效果
- linux下iptables配置模板
linux下iptables配置模板 # Flush all policy iptables -F iptables -X iptables -Z iptables -t nat -F iptable ...
- CentOS 7下使用chkconfig添加的服务无法使用/etc/profile里面的环境变量
经过分析/etc/profile为入口的,基本是登录后执行的变量,而使用chkconfig添加的服务多变以守护经常运行,没有登录. CentOS 7下使用chkconfig添加的服务无法使用/etc/ ...
- CentOS下iptables 配置详解
如果你的IPTABLES基础知识还不了解,建议先去看看. 开始配置 我们来配置一个filter表的防火墙. (1)查看本机关于IPTABLES的设置情况 [root@tp ~]# iptables - ...
- CentOS 7下安装配置搭建jdk+tomcat+MariaDB环境
1.JDK安装 注意:rpm与软件相关命令 相当于window下的软件助手 管理软件 步骤: 1)查看当前Linux系统是否已经安装java 输入 rpm -qa | grep java 2)卸载两个 ...
- tony_iptables_01_linux下IPTABLES配置详解(转)
如果你的IPTABLES基础知识还不了解,建议先去看看. 开始配置 我们来配置一个filter表的防火墙. (1)查看本机关于IPTABLES的设置情况 [root@tp ~]# iptables - ...
- linux下IPTABLES配置详解(转)
如果你的IPTABLES基础知识还不了解,建议先去看看. 开始配置 我们来配置一个filter表的防火墙. (1)查看本机关于IPTABLES的设置情况 [root@tp ~]# iptables - ...
随机推荐
- Chapter 1 A Definition of Causal Effect
目录 1.1 Individual casual effects 1.2 Average casual effects 1.5 Causation versus association Hern\(\ ...
- electron串口通信使用serialport安装报错
1.报错信息没有安装python环境 1 gyp ERR! find Python 2 gyp ERR! find Python Python is not set from command line ...
- JDK HttpClient 多重请求-响应的处理
HttpClient 多重请求-响应的处理 目录 HttpClient 多重请求-响应的处理 1. 简述 2. 请求响应流程图 3. 用户请求的复制 4. 多重请求处理概览 5. 请求.响应过滤的执行 ...
- Linux设置主机名与hosts映射
目的 方便操作,便于建立Linux集群. 设置主机名 查看主机名:hostname 设置主机名,修改/etc/hosts:vim /etc/hostname 通过主机名ping通 原理 通过hosts ...
- 搞一下vue生态,从vuex开始
Vuex vuex 是专门帮助vue管理的一个js库,利用了vue.js中细粒度数据响应机制来进行高效的状态更新. vuex核心就是store,store就是个仓库,这里采用了单一的store状态树, ...
- localstorage的浏览器支持情况
localStorage的兼容性不错,就国内的情况,已经基本没有问题了.localStorage的原理很简单,浏览器为每个域名划出一块本地存储空间,用户网页可以通过localStorage命名空间进行 ...
- js 拟写登录页 可以拖动登录框
<!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8&quo ...
- python+requests传两种参数体
在JMeter请求参数中,我们了解到,在做接口测试时,发送请求的参数有两种格式,一种是Parameters,一种是JSON.怎么区分请看 https://www.cnblogs.com/testlea ...
- JMeter_请求header
在接口调试的时候,请求参数确认正确无误,但是请求失败! 通过对比header,发现header缺少一些字段(token)以及传入的值不正确(Content-Type) 增加这些字段信息后,接口调试成功 ...
- Web开发之response
Web服务器收到客户端的http请求,会针对每一次请求,分别创建一个用于代表请求的request对象.和代表响应的response对象. 我们要获取客户机提交过来的数据,只需要找request对象就行 ...