目录

  • 使用 iptables 方式
  • 使用 firewalld 方式(推荐)
    • firewalld 常用命令

一、使用 iptables 方式


1、安装 iptables-services如果没有安装的话

yum install iptables-services

设置开机启动

systemctl enable iptables

2、关闭 firewall

# 关闭并屏蔽 firewalld
systemctl stop firewalld
systemctl mask firewalld# 解除 iptables 的屏蔽
systemctl unmask iptables

3、开放 8080 端口

iptables -A INPUT -m tcp -p tcp --dport 8080 -j ACCEPT

或者编辑配置文件:

vim /etc/sysconfig/iptables# 添加一条
-A INPUT -m tcp -p tcp --dport 8080 -j ACCEPT

4、保存配置

service iptables save

5、重启 iptables

systemctl restart iptables

以下是 iptables 的一些命令,停止/启动/重启 防火墙

# 使用 systemctl 操作
systemctl [stop|start|restart] iptables# 使用 service 操作
service iptables [stop|start|restart]

启动成功之后,查看 iptables 的运行状态,如果为 active 表示运行成功,为 inactive 则表示未启动:

[user@localhost home]$ systemctl status iptables● iptables.service - IPv4 firewall with iptablesLoaded: loaded (/usr/lib/systemd/system/iptables.service; enabled; vendor preset: disabled)Active: active (exited) since Tue 2022-03-01 16:12:22 CST; 14min agoProcess: 9061 ExecStop=/usr/libexec/iptables/iptables.init stop (code=exited, status=0/SUCCESS)Process: 9068 ExecStart=/usr/libexec/iptables/iptables.init start (code=exited, status=0/SUCCESS)Main PID: 9068 (code=exited, status=0/SUCCESS)Tasks: 0Memory: 0BCGroup: /system.slice/iptables.service

二、使用 firewalld 方式(推荐)


1、安装 firewalld如果没有安装的话

yum install firewalld

设置开机自动启动:

systemctl enable firewalld

3、启动 firewalld

systemctl start friewalld

如果之前启动了 iptables,可以按以下方式切换

# 关闭并屏蔽 iptables
systemctl stop iptables
systemctl mask iptables# 解除 firewalld 的屏蔽
systemctl unmask friewalld

启动成功之后,查看 firewalld 的运行状态,如果为 active 表示运行成功,为 inactive 则表示未启动:

[user@localhost home]$ systemctl status firewalld● firewalld.service - firewalld - dynamic firewall daemonLoaded: loaded (/usr/lib/systemd/system/firewalld.service; enabled; vendor preset: enabled)Active: active (running) since Tue 2022-03-01 16:40:53 CST; 4s agoDocs: man:firewalld(1)Main PID: 10206 (firewalld)Tasks: 2Memory: 30.0MCGroup: /system.slice/firewalld.service└─10206 /usr/bin/python2 -Es /usr/sbin/firewalld --nofork --nopid

4、开放 8080 端口

firewall-cmd --add-port=8080/tcp --permanent

5、重启 firewall

firewall-cmd --reload

PS:如果使用的是阿里云的ECS服务器,需要在服务器的安全组规则配置规则添加开放端口:

  • 端口范围为:8080/808
  • 授权对象为:0.0.0.0/0

firewalld 常用命令


查看防火墙状态:

systemctl status firewalld
firewall-cmd --state

开启、关闭、重启防火墙:

systemctl start|stop|restart firewalld

开启、关闭开机自动启动:

systemctl enable|disable firewalld

重新载入配置(比如添加规则之后,需要执行此命令):

firewall-cmd --reload

列出支持的 zone

firewall-cmd --get-zones

列出支持的服务:

firewall-cmd --get-services

查看 ftp 服务是否支持(返回 yes 或者 no):

firewall-cmd --query-service ftp

临时开放 ftp 服务:

firewall-cmd --add-service=ftp

永久开放 ftp 服务:

firewall-cmd --add-service=ftp --permanent

永久移除 ftp 服务:

firewall-cmd --remove-service=ftp --permanent

永久添加8080端口:

firewall-cmd --add-port=8080/tcp --permanent

永久移除8080端口:

firewall-cmd --remove-port=8080/tcp --permanent

查看开启的服务:

firewall-cmd --permanent --zone=public --list-services

查看已开发的端口:

firewall-cmd --permanent --zone=public --list-ports

查看端口是否生效:

firewall-cmd --zone=public --query-port=8080/tcp

