首页 > 系统相关 >linux防火墙管理

linux防火墙管理

时间:2023-03-03 17:47:16浏览次数:40  
标签:iptables service 管理 端口 防火墙 tcp firewalld linux

安装systemctl:
yum install iptables-services

设置开机启动
systemctl enable iptables.service

如果报错:Failed to start IPv4 firewall with iptables.

因为centos7默认的防火墙是firewalld防火墙,不是使用iptables,因此需要先关闭firewalld服务,或者干脆使用默认的firewalld防火墙。
关闭firewalld:
systemctl stop firewalld  
systemctl mask firewalld

开启443端口
iptables -A INPUT -p tcp --dport 443 -j ACCEPT

保存规则
service iptables save

开启服务
systemctl restart iptables.service

 

防火墙常规操作:

1、 重启后永久性生效:
开启:chkconfig iptables on
关闭:chkconfig iptables off

2、 即时生效,重启后失效:
开启:service iptables start
关闭:service iptables stop

3、Linux 防火墙开放特定端口
iptables是linux下的防火墙,同时也是服务名称。
service iptables status 查看防火墙状态
service iptables start 开启防火墙
service iptables stop 关闭防火墙
service iptables restart 重启防火墙

防火墙开放特定端口:
1.文件/etc/sysconfig/iptables
2.添加:
-A RH-Firewall-1-INPUT -m state –state NEW -m tcp -p tcp –dport 3306 -j ACCEPT
 ★具体参照/etc/sysconfig/iptables中的配置,一般默认会有一个22端口开放★
★数字3306代表开放3306端口,也可以改成其他的端口.★

3.重启防火墙
service iptables restart

4.保存对防火墙的设置
serivce iptables save 

5.查看iptables规则及编号
iptables -nL –line-number 

6.查看iptables规则及编号
iptables -nL –line-number 

7.关闭所有的INPUT FORWARD(转发) OUTPUT的所有端口 
iptables -P INPUT DROP
iptables -P FORWARD DROP
iptables -P OUTPUT DROP 

8.只打开22端口
iptables -A INPUT -p tcp –dport 22 -j ACCEPT
iptables -A OUTPUT -p tcp –sport 22 -j ACCEPT
参数讲解:
–A 参数就看成是添加一条规则
–p 指定是什么协议,我们常用的tcp 协议,当然也有udp,例如53端口的DNS
–dport 就是目标端口,当数据从外部进入服务器为目标端口
–sport 数据从服务器出去,则为数据源端口使用
–j 就是指定是 ACCEPT -接收 或者 DROP 不接收

9.禁止某个IP访问
iptables -A INPUT -p tcp -s 192.168.1.2 -j DROP

标签:iptables,service,管理,端口,防火墙,tcp,firewalld,linux
From: https://www.cnblogs.com/brad93/p/17176434.html

相关文章

  • 【mysql】Linux下定时备份数据shell脚本
    mysql_full_bak.sh#!/bin/bash#全量备份(建议一周一次)#时间参数DATE=$(date+%Y-%m-%d)DATETIME=$(date+%Y%m%d%H%M%S)#数据库的地址HOST=localhost#数据库的......
  • Rancher 使用介绍(可以通过界面管理 K8s 平台)
    参考链接https://blog.csdn.net/weixin_46902396/article/details/122433622https://www.hugedomains.com/domain_profile.cfm?d=kukasoft.comhttps://ranchermanager.d......
  • linux上文件复制的python代码实现3.py
    每次都需要打开代码修改要复制的文件路径台麻烦,所以改用位置参数#文件的复制3.pyimportsysdefcopy(source,destination): file_read1=open(source,mode="rb") file_......
  • Linux时钟子系统分析
    梦开始的地方X86硬件时钟首先我们需要了解一下,目前有哪些时钟PITpit是最古老的pc时钟设备。Intel8253/8254PIT是具有3个16位计数器通道的可编程计数/定时器芯片,晶振......
  • Linux系列---【设置ssh连接超时时间】
    设置ssh连接超时时间shell工具总是不断的超时,上个厕所就断开了,很不方便,这里根据自己习惯设置一下。echo"exportTMOUT=600">>/etc/profile&&source/etc/profile......
  • Linux文件删除,但是磁盘空间没有释放
    Linux文件删除,但是df之后磁盘空间没有释放问题:Linux磁盘空间总是报警,查到大文件,删除之后,df看到磁盘空间并没有释放。查找了下发现系统对rm进行了alias,因为Linux对删除操......
  • Linux下 Jdk版本切换
    安装:甲骨文官网下jdk上传到云服务器解压:tar-zxvfjdk-7u79-linux-x64.tar.gz设置环境变量vim/etc/profile末尾加上exportJAVA_HOME=/usr/local/jdk1.8.0_351ex......
  • lazarus linux使用StringGrid和DBGrid等控件时,如果内容包含#13时会出现乱码
    lazaruslinux使用StringGrid和DBGrid等控件时,如果单元格内容包含#13时会显示乱码.  修改/lazarus/lcl/interfaces/gtk2/gtk2devicecontext.inc行1303行开始的:proc......
  • Linux系统安全:SNAT和DNAT的实现
    一、SNAT1、SNAT实验目的公司内有2台机器,但是只有一个公网ip,利用SNAT技术实现2台私网地址都可以访问公网。2、SNAT实验环境准备①三台服务器:PC1客户端、PC2网关、PC3服务......
  • Linux修改主机名
    Linux安装的时候一般都是使用默认的主机名。一般的主机名为localhost.localdomain。不同的操作系统使用的默认名字不同。 为什么需要修改主机名呢?答案是您无......