Skip to content

Instantly share code, notes, and snippets.

@radomd92
Forked from tzermias/ip_forward.md
Created July 29, 2020 18:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save radomd92/821a2a46f7c64f0227b888492fa6c0c6 to your computer and use it in GitHub Desktop.
Save radomd92/821a2a46f7c64f0227b888492fa6c0c6 to your computer and use it in GitHub Desktop.
Forward traffic from wlan0 to eth0 interface

Forward traffic from a laptop's eth0 to wlan0

###To laptop

Specify an IP address to eth0 (here 192.168.56.1)

sudo ifconfig eth0 192.168.56.1 netmask 255.255.255.0

Enable IP forwarding

sudo sysctl -w net.ipv4.ip_forward=1

Forward packets from eth0 to wlan0

sudo iptables -A FORWARD --in-interface eth0 -j ACCEPT
sudo iptables --table nat -A POSTROUTING --out-interface wlan0 -j MASQUERADE

###To device connected to laptop

Setup IP address for eth0,and add gateway

sudo ifconfig eth0 192.168.56.2 netmask 255.255.255.0
sudo route add default gw 192.168.56.1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment