首页
文章
登录
登录
注册
忘记密码
反馈
iptables
lyj
Published 2023-03-16
570
分享
# iptables >iptables/ip6tables命令,用于在Linux内核中设置、维护和检查IPv4和IPv6数据包过滤规则的表,从而实现IPv4/IPv6数据包过滤和NAT的管理工具。它可以定义多个不同的表,每个表中包含多个预定义的链,也可能包含用户自定义的链。每个链都是一个规则列表,用来匹配一组数据包,每个规则都指定如何处理匹配到的数据包,也被称为“目标”,它可能是跳转到同一个表中用户自定义的链。 ## 查看端口占用情况 ```shell netstat -luntp ```  ## 显示iptable规则(可显示规则序号,用户删除规则) ```shell iptables -L -n --line-numbers ```  ## 开放指定端口: ```shell iptables -A INPUT -p tcp --dport 22 -j ACCEPT ``` ## 禁止指定端口: ```shell iptables -A INPUT -p tcp --dport 22 -j DROP ``` ## 指定端口不允许外部方位,只允许127.0.0.1访问(比如nginx内部代理服务) ```shell # 以端口2048为例子,首先设置可以内部访问: iptables -A INPUT -s 127.0.0.1 -d 127.0.0.1 -p tcp --dport 2048 -j ACCEPT # 再设置全部不可访问 iptables -A INPUT -p tcp --dport 2048 -j DROP ``` ## 清除单条iptables规则 ``` sudo iptables -D INPUT(链) 3(规则对应的序号) ``` ## 禁用所有,使配置的规则失效 ``` iptables -P INPUT DROP ``` ## 启用配置的规则 ``` iptables -P INPUT ACCEPT ```
分享
Share this article
关闭
Scan the QR code on your device to read or share instantly.
Copy
Use the link above to share with your team or friends.
暂无评论
请登录后评论
新评论
删除
关闭
提交