Linux性能调优:如何优化NAT性能?

本文探讨了NAT技术的用途、分类及其在Linux中的实现,特别是NAT性能调优。通过分析NAT问题,如DNAT、SNAT的配置,以及conntrack表的调整,揭示了内核参数对NAT性能的影响。通过增加nf_conntrack_max和调整超时时间,可以有效改善NAT性能。
摘要由CSDN通过智能技术生成

1、NAT的目的

  由于IPV4地址短缺,为解决公网 IP 地址短缺的问题,所以诞生了NAT技术,来重写IP数据包源IP或者目的IP。

2、NAT分类

        静态 NAT,即内网 IP 与公网 IP 是一对一的永久映射关系;

        动态 NAT,即内网 IP 从公网 IP 池中,动态选择一个进行映射;

        网络地址端口转换 NAPT(Network Address and Port Translation),即把内网 IP 映射到公网 IP 的不同端口上,让多个内网 IP 可以共享同一个公网 IP 地址。

3、NAPT分类

        源地址转换SNAT,即目的地址不变,只替换源 IP 或源端口。SNAT 主要用于,多个内网 IP 共享同一个公网 IP ,来访问外网资源的场景。

        目的地址转换 DNAT,即源 IP 保持不变,只替换目的 IP 或者目的端口。DNAT 主要通过公网 IP 的不同端口号,来访问内网的多种服务,同时会隐藏后端服务器的真实 IP 地址。

        双向地址转换,即同时使用 SNAT 和 DNAT。当接收到网络包时,执行 DNAT,把目的 IP 转换为内网 IP;而在发送网络包时,执行 SNAT,把源 IP 替换为外部 IP。

        IPtables 是linux常用的一种配置工具,我们可以man iptables,可以发现table,用来管理链规则的,其中包含5个表,filter(过滤),nat(转换)、mangle(修改分组数据)、raw(原始数据包)、security(安全)

        Filter表中,内置INPUT、OUTPUT和FORWARD链

  -t, --table table
              This option specifies the packet matching table which the command should  operate  on.   If
              the kernel is configured with automatic module loading, an attempt will be made to load the
              appropriate module for that table if it is not already there.

              The tables are as follows:

              filter:
                  This is the default table (if no -t option is passed). It contains the built-in  chains
                  INPUT  (for  packets  destined  to  local  sockets),  FORWARD (for packets being routed
                  through the box), and OUTPUT (for locally-generated packets).

              nat:
                  This table is consulted when a packet that creates a new connection is encountered.  It
                  consists  of four built-ins: PREROUTING (for altering packets as soon as they come in),
                  INPUT (for altering packets destined for local sockets), OUTPUT (for altering  locally-
                  generated  packets  before  routing), and POSTROUTING (for altering packets as they are
                  about to go out).  IPv6 NAT support is availab
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值