Netfilter

是 Linux 内核中用于数据包处理的模块

Hook point

  • pre_routing
  • input
  • output
  • forward
  • post_routing

image.png

iptables 规则

四表 + 五链 + 规则

四表

  • filter, 访问控制
  • nat, 转发
  • mangle, 更改数据包
  • raw, 跟踪数据包

五链

  • pre_routing
  • input
  • output
  • forward
  • post_routing

image.png

规则

数据包访问控制

  • accept
  • drop
  • reject

数据包改写

  • snat, 改写 src
  • dnat, 改写 dest

信息记录

  • log

使用

image.png

filter

  1. $ iptables -I INPUT -p tcp --dport 80 -j ACCEPT
  2. $ iptables -I INPUT -p tcp --dport 10:21 -j ACCEPT

nat

image.png

image.png

  1. # 177.232
  2. // 配置允许转发
  3. $ vim /etc/sysctl.conf
  4. net.ipv4.ip_forward = 1
  5. $ sysctl -p
  1. # 177.232
  2. $ iptables -t nat -A POSTROUTING -s 10.10.177.0/24 -j SNAT --to 10.10.188.232
  3. # 需要在 177.233 上配置 177.232 为网关
  4. $ vim /etc/sysconfig/network
  5. GATEWARY=10.10.177.232

image.png