Internet sharing WIFI to LAN on Linux Easy
Page 1 of 1
Internet sharing WIFI to LAN on Linux Easy
Server Side Linux to host internet through LAN Port (even on RPI 5) from wifi connection!
(This will forward inet traffic internet sharing easy asf)!
Step 1 connect your RPI 5 (or linux laptop / pc) to your wireless internet!
Step 2 (The Setup)
Step 3 (Starting up the inet server)
Last Step aka Client Side Commands!
Test the connection!
This is temporary and will need to be re run each reboot! (both server and client)!
Heres an updated script version that dont require client side setup!
enable.sh
disable.sh
(This will forward inet traffic internet sharing easy asf)!
Step 1 connect your RPI 5 (or linux laptop / pc) to your wireless internet!
Step 2 (The Setup)
- Code:
sudo apt update
sudo apt install -y dnsmasq iptables network-manager
sudo cp /etc/dnsmasq.conf /etc/dnsmasq.conf.bak
Step 3 (Starting up the inet server)
- Code:
sudo sysctl -w net.ipv4.ip_forward=1
sudo ip addr add 192.168.4.1/24 dev eth0
sudo ip link set dev eth0 up
sudo cp /etc/dnsmasq.conf /etc/dnsmasq.conf.bak
sudo gedit /etc/dnsmasq.conf
sudo systemctl restart dnsmasq
sudo iptables -t nat -A POSTROUTING -o wlan0 -j MASQUERADE
sudo iptables -A FORWARD -i eth0 -j ACCEPT
sudo sh -c "iptables-save > /etc/iptables.rules"
Last Step aka Client Side Commands!
- Code:
sudo ifconfig eth0 192.168.4.10 netmask 255.255.255.0 up
sudo route add default gw 192.168.4.1
Test the connection!
- Code:
ifconfig
This is temporary and will need to be re run each reboot! (both server and client)!
Heres an updated script version that dont require client side setup!
enable.sh
- Code:
#!/bin/bash
# (c) J~Net 2024
# https://jnet.forumotion.com/t2047-internet-sharing-wifi-to-lan-on-linux-easy#3195
#
# ./enable.sh
# Enable IP forwarding
echo "Setting Internet Sharing Up..."
# Enable IP forwarding
sudo sysctl -w net.ipv4.ip_forward=1
# Configure static IP for the LAN interface
sudo ip addr add 192.168.4.1/24 dev eth0
sudo ip link set dev eth0 up
# Backup the existing dnsmasq configuration file (optional)
# sudo cp /etc/dnsmasq.conf /etc/dnsmasq.conf.bak
# Configure dnsmasq for DHCP and DNS
sudo tee /etc/dnsmasq.conf > /dev/null <<EOL
# Listen on the LAN interface
interface=eth0
# DHCP range for clients
dhcp-range=192.168.4.2,192.168.4.20,255.255.255.0,24h
# Gateway (default route) for clients
dhcp-option=3,192.168.4.1
# DNS server for clients
dhcp-option=6,192.168.4.1
# Upstream DNS servers
server=8.8.8.8
server=8.8.4.4
EOL
# Restart dnsmasq to apply the new configuration
sudo systemctl restart dnsmasq
# Configure NAT for Internet sharing
sudo iptables -t nat -A POSTROUTING -o wlan0 -j MASQUERADE
sudo iptables -A FORWARD -i eth0 -j ACCEPT
# Save iptables rules for persistence
sudo sh -c "iptables-save > /etc/iptables.rules"
# Display success message
echo "Internet Sharing Enabled On LAN IP: 192.168.4.1"
disable.sh
- Code:
#!/bin/bash
# (c) J~Net 2024
# https://jnet.forumotion.com/t2047-internet-sharing-wifi-to-lan-on-linux-easy#3195
#
# ./disable.sh
#
# Stop dnsmasq service
sudo systemctl stop dnsmasq
# Restore original dnsmasq configuration
if [ -f /etc/dnsmasq.conf.bak ]; then
sudo mv /etc/dnsmasq.conf.bak /etc/dnsmasq.conf
echo "Restored original dnsmasq configuration."
else
echo "Backup dnsmasq configuration not found; skipping restore."
fi
# Remove static IP configuration for eth0
sudo ip addr flush dev eth0
sudo ip link set dev eth0 down
# Disable IP forwarding
sudo sysctl -w net.ipv4.ip_forward=0
sudo sed -i '/net.ipv4.ip_forward=1/d' /etc/sysctl.conf
# Clear iptables rules
sudo iptables -t nat -F
sudo iptables -F
sudo iptables -t nat -X
sudo iptables -X
# Remove saved iptables rules if they exist
if [ -f /etc/iptables.rules ]; then
sudo rm /etc/iptables.rules
echo "Removed saved iptables rules."
else
echo "No saved iptables rules found; skipping removal."
fi
# Restart dnsmasq service to apply clean configuration
sudo systemctl restart dnsmasq
echo "Internet sharing disabled and settings reverted to normal."
Last edited by jamied_uk on 17th November 2024, 09:02; edited 1 time in total
Re: Internet sharing WIFI to LAN on Linux Easy
Setup Script for IS
No Client Side Setup Required!
Reset script to disable IS
- Code:
#!/bin/bash
# (c) J~Net 2024
# https://jnet.forumotion.com/t2047-internet-sharing-wifi-to-lan-on-linux-easy#3195
#
# ./enable.sh
# Enable IP forwarding
echo "Setting Internet Sharing Up..."
# Enable IP forwarding
sudo sysctl -w net.ipv4.ip_forward=1
# Configure static IP for the LAN interface
sudo ip addr add 192.168.4.1/24 dev eth0
sudo ip link set dev eth0 up
# Backup the existing dnsmasq configuration file (optional)
# sudo cp /etc/dnsmasq.conf /etc/dnsmasq.conf.bak
# Configure dnsmasq for DHCP and DNS
sudo tee /etc/dnsmasq.conf > /dev/null <<EOL
# Listen on the LAN interface
interface=eth0
# DHCP range for clients
dhcp-range=192.168.4.2,192.168.4.20,255.255.255.0,24h
# Gateway (default route) for clients
dhcp-option=3,192.168.4.1
# DNS server for clients
dhcp-option=6,192.168.4.1
# Upstream DNS servers
server=8.8.8.8
server=8.8.4.4
EOL
# Restart dnsmasq to apply the new configuration
sudo systemctl restart dnsmasq
# Configure NAT for Internet sharing
sudo iptables -t nat -A POSTROUTING -o wlan0 -j MASQUERADE
sudo iptables -A FORWARD -i eth0 -j ACCEPT
# Save iptables rules for persistence
sudo sh -c "iptables-save > /etc/iptables.rules"
# Display success message
echo "Internet sharing enabled. LAN IP: 192.168.4.1"
No Client Side Setup Required!
Reset script to disable IS
- Code:
#!/bin/bash
# (c) J~Net 2024
# https://jnet.forumotion.com/t2047-internet-sharing-wifi-to-lan-on-linux-easy#3195
#
# ./disable.sh
#
# Stop dnsmasq service
sudo systemctl stop dnsmasq
# Restore original dnsmasq configuration
if [ -f /etc/dnsmasq.conf.bak ]; then
sudo mv /etc/dnsmasq.conf.bak /etc/dnsmasq.conf
echo "Restored original dnsmasq configuration."
else
echo "Backup dnsmasq configuration not found; skipping restore."
fi
# Remove static IP configuration for eth0
sudo ip addr flush dev eth0
sudo ip link set dev eth0 down
# Disable IP forwarding
sudo sysctl -w net.ipv4.ip_forward=0
sudo sed -i '/net.ipv4.ip_forward=1/d' /etc/sysctl.conf
# Clear iptables rules
sudo iptables -t nat -F
sudo iptables -F
sudo iptables -t nat -X
sudo iptables -X
# Remove saved iptables rules if they exist
if [ -f /etc/iptables.rules ]; then
sudo rm /etc/iptables.rules
echo "Removed saved iptables rules."
else
echo "No saved iptables rules found; skipping removal."
fi
# Restart dnsmasq service to apply clean configuration
sudo systemctl restart dnsmasq
echo "Internet sharing disabled and settings reverted to normal."
Similar topics
» internet connection sharing
» sharing files between linux and windows
» windows xp and linux samba sharing folder shares
» reveal wifi passwords on linux
» wifi host creation for linux
» sharing files between linux and windows
» windows xp and linux samba sharing folder shares
» reveal wifi passwords on linux
» wifi host creation for linux
Page 1 of 1
Permissions in this forum:
You cannot reply to topics in this forum