There are many posts about this topic however some of them are quite old.
Here's the simple instruction of doing it.
Linux machine with 2 network adapters.
A Laptop usually have two network adapters: one for LAN, one for Wi-fi.
Below, I have two adapters connected to:
eth1: connected to private network
wlan1: connected to internet
1. turn on ip forward functionality
uncomment(or change if set to 0) net.ipv4.ip_forward = 1
$sysctl -p /etc/sysctl.conf
you can check whether it is correctly set or not with
2. setup ip forwarding & masquerading
Reminder: wlan1 is to internet, eth1 is to intranet(local network)
$iptables -t nat -A POSTROUTING -o wlan1 -j MASQUERADE
$iptables -A FORWARD -i eth1 -j ACCEPT
Now change gateway of your local network pc to linux machine's IP address and you can use internet from your local network pc via linux gateway.
If you cannot access internet from your local network pc, check linux machine's routing table.
192.168.16.0/24 dev wlan1 proto kernel scope link src 192.168.16.21 metric 2
192.168.0.0/24 dev eth1 proto kernel scope link src 192.168.0.58 metric 1
default via 192.168.0.1 dev eth1
As above, if eth1(private network) is set as default route, change default route to wlan1(internet) by:
$ip ro change default via xxx.xxx.xxx.xxx dev wlan1
$ip ro flush cache
where xxx.xxx.xxx.xxx is your wlan1(internet accessible adpater) gateway.