首页 > 系统相关 >Linux防火墙firewalld&iptables(2)iptables开放指定端口开放指定端口

Linux防火墙firewalld&iptables(2)iptables开放指定端口开放指定端口

时间:2023-08-08 15:57:34浏览次数:39  
标签:iptables service -- 端口 指定 tcp 防火墙

一、CentOs6 iptables基本操作

# chkconfig --list | grep iptables	查看防火墙的服务
# chkconfig iptables off	永久关闭防火墙
#chkconfig iptables on	永久开启防火墙

# service status iptables 	查看防火墙状态
# service start iptables		启动防火墙
# service stop iptables		停止防火墙
# service restart iptables	重启防火墙

# /etc/init.d/iptables status		查看防火墙状态
# /etc/init.d/iptables start		启动防火墙
# /etc/init.d/iptables stop		停止防火墙
# /etc/init.d/iptables restart	重启防火墙

二、CentOs7 iptables基本操作

## 2.1 防火墙服务

#chkconfig --list | grep iptables	查看防火墙的服务
#chkconfig iptables off	永久关闭防火墙
#chkconfig iptables on	永久开启防火墙

## 2.2 systemctl基本命令

#systemctl status iptables.service	查看防火墙的状态
#systemctl stop iptables.service	停止防火墙
#systemctl start iptables.service	启动防火墙
#systemctl restart iptables.service	重启防火墙
#systemctl reload iptables.service	重载防火墙等价于restart
#systemctl disable iptables.service	禁止开机启动防火墙
#systemctl enable iptables.service	开机启动防火墙

## 2.3 service基本命令

#service iptables status    查看防火墙状态        
#service iptables start	启动防火墙
#service iptables stop	停止防火墙
#service iptables restart	重启防火墙
#service iptables try-restart	尝试重启防火墙
#service iptables reload	重载防火墙
#service iptables force-reload	强制重载防火墙

三、防火墙端口(开放/阻止)

3.1 查询防火墙开放端口

iptables -L -n
或
iptables -L -n --line-number

3.2 开放防火墙指定端口
3.2.1 允许所有服务器访问指定端口
例如放开常用端口22/80/8080/3306

iptables -A INPUT -p tcp -m state --state NEW -m tcp --dport 22 -j ACCEPT
iptables -A INPUT -p tcp -m state --state NEW -m tcp --dport 80 -j ACCEPT
iptables -A INPUT -p tcp -m state --state NEW -m tcp --dport 8080 -j ACCEPT
iptables -A INPUT -p tcp -m state --state NEW -m tcp --dport 3306 -j ACCEPT

–参数说明

参数 说明
-A 添加一条INPUT的规则
-p 指定是什么协议(TCP/UDP)
--dport 就是目标端口,当数据从外部进入服务器为目标端口
--sport 数据从服务器出去,则为数据原端口
-j 就是指定是ACCEPT接受或阻止DROP
-s 来源
重启服务
service iptables restart
或
systemctl restart iptables.service

保存配置

service iptables save
或
/etc/rc.d/init.d/iptables save

3.2.2 防火墙指定IP(允许/禁止)访问

# 允许ip访问
iptables -A INPUT -p tcp -s 192.168.xx.x -j ACCEPT
# 禁止ip访问
iptables -A INPUT -p tcp -s 192.168.xx.x -j DROP

–参数说明: -s 来源

3.2.3 防火墙指定IP(允许/禁止)访问指定端口

# 允许访问3306
iptables -A INPUT -s 192.168.xx.x -p tcp -m tcp --dport 3306 -j ACCEPT
# 禁止访问3306
iptables -A OUTPUT -s 192.168.xx.x -p tcp -m tcp --sport 3306 -j DROP

重启服务

service iptables restart
或
systemctl restart iptables.service

保存配置

service iptables save
或
/etc/rc.d/init.d/iptables save

四、删除防火墙端口

先查看防火墙端口规则

iptables -L -n
或
iptables -L -n --line-number

再根据序号删除指定端口的防火墙规则

iptables -D INPUT 1
iptables -D INPUT 2
iptables -D INPUT 3
iptables -D INPUT 4

