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,如需转载请自行联系原作者


相关文章
|
9月前
|
Linux 网络性能优化 网络安全
Linux(openwrt)下iptables+tc工具实现网络流量限速控制(QoS)
通过以上步骤,您可以在Linux(OpenWrt)系统中使用iptables和tc工具实现网络流量限速控制(QoS)。这种方法灵活且功能强大,可以帮助管理员有效管理网络带宽,确保关键业务的网络性能。希望本文能够为您提供有价值的参考。
1295 28
|
机器学习/深度学习 安全 网络协议
Linux防火墙iptables命令管理入门
本文介绍了关于Linux防火墙iptables命令管理入门的教程,涵盖了iptables的基本概念、语法格式、常用参数、基础查询操作以及链和规则管理等内容。
410 73
|
10月前
|
监控 安全 Linux
启用Linux防火墙日志记录和分析功能
为iptables启用日志记录对于监控进出流量至关重要
300 1
|
运维 网络协议 安全
Linux安全运维--一篇文章全部搞懂iptables
Linux安全运维--一篇文章全部搞懂iptables
189 1
|
11月前
|
存储 运维 Linux
Linux防火墙firewall的使用
CentOS 7 中的 firewalld 是基于 Netfilter 的防火墙服务,支持动态配置,无需重启服务即可生效。它通过区域管理网络流量,每个区域可以设置不同的防火墙规则。默认区域为 public,可以通过命令行工具 firewall-cmd 进行管理和配置。firewalld 提供了丰富的预定义服务和区域,方便用户根据需求进行灵活配置。
194 0
|
Linux 网络安全
linux关闭方防火墙的命令
linux关闭方防火墙的命令
231 2
|
安全 Linux 应用服务中间件
在Linux中,包过滤防火墙与代理应用防火墙有什么区别?有哪些相应的产品?
在Linux中,包过滤防火墙与代理应用防火墙有什么区别?有哪些相应的产品?
|
网络协议 Linux 网络安全
入职必会-开发环境搭建39-Linux常用操作-Linux防火墙操作
在CentOS 7中,新引入了firewalld服务(防火墙),取代了CentOS 6之前的iptables服务(防火墙)。
152 5
入职必会-开发环境搭建39-Linux常用操作-Linux防火墙操作
|
Linux 网络安全
在Linux中,如何设置防火墙规则?
在Linux中,如何设置防火墙规则?
|
Linux 网络安全
在Linux中,iptables和firewalld两种防火墙如何使用?
在Linux中,iptables和firewalld两种防火墙如何使用?

热门文章

最新文章