iptables配置实例

2023-05-16

查看当前所有规则

iptables -L -n 查看所有规则
iptables -nL --line-number 显示行
iptables -nvL --line-number 显示行

清空所有配置

iptables -F
iptables -X
iptables -Z

允许ssh端口及lookback规则

iptables -A INPUT -i lo -j ACCEPT
iptables -A OUTPUT -o lo -j ACCEPT
iptables -A INPUT -p tcp --dport 22 -j ACCEPT

拒绝所有数据,只允许流出数据

iptables --policy OUTPUT ACCEPT
iptables --policy FORWARD DROP
iptables -P INPUT DROP

对所有开放80端口

iptables -A INPUT -p tcp --dport 80 -j ACCEPT

单独对某个ip开放80端口

iptables -A INPUT -s 172.16.21.1 -p tcp --dport 80 -j ACCEPT

多端口开放

iptables -A INPUT -s 172.16.0.0/24 -p tcp -m multiport --dport 8080,8081,8082 -j ACCEPT

禁止ping

iptables -A INPUT -p icmp –icmp-type 8 -s 0/0 -j DROP
iptables -A INPUT -p icmp --icmp-type 8 -s 172.21.3.18 -j ACCEPT

开放SNMP协议

iptables -A INPUT -s 192.168.2.0/24 -p udp –dport 161 -j ACCEPT

开放关联规则包(配置完成所有规则,后增加这条)

iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -A OUTPUT -m state --state ESTABLISHED,RELATED -j ACCEPT

保存所有规则与重启iptables

/etc/init.d/iptables save
/etc/init.d/iptables restart

插入规则

iptables -A INPUT -s 192.168.1.5 -j DROP    尾部添加拒绝IP
iptables -I INPUT 3 -s 192.168.1.5 -j DROP  插入这条规则到第3行

删除某条规则

iptables -D INPUT -p icmp –icmp-type 8 -s 192.168.3.0/24 -j DROP   删除这条规
iptables -D INPUT 3      删除规则3
iptables -D INPUT -p icmp –icmp-type 8 -s 192.168.3.0/24 -j DROP 删除这条规则
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

iptables配置实例 的相关文章

随机推荐

  • 什么是实时数据库?

    实时数据库是数据库系统发展的一个分支 xff0c 它适用于处理不断更新的快速变化的数据及具有时间 限制的事务处理 实时数据库技术是实时系统和数据库技术相结合的产物 xff0c 研究人员希望利用数据库 技术来解决实时系统中的数据管理问题 xf
  • 带你阅读linux内核源码:linux内核源代码编程规范

    linux内核代码是许许多多遵循相同内核开发规范的牛人们的共同的创造的结晶 作为一名linux内核或者驱动开发工程师 xff0c 很有必要了解这些内核开发规范 好处有以下几个 xff1a 这些约定或者规范对我们阅读linux内核源码 了解设
  • linux进程上下文、中断上下文介绍,以及为什么软中断不能睡眠?

    linux内核的软中断处理程序中能不能睡眠 xff1f 这是一个值得讨论的问题 答案其实很简单 xff0c 那就是不能 因为Linux的软中断处理程序的运行上下文有可能是中断上下文 xff08 注意此处是有可能 xff0c 而并非一定 xf
  • VS2008用devenv.com命令行工具自动编译工程

    转自 xff1a http www cr173 com html 18500 1 html 在vs2008下面提供了devenv com命令行方式 我们可以从VS安装目录 MicrosoftVisual Studio 9 Common7 I
  • 使用ICMP协议检测网络状态

    ICMP xff08 Internet ControlMessages Protocol xff0c 网间控制报文协议 xff09 是TCP IP协议族的子协议 xff0c 是一种面向无连接的协议 xff0c 在IP和路由器之前传递控制消息
  • c++打印enum class

    span class token keyword enum span span class token keyword class span span class token class name A span span class tok
  • 使用strace查找Emacs启动阻塞的原因(exec-path-from-shell)

    原文地址 https www lujun9972 win blog 2019 09 26 使用strace查找emacs启动阻塞的原因 exec path from shell index html 之前就觉得我的Emacs启动好慢 xff
  • 为Linux安装虚拟PDF打印机

    原文地址 https lujun9972 github io blog 2020 04 11 为linux安装虚拟pdf打印机 index html 今天发现一个 CUPS PDF 项目 可以为 CUPS Common Unix Print
  • ubuntu系统启用shell远程登陆

    Ubuntu desktop系统安装后 xff0c 想使用shell远程登陆 xff0c 会提示 Connecting to 192 168 220 133 22 Could not connect to 39 192 168 220 13
  • 枚举类(ENUM)用法总结

    对于ENUM一直是比较陌生的 xff0c 在和某酷爱ENUM的大神合作时 xff0c 才慢慢接触到ENUM的用法 1 ENUM是什么 xff1f 首先ENUM是一个类 xff0c 不像String int之类的数据结构 xff0c 更类似于
  • Python循环结构练习2

    Problem A xff1a 循环结构 输出数列2 xff0c 5 xff0c 8 xff0c 11 xff0c 14 题目描述 输入正整数n xff08 n 100 xff09 xff0c 输出数列2 xff0c 5 xff0c 8 x
  • KVM网络模型之:PCI Passthrough

    目录 PCI Passthrough技术介绍和KVM中配置 案例 内核启用 重新启动虚拟机实例 PCI Passthrough技术介绍和KVM中配置 PCI Passthrough技术是虚拟化网卡的终极解决方案 xff0c 能够让虚拟机独占
  • 微信开放公众平台,扩展自定义类,定时提醒,定时发消息

    微信开放公众平台 xff0c 扩展自定义类 xff0c 定时提醒 xff0c 定时发消息 lt php class MyapiAction extends BaseAction public function index 微医疗 预约提醒
  • Ubuntu配置iptables规则

    Ubuntu配置防火墙 xff0c 并且开机iptables自启动规则 适用于CentOS 1 登录root账号 span class token comment 切换到root账号 span super 64 super span cla
  • Linux记录用户执行命令

    span class token shebang important bin bash span span class token comment By lumia98 64 vip qq com span span class token
  • Nginx规则配置实例

    配置某个ip或者页面禁止访问及跳转方法 server listen 80 server name www test com cn location proxy redirect off proxy set header host host
  • Debian 11.2安装ssh服务

    切换到root用户 更新软件源 span class token function apt get span update 安装ssh span class token function apt get span span class to
  • Python计算文件大小

    span class token comment usr bin env python span span class token comment coding utf 8 span span class token triple quot
  • Python获取文件内的下一行数据

    span class token comment usr bin env python span span class token comment Version 61 3 8 1 span span class token comment
  • iptables配置实例

    查看当前所有规则 iptables L n 查看所有规则 iptables nL line number 显示行 iptables nvL line number 显示行 清空所有配置 iptables F iptables X iptab