标签:iptables,service,--,端口,指定,tcp,防火墙
From: https://www.cnblogs.com/muzlei/p/17614573.html

相关文章

  • DataFrame 指定某列的格式
    importpandasaspd#创建示例DataFramedata={'Name':['Alice','Bob','Charlie'],'Age':[25.0,30.0,35.0]#注意:这里的年龄列是浮点数类型}df=pd.DataFrame(data)#将'Age'列的数据类型设置为整数df['......
  • 常用服务器端口有哪些,安全性怎么样
    常用的服务器端口主要用于各种网络服务和应用程序。以下是一些常见的服务器端口及其对应的服务:80-HTTP:用于常规的网页浏览,是网站访问的默认端口。443-HTTPS:用于加密的网页浏览,提供更安全的数据传输。21-FTP:用于文件传输协议,用于上传和下载文件。22-SSH:用于安全外部访问服务......
  • 端口映射软件可以做什么? 快解析如何设置端口映射?
    说到端口映射,首先说说nat。简单地说,nat就是在局域网内部网络中使用内部地址,而当内部节点要与外部网络进行通讯时,就在网关处,将内部地址替换成公用地址,从而在外部公网(internet)上正常使用,nat可以使多台计算机共享Internet连接,这一功能很好地解决了公共IP地址紧缺的问题。通过这种方法......
  • Rinetd——端口转发工具
    前言iptables的功能当然强大,但理解与设置却有点抽象,便通过google认识了rinetd。简介Rinetd是为在一个Unix和Linux操作系统中为重定向传输控制协议(TCP)连接的一个工具。Rinetd是单一过程的服务器,它处理任何数量的连接到在配置文件etc/rinetd中指定的地址/端口对。尽管rinetd......
  • SpringBoot配置文件和修改端口
    我们在上一篇文章中已经运行起了一个简单的基础项目并运行起来了。SpringBoot简介项目创建和运行使用但是我们发现简单版的SpringBoot项目没有配置文件,定制版的项目有一个配置文件application.properties,我们还可以发现有些SpringBoot的项目使用的是xml或者yml配置文件。那么......
  • CentOS 查询端口占用情况
    使用netstat命令:netstat-tuln|grep<端口号>将<端口号>替换为你要查询的端口号。例如,如果你要查询端口80的占用情况,可以输入:netstat-tuln|grep80上述命令将列出所有占用端口80的进程和其PID。使用lsof命令:lsof-i:<端口号>将<端口号>替换为你要查询的端......
  • 七月学习之Iptables地址转换
    8、Iptables地址转换8.1、什么是NAT网络地址转换(NAT),意思也比较清楚:对(数据包)的网络地址(IP+PORT)进行转换例如,机器自己的IP10.1.1.2是能与外部正常通信的,但是192.168网段是私有IP段。无法与外界通信因此当源地址为192.168网段的包要出去时,机器会先将源IP换成机器自己的10.......
  • 在docker中创建指定版本的jenkins
     dockerrun-it-d-p8082:8080-p50000:50000 --namemyjenkins01jenkins/jenkins:2.417 以下是对给定的命令参数的解释:dockerrun:运行一个新的容器-it:在一个交互式终端中运行容器-d:在后台运行容器-p8082:8080:将容器的8080端口映射到主机的8082端口......
  • Linux:防火墙iptables与firewalld的启停
    Linux关闭防火墙firewall和iptables命令_永久关闭iptables防火墙_红烧柯基的博客-CSDN博客Linux防火墙——iptables以及firewalld的使用介绍_树下一少年的博客-CSDN博客干货!Linux防火墙配置(iptables和firewalld)_数据包_规则_进行 iptables与firewalld1、状态syste......
  • 如何查看容器端口到宿主机端口的映射关系?
    使用dockerport命令进行查看 #查看容器的ID[root@nccztsjb-node-27~]#dockerps|grepnginx78e7140c0b8cgoharbor/nginx-photon:v2.6.1"nginx-g'daemonof…"2monthsagoUp2months(healthy)0.0.0.0:80->8080/tcp,:::80->......