Chapter 5. Network Address Translation (NAT)

本文介绍了Linux下两种类型的网络地址转换(NAT):无状态NAT及目的地NAT(DNAT)。无状态NAT可在2.2及2.4内核版本中使用,而DNAT仅限于2.4内核版本,并且可以通过iptables工具进行配置。

Chapter 5. Network Address Translation (NAT)

Table of Contents

5.1. Rationale for and Introduction to NAT5.2. Application Layer Protocols with Embedded Network Information5.3. Stateless NAT with iproute2
5.3.1. Stateless NAT Packet Capture and Introduction5.3.2. Stateless NAT Practicum5.3.3. Conditional Stateless NAT
5.4. Stateless NAT and Packet Filtering5.5. Destination NAT with netfilter (DNAT)
5.5.1. Port Address Translation with DNAT
5.6. Port Address Translation (PAT) from Userspace5.7. Transparent PAT from Userspace

Network Address Translation (NAT) is a deceptively simple concept. NAT is the technique of rewriting addresses on a packet as it passes through a routing device. There are far reaching ramifications on network design and protocol compatibility wherever NAT is used.

This chapter will introduce two types of NAT available under linux. One, full NAT or stateless NAT, is available under kernel 2.2 and kernel 2.4 via the iproute2 userspace interface. Available only under kernel 2.4, destination NAT (DNAT) is an important derivative of full NAT. DNAT configuration from userspace is accomplished via the iptables utility. The experienced network administrator is probably puzzling about absent references to source NAT (SNAT) and masquerading. These prominent and prevalent uses of NAT are covered in Chapter 6, Masquerading and Source Network Address Translation, although many concepts involved in the special purpose SNAT and masquerading will be introduced in this chapter.

Network address translation is known by a number of names in the networking world: full NAT, one-to-one NAT and inbound NAT. As used in this chapter and throughout this documentation, NAT, when unqualified, will refer to full network address translation or one-to-one NAT. NAT techniques derived from full NAT, such as destination or source NAT, will be described as DNAT (destination NAT) and SNAT (source NAT).

Michael Hasenstein's seminal paper on network address translation is available courtesy of SuSe Linux AG here.

1)按照教材中的说明,编写OrdersMapper 接口,它位于org.ngweb.chapter5.mapper 包中。 代码如下(可以复制下述代码,避免打字错误): package org.ngweb.chapter5.mapper; import java.util.List; import org.ngweb.chapter5.pojo.Orders; public interface OrdersMapper { public List<Orders> getOrderList(int id); } 2)按照教材中的说明,编写UserMapper 接口,它位于org.ngweb.chapter5.mapper 包中。 代码如下(可以复制下述代码,避免打字错误): package org.ngweb.chapter5.mapper; import org.ngweb.chapter5.pojo.User; public interface UserMapper { public User getUserById(int id); } 3)按照教程中的说明,编写OrdersMapper 接口对应的xml 文件OrdersMapper.xml,它位于org.ngweb.chapter5.mapper 包中。 代码如下(可以复制下述代码,避免打字错误): <?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <mapper namespace="org.ngweb.chapter5.mapper.OrdersMapper"> // 在这里补写代码 </mapper> 4)按照教程中的说明,编写UserMapper 接口对应的xml 文件UserMapper.xml,它位于org.ngweb.chapter5.mapper 包中。 代码如下(可以复制下述代码,避免打字错误): <?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <mapper namespace="org.ngweb.chapter5.mapper.UserMapper"> // 在这里补写代码 </mapper>
11-05
### 补全 OrdersMapper.xml 文件 ```xml <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <mapper namespace="org.ngweb.chapter5.mapper.OrdersMapper"> <!-- 对应 OrdersMapper 接口的 getOrderList 方法 --> <select id="getOrderList" resultType="java.util.Map"> -- 这里需要根据实际的数据库表结构和业务需求编写 SQL 查询语句 -- 示例:假设存在一个 orders 表 SELECT * FROM orders; </select> </mapper> ``` ### 补全 UserMapper.xml 文件 ```xml <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <mapper namespace="org.ngweb.chapter5.mapper.UserMapper"> <!-- 对应 UserMapper 接口的 getUserById 方法 --> <select id="getUserById" parameterType="int" resultType="java.util.Map"> -- 这里需要根据实际的数据库表结构和业务需求编写 SQL 查询语句 -- 示例:假设存在一个 users 表,有 id 字段作为主键 SELECT * FROM users WHERE id = #{id}; </select> </mapper> ``` ### 注意事项 - `namespace` 属性的值需要与对应的接口全限定名一致,这样 MyBatis 才能正确找到对应的接口方法。 - `id` 属性的值需要与接口中的方法名一致。 - `resultType` 属性用于指定查询结果的类型,这里示例使用 `java.util.Map` 作为通用类型,实际使用中可以根据业务需求替换为具体的实体类。 - `parameterType` 属性用于指定传入参数的类型,在 `getUserById` 方法中传入的是一个整数类型的用户 ID,所以使用 `int` 类型。
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值