Skip to content

Instantly share code, notes, and snippets.

@Juul
Last active December 3, 2018 22:50
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Juul/1f2b99d0fbcfa8cf540c02aa6d75fa66 to your computer and use it in GitHub Desktop.
Save Juul/1f2b99d0fbcfa8cf540c02aa6d75fa66 to your computer and use it in GitHub Desktop.
Turn your computer into a gateway that shares internet from the wifi to ethernet
# Edit /etc/NetworkManager/NetworkManager.conf adding the following
# to make network manager stop managing your ethernet interface
[keyfile]
unmanaged-devices=mac:3c:90:01:39:b2:62; 
# Use the MAC address from your ethernet card
# You can get the MAC address with the command: 
ip link show dev eth0
# (assuming your ethernet device is called eth0)

# restart network-manager to pick up the changes
sudo service network-manager restart

# Install dnsmasq
sudo apt install dnsmasq

# Add the following line to /etc/dnsmasq.conf
dhcp-range=172.23.0.50,172.23.0.200,12h

# If you aren't using dnsmasq for DNS (which probably you aren't if you just installed it)
# change the line 'port=53' to:
port=0

# If you set 'port=0' then you should add the following line to enable DNS for the clients
dhcp-option=6,8.8.8.8

# Save the file.

# Run the following to turn you computer into a gateway
# (replace eth0 with your ethernet interface name)
# (replace wlan0 with your wifi interface name)

ip addr flush dev eth0 # this will remove all existing addresses on eth0 and may not be necessary
ip addr add dev eth0 172.23.0.1/24
ip link set dev eth0 up
echo "1" > /proc/sys/net/ipv4/ip_forward
iptables -P FORWARD ACCEPT
iptables -t nat -F POSTROUTING
iptables -t nat -A POSTROUTING -o wlan0 -j MASQUERADE
/etc/init.d/dnsmasq restart

# Connect another computer to your ethernet port and it should get an IP using DHCP and have internet access

# You can watch for DCHP requests using 
tail -f /var/log/syslog

# Or if you're using systemd
journalctl -u dnsmasq.service -f
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment