linux防火墙-iptables(上)

本文涉及的产品
云防火墙,500元 1000GB
简介:

FILTER表:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
[root@server01 ~] # iptables -t filter -nvL ##查看filter表,主要用于过滤包
Chain INPUT (policy ACCEPT 0 packets, 0 bytes)
  pkts bytes target  prot opt  in  out   source     destination
   116  8692 ACCEPT  all  --  *    *  0.0.0.0 /0  0.0.0.0 /0  state RELATED,ESTABLISHED
     0     0 ACCEPT  icmp --  *    *  0.0.0.0 /0  0.0.0.0 /0
     0     0 ACCEPT  all  --  lo   *  0.0.0.0 /0  0.0.0.0 /0
     0     0 ACCEPT  tcp  --  *    *  0.0.0.0 /0  0.0.0.0 /0  state NEW tcp dpt:22
     4   478 REJECT  all  --  *    *  0.0.0.0 /0  0.0.0.0 /0  reject-with icmp-host-prohibited
 
Chain FORWARD (policy ACCEPT 0 packets, 0 bytes)
  pkts bytes target  prot opt  in  out  source     destination
     0     0 REJECT  all  --  *    * 0.0.0.0 /0  0.0.0.0 /0   reject-with icmp-host-prohibited
 
Chain OUTPUT (policy ACCEPT 68 packets, 9944 bytes)
  pkts bytes target     prot opt  in      out      source                destination
[root@server01 ~] # iptables -Z  ##清零计数器
[root@server01 ~] # iptables -nvL --line-numbers ##显示行号
Chain INPUT (policy ACCEPT 0 packets, 0 bytes)
num  pkts bytes target  prot opt  in   out  source      destination
1       6  432  ACCEPT  all  --  *   *   0.0.0.0 /0   0.0.0.0 /0   state RELATED,ESTABLISHED
2       0     0 ACCEPT  icmp --  *   *   0.0.0.0 /0   0.0.0.0 /0
......
  [root@server01 ~] # iptables -F  ##清空规则
[root@server01 ~] # iptables -nvL ##查看iptables规则
Chain INPUT (policy ACCEPT 6 packets, 432 bytes)
  pkts bytes target     prot opt  in      out      source                destination 
 
Chain FORWARD (policy ACCEPT 0 packets, 0 bytes)
  pkts bytes target     prot opt  in      out      source                destination 
 
Chain OUTPUT (policy ACCEPT 4 packets, 448 bytes)
  pkts bytes target     prot opt  in      out      source                destination 
[root@server01 ~] # service iptables save  ##保存规则
iptables: Saving firewall rules to  /etc/sysconfig/iptables :[  确定  ]
 
##三种动作:DROP、REJECT、ACCEPT,链默认规则是ACCEPT。
[root@server01 ~] # iptables -A INPUT -s 192.168.111.1 -p tcp --sport 1234 -d 192.168.137.100 --dport 80 -j DROP  ##在下面增加
[root@server01 ~] # iptables -I INPUT -s 192.168.111.2 -p tcp --sport 1234 -d 192.168.137.100 --dport 80 -j DROP  ##在上面增加
[root@server01 ~] # iptables -nvL
Chain INPUT (policy ACCEPT 0 packets, 0 bytes)
  pkts bytes target prot opt  in  out  source          destination
     0     0 DROP   tcp  --  *    * 192.168.111.2  192.168.137.100  tcp spt:1234 dpt:80
     ......
     0     0 DROP   tcp  --  *    *  192.168.111.1 192.168.137.100  tcp spt:1234 dpt:80
[root@server01 ~] # iptables -D INPUT 1  ##删除INPUT第一行
[root@server01 ~] # iptables -nvL --line-numbers
Chain INPUT (policy ACCEPT 0 packets, 0 bytes)
num   pkts bytes target prot opt  in  out  source      destination
1      353 28859 ACCEPT all  --  *  *   0.0.0.0 /0   0.0.0.0 /0     state RELATED,ESTABLISHED
......
[root@server01 ~] # iptables -I INPUT -s 100.100.100.0/24 -i ens33 -j ACCEPT
[root@server01 ~] # iptables -nvL --line-numbers
Chain INPUT (policy ACCEPT 0 packets, 0 bytes)
num   pkts bytes target     prot opt  in      out      source                destination
1        0     0 ACCEPT     all  --  ens33  *       100.100.100.0 /24      0.0.0.0 /0
.......
[root@server01 ~] # iptables -D INPUT -s 100.100.100.0/24 -i ens33 -j ACCEPT
[root@server01 ~] # iptables -nvL --line-numbers
Chain INPUT (policy ACCEPT 0 packets, 0 bytes)
num   pkts bytes target prot opt  in  out  source      destination
1      626 50787 ACCEPT all  --  *  *   0.0.0.0 /0   0.0.0.0 /0    state RELATED,ESTABLISHED
......
[root@server01 ~] # iptables-save  > 1.ipt    ##将规则重定向到文件中,备份用
[root@server01 ~] # iptables-restore < 1.ipt  ##恢复规则
[root@server01 ~] # service iptables restart  ##重启iptables服务
Redirecting to  /bin/systemctl  restart  iptables.service


