> 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/hacking-wifi/wpa-wpa2-psk-network-attacks/evil-twin/eviltwin-iptables-rules-and-network-interfaces.md).

# EvilTwin - iptables Rules and Network Interfaces

Configure the network interface and iptables rules for EvilTwin.

## iptables Rules and Network Interfaces

Start Airbase to create the access point.

### Create the `at0` Interface

Create the network interface for the access point:

{% 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 %}

### Add the Network Route

Add the route for the new subnet:

{% 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://131707722-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>

The configuration should look like this:

<figure><img src="https://131707722-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>

### Enable IP Forwarding

Set `ip_forward` to `1`:

{% code overflow="wrap" %}

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

{% endcode %}

### Clear iptables Rules

Clear the existing rules:

{% code overflow="wrap" %}

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

{% endcode %}

### Verify the Rules

Verify the active rules:

{% code overflow="wrap" %}

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

{% endcode %}

<figure><img src="https://131707722-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>

### Configure Forwarding and NAT

Configure the external interface to forward traffic to `at0`. Also redirect HTTP traffic:

{% 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/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.
