小知识:linux iptables防火墙中的工作常用命令

linux iptables防火墙-工作常用命令

Linux之iptables防火墙基础

[推荐]Linux之iptables防火墙

 

linux系统的防火墙:IP信息包过滤u系统,它实际上由两个组件netfilter和iptables组成。

主要工作在网络层,针对IP数据包,体现在对包内的IP地址、端口、协议等信息的处理上。

数据包到达防火墙时,规则表之间的优先顺序: 首先过滤raw表里面的规则其次依次过滤> mangle > nat > filter如果所有表都没有匹配到则表示放空

%小知识:linux iptables防火墙中的工作常用命令-猿站网-插图

入站数据(来自外界的数据包,且目标地址是防火墙本机) : PREROUTING –> INPUT –> 本机的应用程序 出站数据(从防火墙本机向外部地址发送的数据包) :本机的应用程序–> OUTPUT –> POSTROUTING 网络型防火墙 转发数据(需要经过防火墙转发的数据包) : PREROUTING –> FORWARD –> POSTROUTING

iptables命令行配置方法

iptables [-t 表明] 管理选项 [链名] [匹配条件] [-j 控制类型]

%小知识:linux iptables防火墙中的工作常用命令-1猿站网-插图

查看iptables防火墙规则

iptables -nvL –line-number

-L 查看当前表的所有规则,默认查看的是filter表,如果要查看NAT表,可以加上-t NAT参数

-n 不对ip地址进行反查,加上这个参数显示速度会快很多

-v 输出详细信息,包含通过该规则的数据包数量,总字节数及相应的网络接口

–-line-number 显示规则的序列号,这个参数在删除或修改规则时会用到

关闭某个端口(注意同时添加ip或接口的限制)iptables 配置只能本地ip访问某端口

iptables -I INPUT -p tcp –dport 9527 -j DROP

ip6tables -I INPUT -p tcp –dport 9527 -j DROP

注意:工作中切记不要直接使用上面命令,除非在这个命令之前还有一条放过lo接口的防火墙规则。

一般情况,我们目的都是某个端口不让外网访问,这样操作,就127.0.0.1访问这个端口也被限制了。

一定要记得,添加ip或接口的条件~

例如:
iptables -I INPUT ! -i lo -p tcp –dport 9527 -j DROP ip6tables -I INPUT ! -i lo -p tcp –dport 9527 -j DROP

iptables -I INPUT ! -d 127.0.0.1 -p tcp –dport 9527 -j DROP

iptables 是控制ipv4的,ip6tables 是控制ipv6的

注意 感叹号的位置,亲测可用.~

防火墙规则放开自己的ip,让自己的ip可以访问

iptables -I INPUT -p tcp -s 192.168.11.1 -j ACCEPT

开放某个tcp、某个udp。

iptables -I INPUT -p tcp –dport 9527 -j ACCEPT iptables -I INPUT -p tcp –dport 9527 -j ACCEPT

iptables永久生效

第一种方法

执行命令service iptables save

第二种方法

执行命令iptables-save > xxx写入到一个文件,开机以后执行命令iptables-restore < xxx用来恢复。 报错:The service command supports only basic LSB actions (start, stop, restart, try-restart, reload, force-reload, status). For other actions, please try to use systemctl.

问题描述:

执行命令service iptables save 报错The service command supports only basic LSB actions (start, stop, restart, try-restart, reload, force-reload, status). For other actions, please try to use systemctl.

问题分析:

The service command supports only basic LSB actions (start, stop, restart, try-restart, reload, force-reload, status). For other actions, please try to use systemctl.

服务命令只支持基本的LSB操作(启动、停止、重启、尝试重启、重载、强制重载、状态)。对于其他操作,请尝试使用systemctl。

centos新版本,firewalld 被引入代替 iptables 了,所以再使用 service iptables save 保存 iptables 规则时,就会出现上述的报错。

service命令只保留下了极少部分使用,大部分命令都要改用systemctl使用。

这是因为没有安装iptables服务,直接使用yum安装iptables服务即可.

解决方法:

1.systemctl stop firewalld –关闭防火墙

2.yum install iptables-services –安装或更新服务
yum install iptables-services

3.systemctl enable iptables –允许开机启动iptables

4.systemctl start iptables –启动iptables

5.service iptables save –保存设置

6.service iptables restart –重启iptables服务:

到此这篇关于linux iptables防火墙-工作常用命令的文章就介绍到这了,更多相关linux iptables命令内容请搜索服务器之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持服务器之家!

原文地址:https://blog.csdn.net/inthat/article/details/127394548

声明: 猿站网有关资源均来自网络搜集与网友提供,任何涉及商业盈利目的的均不得使用,否则产生的一切后果将由您自己承担! 本平台资源仅供个人学习交流、测试使用 所有内容请在下载后24小时内删除,制止非法恶意传播,不对任何下载或转载者造成的危害负任何法律责任!也请大家支持、购置正版! 。本站一律禁止以任何方式发布或转载任何违法的相关信息访客发现请向站长举报,会员发帖仅代表会员个人观点,并不代表本站赞同其观点和对其真实性负责。本网站的资源部分来源于网络,如有侵权烦请发送邮件至:2697268773@qq.com进行处理。
建站知识

小知识:Apache网页的优化、安全与防盗链图文详解

2023-3-5 15:23:13

建站知识

小知识:浅谈云服务器中安全组和云防火墙的区别

2023-3-5 15:27:04

0 条回复 A文章作者 M管理员
    暂无讨论,说说你的看法吧
个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
搜索