Skip to content

Instantly share code, notes, and snippets.

@felixknorre
Last active May 6, 2021 08:48
Show Gist options
  • Select an option

  • Save felixknorre/422e67764e5afca78faca64667d08202 to your computer and use it in GitHub Desktop.

Select an option

Save felixknorre/422e67764e5afca78faca64667d08202 to your computer and use it in GitHub Desktop.
NAPT with a Raspberry Pi

Raspberry Pi Gateway

update packages

sudo apt update
sudo apt upgrade

change password

passwd

Konfiguration des statischen Netzes

Server

vi /etc/dhcpcd.conf
interface eth0
static ip_address=10.10.10.2/24    
static routers=10.10.10.1
static domain_name_servers=192.168.0.1 8.8.8.8

Pi Gateway

vi /etc/dhcpcd.conf
interface eth0
static ip_address=10.10.10.1/24    
static routers=192.168.0.1
static domain_name_servers=192.168.0.1 8.8.8.8

NAPT einrichten

echo 1 > /proc/sys/net/ipv4/ip_forward
iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
iptables -A FORWARD -i eth1 -o eth0 -m state --state RELATED,ESTABLISHED -j ACCEPT
iptables -A FORWARD -i eth0 -o eth1 -j ACCEPT
apt-get install iptables-persistent # make config persistent
  • -t nat -> "nat" Tabelle
  • POSTROUTING -> Füge Regel in POSTROUTING Kette ein
  • -o eth0 -> Ausgang
  • -j MASQUERADE -> setze eigene Adresse als Quelladresse ein
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment