IPTables NAT Configuration: Laptop & Orange Pi 1 & Orange Pi 2
In this article, we will discuss how to configure IP Tables to set up a NAT (Network Address Translation) network involving a Laptop, Orange Pi 1, and Orange Pi 2. This configuration will allow the Orange Pi 2 to access the internet through the Laptop's network connection.
Prerequisites
Before we begin, make sure that you have the following:
- A Laptop with a network connection
- An Orange Pi 1 with a network connection
- An Orange Pi 2 with a network connection
- A basic understanding of IP Tables and NAT
Network Diagram
The following is a diagram of the network configuration:
+---------------+ +---------------+ +---------------+
| Laptop | <------> | Orange Pi 1 | <------> | Orange Pi 2 |
| (DHCP Address)| | (DHCP Address)| | (Static |
+---------------+ +---------------+ | Address) |
+---------------+
IPTables Configuration
To configure IP Tables for NAT, we need to perform the following steps:
- Allow forwarding of packets between the interfaces
- NAT the packets going from Orange Pi 2 to the internet
- Log the NATed packets
Step 1: Allow forwarding of packets between the interfaces
By default, Linux distributions do not allow forwarding of packets between interfaces. To enable packet forwarding, we need to modify the sysctl configuration.
# echo 1 > /proc/sys/net/ipv4/ip_forward
To make this change persistent, we need to modify the sysctl configuration file:
# vi /etc/sysctl.conf
# Add the following line to the file
net.ipv4.ip_forward = 1
Step 2: NAT the packets going from Orange Pi 2 to the internet
To NAT the packets going from Orange Pi 2 to the internet, we need to add the following IP Tables rules:
# iptables -t nat -A POSTROUTING -o -j MASQUERADE
# iptables -A FORWARD -i -o -m state --state RELATED,ESTABLISHED -j ACCEPT
# iptables -A FORWARD -i -o -j ACCEPT
Replace
Step 3: Log the NATed packets
To log the NATed packets, we can add the following IP Tables rule:
# iptables -A FORWARD -m limit --limit 5/min -j LOG --log-prefix "IPTables-Dropped: " --log-level 7
In this article, we discussed how to configure IP Tables for NAT involving a Laptop, Orange Pi 1, and Orange Pi 2. We covered the prerequisites, network diagram, and IP Tables configuration steps. With this configuration, Orange Pi 2 can access the internet through the Laptop's network connection.