Skip to content

Instantly share code, notes, and snippets.

@pojntfx
Last active September 4, 2024 05:37
Show Gist options
  • Save pojntfx/03598ee86574d5e7bc196683b629534a to your computer and use it in GitHub Desktop.
Save pojntfx/03598ee86574d5e7bc196683b629534a to your computer and use it in GitHub Desktop.
Share Wifi/WLAN to an Ethernet/LAN network using a Linux Desktop
#!/bin/bash
# 1. Go to "Settings → Networks"
# 2. Create a new profile
# 3. Go to "Identity" and set the name to "Shared", and the MAC address to that of your ethernet device (use the dropdown)
# 4. Go to "IPv4" and set the method to "Shared with other computers"
# 5. Go to "IPv6" and set the method to "Shared with other computers"
# 6. Select "Apply" to create the profile
# 7. Enable the profile by clicking on it
# 8. Run the commands below (replace wlp0s20f3 with your WLAN interface and enp0s13f0u3u1c2 with your LAN interface)
sudo iptables -A FORWARD -i enp0s13f0u1u1c2 -o wlp0s20f3 -j ACCEPT
sudo iptables -A FORWARD -i wlp0s20f3 -o enp0s13f0u1u1c2 -m state --state ESTABLISHED,RELATED -j ACCEPT
sudo iptables -t nat -A POSTROUTING -o wlp0s20f3 -j MASQUERADE
sudo ip6tables -A FORWARD -i enp0s13f0u1u1c2 -o wlp0s20f3 -j ACCEPT
sudo ip6tables -A FORWARD -i wlp0s20f3 -o enp0s13f0u1u1c2 -m state --state ESTABLISHED,RELATED -j ACCEPT
sudo ip6tables -t nat -A POSTROUTING -o wlp0s20f3 -j MASQUERADE
# If you're using Tailscale/a VPN with a default route
sudo ip rule add from 10.42.0.1/24 table main
sudo ip rule add to 10.42.0.1/24 table main
sudo iptables -A FORWARD -i enp0s13f0u1u1c2 -o tailscale0 -j ACCEPT
sudo iptables -A FORWARD -i tailscale0 -o enp0s13f0u1u1c2 -j ACCEPT
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment