iptables的50条常用命令

iptables的50条常用命令:

  1. 查看当前防火墙规则:
    iptables -L

  2. 清空所有防火墙规则:
    iptables -F

  3. 允许所有本地回环接口的访问:
    iptables -A INPUT -i lo -j ACCEPT

  4. 允许已建立的连接进入:
    iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT

  5. 允许指定IP地址的访问:
    iptables -A INPUT -s 192.168.0.10 -j ACCEPT

  6. 允许指定IP地址范围的访问:
    iptables -A INPUT -m iprange --src-range 192.168.0.1-192.168.0.100 -j ACCEPT

  7. 允许指定端口的访问:
    iptables -A INPUT -p tcp --dport 80 -j ACCEPT

  8. 允许指定协议的访问:
    iptables -A INPUT -p icmp -j ACCEPT

  9. 拒绝所有未匹配规则的访问:
    iptables -A INPUT -j REJECT

  10. 允许特定MAC地址的访问:
    iptables -A INPUT -m mac --mac-source 00:11:22:33:44:55 -j ACCEPT

  11. 允许某个网卡的访问:
    iptables -A INPUT -i eth0 -j ACCEPT

  12. 允许某个端口的出站连接:
    iptables -A OUTPUT -p tcp --dport 22 -j ACCEPT

  13. 允许某个IP地址的出站连接:
    iptables -A OUTPUT -d 192.168.0.10 -j ACCEPT

  14. 允许特定协议的出站连接:
    iptables -A OUTPUT -p icmp -j ACCEPT

  15. 允许所有本地回环接口的出站连接:
    iptables -A OUTPUT -o lo -j ACCEPT

  16. 拒绝所有出站连接:
    iptables -A OUTPUT -j REJECT

  17. 允许某个端口的转发:
    iptables -A FORWARD -p tcp --dport 80 -j ACCEPT

  18. 允许某个IP地址的转发:
    iptables -A FORWARD -d 192.168.0.10 -j ACCEPT

  19. 允许特定协议的转发:
    iptables -A FORWARD -p icmp -j ACCEPT

  20. 拒绝所有转发连接:
    iptables -A FORWARD -j REJECT

  21. 开启SNAT:
    iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE

  22. 开启DNAT:
    iptables -t nat -A PREROUTING -p tcp --dport 80 -j DNAT --to-destination 192.168.0.10:80

  23. 删除指定规则:
    iptables -D INPUT 5

  24. 允许某个端口的限速:
    iptables -A INPUT -p tcp --dport 80 -m limit --limit 100/s -j ACCEPT

  25. 将防火墙规则保存到文件:
    iptables-save > /etc/iptables/rules.v4

  26. 从文件加载防火墙规则:
    iptables-restore < /etc/iptables/rules.v4

  27. 开启SYN洪水攻击防御:
    iptables -A INPUT -p tcp --syn -m limit --limit 1/s -j ACCEPT

  28. 允许ICMP回应包通过:
    iptables -A INPUT -p icmp --icmp-type echo-reply -j ACCEPT

  29. 允许Ping请求通过:
    iptables -A INPUT -p icmp --icmp-type echo-request -j ACCEPT

  30. 拒绝Ping请求:
    iptables -A INPUT -p icmp --icmp-type echo-request -j REJECT

  31. 允许指定源端口的访问:
    iptables -A INPUT -p tcp --sport 1024:65535 -j ACCEPT

  32. 允许指定目标端口的访问:
    iptables -A INPUT -p tcp --dport 1024:65535 -j ACCEPT

  33. 拒绝所有ICMP协议的报文:
    iptables -A INPUT -p icmp -j DROP

  34. 允许特定用户的访问:
    iptables -A OUTPUT -m owner --uid-owner username -j ACCEPT

  35. 允许指定IP地址的多个端口访问:
    iptables -A INPUT -s 192.168.0.10 -p tcp -m multiport --dports 80,443 -j ACCEPT

  36. 拒绝特定IP地址的访问:
    iptables -A INPUT -s 192.168.0.10 -j DROP

  37. 允许指定IP地址的SSH登录:
    iptables -A INPUT -s 192.168.0.10 -p tcp --dport 22 -j ACCEPT

  38. 拒绝特定IP地址的SSH登录:
    iptables -A INPUT -s 192.168.0.10 -p tcp --dport 22 -j REJECT

  39. 允许指定端口的UDP访问:
    iptables -A INPUT -p udp --dport 53 -j ACCEPT

  40. 允许指定端口范围的UDP访问:
    iptables -A INPUT -p udp --dport 60000:61000 -j ACCEPT

  41. 允许指定协议类型和端口的访问:
    iptables -A INPUT -p 50 -j ACCEPT

  42. 允许指定协议类型和端口范围的访问:
    iptables -A INPUT -p tcp --dport 10000:20000 -j ACCEPT

  43. 阻止指定协议类型和端口的访问:
    iptables -A INPUT -p tcp --dport 23 -j DROP

  44. 允许输入端口多于等于80的TCP数据包通过:
    iptables -A INPUT -p tcp --dport 80 -j ACCEPT

  45. 阻止目标地址为192.168.0.2的数据包通过:
    iptables -A FORWARD -d 192.168.0.2 -j DROP

  46. 开启对外ping功能:
    iptables -I INPUT -p icmp --icmp-type echo-request -j ACCEPT

  47. 阻止192.168.0.0/24网段的IP访问本机的80端口:
    iptables -I INPUT -s 192.168.0.0/24 -p tcp --dport 80 -j DROP

  48. 允许某个地址段对本机进行SSH登录:
    iptables -I INPUT -s 192.168.0.0/24 -p tcp --dport 22 -j ACCEPT

  49. 清除某个链的所有规则:
    iptables -F chain_name

  50. 拒绝特定IP地址范围的访问:
    iptables -A INPUT -m iprange --src-range 192.168.0.1-192.168.0.100 -j REJECT

请注意,对于实际使用中的防火墙配置需根据具体的网络环境和安全需求做出调整。

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

hhb_618

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值