> For the complete documentation index, see [llms.txt](https://fashaun.gitbook.io/dev-network/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://fashaun.gitbook.io/dev-network/nat.md).

# NAT

\#NAT

\###NAT\
負責進行網路IP位置的封裝轉換 。\
之前也有說到這個主要目的是要解決目前IPv4網路上IP位置不夠的問題。\
雖然IPv4已經慢慢準備要被IPv6取代掉，但那也是好久之後的事情，\
NAT 的轉換方式除了整個網段的轉換(封裝)之外，\
他也可以針對特定port進行轉換，我捫稱為NAPT

這個NAPT跟一般的NAT不太一樣，一般的NAT是我內部連接到外部，\
而且不管是要連接甚麼特定服務都幫你轉換(雖然也可以指限制轉換，例如只讓你連接到80&443)\
但這邊的NAPT是反過來使用的，也就是原本是內部連接外部，

那現在外部連接到內部該怎麼處理呢?\
假使我在我的電腦本機(10.10.10.10)上建立的一個測試用的網站(HTTP)，我想讓客戶看到我的網站。\
但我的IP位置是私有IP，外面一般來說是看不到!!該怎麼辦?\
這時候就是得看NAPT的反向轉換。

\###NAPT

EX:\
公司私有網段:10.10.10.0/24 , 外部IP 11.11.11.11/32 ,服務 HTTP(TCP-80)\
內部 → 外部網路\
10.10.10.0/24 轉換成 11.11.11.11出去連接網際網路\
所以不管是我個人的IP:10.10.10.10/3或者我同事10.10.10.11/32連接出去都是遇同樣的IP。

外部 → 內部\
之前有說過了，內部IP一般外面是無法連接的，除了不知道外，私有IP是不被承認的。\
所以現在要用NAPT了。\
我在NAT服務上面設定10.10.10.10的 TCP -80 直接綁定到11.11.11.11 TCP:80上，\
這個時候別人只要連接[http://11.11.11.11，就會由NAPT幫我顯示我電腦上的測試網站了。](http://11.11.11.11%EF%BC%8C%E5%B0%B1%E6%9C%83%E7%94%B1napt%E5%B9%AB%E6%88%91%E9%A1%AF%E7%A4%BA%E6%88%91%E9%9B%BB%E8%85%A6%E4%B8%8A%E7%9A%84%E6%B8%AC%E8%A9%A6%E7%B6%B2%E7%AB%99%E4%BA%86%E3%80%82/)\
外部IP → 11.11.11.11 (由NAPT協助導向10.10.10.10)去。這也是一種保護內部主機的方法


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://fashaun.gitbook.io/dev-network/nat.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