在虚拟机网络模式为NAT的情况下,也可以实现物理机和虚机的单向访问:                  

iptables -I INPUT -p icmp --icmp-type 0 -j DROP      // 只有物理机可以ping通虚机

iptables -I INPUT -p icmp --icmp-type 8 -j DROP     // 只有虚机可以ping通物理机 


iptables -P INPUT DROP 将filter表INPUT链的默认规则改成DROP(不要随意更改,会导致无法管理)











本文转自Grodd51CTO博客,原文链接:http://blog.51cto.com/juispan/1946913,如需转载请自行联系原作者


相关文章
|
8月前
|
Linux 网络性能优化 网络安全
Linux(openwrt)下iptables+tc工具实现网络流量限速控制(QoS)
通过以上步骤,您可以在Linux(OpenWrt)系统中使用iptables和tc工具实现网络流量限速控制(QoS)。这种方法灵活且功能强大,可以帮助管理员有效管理网络带宽,确保关键业务的网络性能。希望本文能够为您提供有价值的参考。
1184 28
|
机器学习/深度学习 安全 网络协议
Linux防火墙iptables命令管理入门
本文介绍了关于Linux防火墙iptables命令管理入门的教程,涵盖了iptables的基本概念、语法格式、常用参数、基础查询操作以及链和规则管理等内容。
403 73
|
9月前
|
监控 安全 Linux
启用Linux防火墙日志记录和分析功能
为iptables启用日志记录对于监控进出流量至关重要
284 1
|
11月前
|
运维 网络协议 安全
Linux安全运维--一篇文章全部搞懂iptables
Linux安全运维--一篇文章全部搞懂iptables
176 1
|
10月前
|
存储 运维 Linux
Linux防火墙firewall的使用
CentOS 7 中的 firewalld 是基于 Netfilter 的防火墙服务,支持动态配置,无需重启服务即可生效。它通过区域管理网络流量,每个区域可以设置不同的防火墙规则。默认区域为 public,可以通过命令行工具 firewall-cmd 进行管理和配置。firewalld 提供了丰富的预定义服务和区域,方便用户根据需求进行灵活配置。
187 0
|
Linux 网络安全
linux关闭方防火墙的命令
linux关闭方防火墙的命令
221 2
|
网络协议 Linux 网络安全
Linux系列——关于防火墙iptables的常用命令
Linux系列——关于防火墙iptables的常用命令
|
网络协议 Linux 网络安全
百度搜索:蓝易云【Linux 防火墙配置(iptables和firewalld)详细教程。】
以上只是一些常见的iptables和firewalld命令示例,你可以根据自己的需求进行修改和扩展。请注意,在配置防火墙时务必小心,确保不会阻塞你所需要的合法流量,并确保保存和加载配置以使其永久生效。另外,建议在配置防火墙之前备份现有的防火墙规则以防止意外情况发生。
651 2
|
网络协议 安全 Linux
Linux防火墙--IPtables配置策略思路
Linux防火墙--IPtables配置策略思路 防火墙定义:是通过有机结合各类用于安全管理与筛选的软件和硬件设备,帮助计算机网络于其内、外网之间构建一道相对隔绝的保护屏障,以保护用户资料与信息安全性的一种技术。 防火墙发展应用:最早是ipfwadm和ipchains(Redhat7.0), 其次是iptables,Centos7开始后friewalld迅速发展,对iptables进行了 改良,目前还是iptables用的比较多。
580 0
Linux防火墙--IPtables配置策略思路
|
网络协议 Ubuntu 安全
Linux 防火墙 iptables 初学者教程
iptables 是专为 Linux 操作系统打造的极其灵活的防火墙工具。对 Linux 极客玩家和系统管理员来说,iptables 非常有用。本文将向你展示如何配置最通用的 Linux 防火墙。
463 0
Linux 防火墙 iptables 初学者教程

热门文章

最新文章