> For the complete documentation index, see [llms.txt](https://hacking-notes.jord4n.pro/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://hacking-notes.jord4n.pro/ja/hacking-wifi/wpa-wpa2-psk-network-attacks/evil-twin/eviltwin-iptables-rules-and-network-interfaces.md).

# EvilTwin - iptables ルールとネットワークインターフェース

EvilTwin 用にネットワークインターフェースと iptables ルールを構成する。

## iptablesのルールとネットワークインターフェース

アクセスポイントを作成するためにAirbaseを起動します。

### 作成する `at0` インターフェース

アクセスポイント用のネットワークインターフェースを作成します:

{% code overflow="wrap" %}

```bash
sudo ip tuntap add dev at0 mode tap
sudo ip link set at0 up
sudo ip addr add 192.168.1.129/25 dev at0
```

{% endcode %}

### ネットワークルートを追加

新しいサブネットのルートを追加します:

{% code overflow="wrap" %}

```bash
route add -net 192.168.1.128 netmask 255.255.255.128 gw 192.168.1.129 
```

{% endcode %}

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2FjiLCO3D5WQxB6G1BN8e1%2Fimage.png?alt=media&amp;token=e0676c15-c259-43eb-8eee-29c03fb95bbb" alt=""><figcaption></figcaption></figure>

設定は次のようになります:

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2FbpVLV9rfWzYBk1kIIs4G%2Fimage.png?alt=media&amp;token=6d7f5d66-d1a3-4cb6-b7de-4d67aaf423cf" alt=""><figcaption></figcaption></figure>

### IP転送を有効にする

設定する `ip_forward` に `1`:

{% code overflow="wrap" %}

```bash
echo 1 > /proc/sys/net/ipv4/ip_forward
```

{% endcode %}

### iptablesのルールをクリアする

既存のルールをクリアします:

{% code overflow="wrap" %}

```bash
sudo iptables --flush
sudo iptables --table nat --flush
sudo iptables --delete-chain
sudo iptables --table nat --delete-chain
```

{% endcode %}

### ルールを確認する

有効なルールを確認します:

{% code overflow="wrap" %}

```bash
iptables -S
iptables -L
```

{% endcode %}

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fy9YYWmyDDrb8Ef7qvSTp%2Fimage.png?alt=media&amp;token=b2e423d5-443d-4bea-a6d5-896bd33689ab" alt=""><figcaption></figcaption></figure>

### 転送とNATを設定する

外部インターフェースを設定してトラフィックを `at0`に転送します。また、HTTPトラフィックもリダイレクトします:

{% code overflow="wrap" %}

```bash
iptables --table nat --append POSTROUTING --out-interface eth0 -j MASQUERADE
iptables --append FORWARD --in-interface at0 -j ACCEPT
iptables -t nat -A PREROUTING -p tcp --dport 80 -j DNAT --to-destination $(hostname -I | awk '{print $1}'):80
iptables -t nat -A POSTROUTING -j MASQUERADE
```

{% endcode %}


---

# 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 by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://hacking-notes.jord4n.pro/ja/hacking-wifi/wpa-wpa2-psk-network-attacks/evil-twin/eviltwin-iptables-rules-and-network-interfaces.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