【Linux】之对外开放端口相关推荐

  1. linux系统对外开放3306、8080等端口,防火墙设置

    我们很多时候在liunx系统上安装了web服务应用后(如tomcat.apache等),需要让其它电脑能访问到该应用,而linux系统(centos.redhat等)的防火墙是默认只对外开放了22端口 ...

  2. linux服务器3306端口,linux系统对外开放3306、8080等端口,防火墙设置详解

    linux系统对外开放3306.8080等端口,防火墙设置详解 发布时间:2020-10-10 23:08:49 来源:脚本之家 阅读:141 作者:julielele 栏目:服务器 我们很多时候在l ...

  3. linux开放外部端口访问

    前言 linux安装相关软件可能都需要允许外网访问,例如mysql.redis.kafka等,前些天一同事安装了mosquitto(Mqtt服务器),外网却无法访问,检查相关配置外还是不能访问.关于这 ...

  4. Linux Tomcat安装,Linux配置Tomcat,Linux Tomcat修改内存,Linux tomcat修改端口

    Linux Tomcat安装,Linux配置Tomcat,Linux Tomcat修改内存,Linux tomcat修改端口 >>>>>>>>>& ...

  5. linux攻击端口,Linux 常见攻击端口封杀表

    Linux常见攻击端口封杀表 # Vi /etc/sysconfig/iptables # INPUT -A INPUT -p tcp --dport 135 -j REJECT -A INPUT - ...

  6. linux修改ssh端口和禁止root远程登陆设置

    linux修改ssh端口22 vi /etc/ssh/ssh_config vi /etc/ssh/sshd_config 然后修改为port 8888 以root身份service sshd res ...

  7. Linux查看端口监听情况,以及Linux查看某个端口对应的进程号和程序

    文章目录: 1 linux查看那端口监听情况 2 Linux查看某个端口对应的进程号和程序 1 linux查看那端口监听情况 linux中可以使用netstat命令查看端口监听情况,首先来看一下该命令 ...

  8. 利用iptables来配置linux禁止所有端口登陆和开放指定端口

    原文地址:http://www.2cto.com/Article/201109/103089.html 利用iptables来配置linux禁止所有端口登陆和开放指定端口 1.关闭所有的 INPUT ...

  9. 查看ubuntu linux开放的端口以及控制端口范围

    在讨论这个问题前,我们先来了解一下物理端口.逻辑端口.端口号等计算机概念. 端口相关的概念: 在网络技术中,端口(Port)包括逻辑端口和物理端口两种类型.物理端口指的是物理存在的端口,如ADSL M ...

  10. linux查看主机端口进程命令

    linux查看主机端口进程命令 1.查看主机信息 #more /etc/hosts #Do not remove the following line, or various programs #th ...

最新文章

  1. 解决 Unable to get provider
  2. 如何在awk中引用外部变量
  3. cocos creator 游戏源码_Cocos Creator 3D引擎源码阅读之授之以渔 源码阅读
  4. Fix Missing Scripts
  5. 「镁客早报」韩国将支持数字加密货币的正常交易;今年智能手表出货量或达7100万部...
  6. 每日两SQL(10),欢迎交流~
  7. 三星s10能升级android11,三星 S10+手机已在测试 Android 11 系统
  8. mitmproxy抓包 | Python实时生成接口自动化用例(三)
  9. python判断某一天是周几
  10. 【原创】Oracle RAC原理和安装
  11. 三大运营商回复 4G 降速;微信上线语音转文字功能;IntelliJ IDEA 2019.2.1 发布 | 极客头条...
  12. eclipse在线安装ivy和ivyde
  13. VISTA系统下装AUTOCAD 2006
  14. 【Linux】修改权限命令chmod用法示例
  15. livereload(自动刷新)
  16. qq互联代码 php,请教QQ互联的代码是如何写的?
  17. 人物回眸效果怎么用Vegas设置
  18. android 投屏 车载,车载投屏怎么连接
  19. org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':app:processDebugManifest
  20. 计算机毕业设计Java-超市会员积分管理系统-(源码+系统+mysql数据库+lw文档)

热门文章

  1. 软碟通UltraISO 9.65.3237官方注册版
  2. 桌面上IE图标不见了怎么办?
  3. AutoCAD2019+vs2019+C# 二次开发学习笔记day05(持续更新)
  4. 手把手教你在windows下源码编译Open3D
  5. 从FrozenUI中学习移动端屏幕适配问题
  6. Simplify and Robustify Negative Sampling for Implicit Collaborative Filtering (Nips‘20) 论文小结
  7. 医院信息系统 php,php医院门诊信息管理系统
  8. 第9章 maven的插件和生命周期
  9. 初学者,简单易用的猎码安卓中文编程开发工具!
  10. 哪边是上游、哪边是下游