I think this will do what you want, assuming that the network is like this:
Internet <----> Computer A <----> Computer B
<external interface> is the interface (like
p1p1, etc) that is connected to the Internet on Computer A.
<internal interface> is the interface on Computer A that is connected to Computer B.
These commands need to be run as root (in
su -) on Computer A (the one with Internet access).
echo 1 > /proc/sys/net/ipv4/ip_forward #Tell the system it is OK to forward IP packets
iptables -t nat -A POSTROUTING -o $EXT -j MASQUERADE
iptables -A FORWARD -i $EXT -o $INT -m state --state RELATED,ESTABLISHED -j ACCEPT
iptables -A FORWARD -i $INT -o $EXT -j ACCEPT
ip addr show $INT
In the output of the
ip addr command, find the line that starts with
inet6 if you are using IPv6). Use the IP address on that line in the following command, as root, on Computer B:
ip route add default via <put ComputerA's internal IP address here>
Now, see if it works by running
ping google.com on Computer B, or simply by attempting to load a web page in the browser.
If you want to save the changes on Computer A, run these commands as root:
apt-get install iptables-persistent
Now I don't know exactly how to restore the saved rules on boot, can anybody else suggest something? It should work to do
/etc/init.d/iptables-persistent reload (as root) every time after you boot, but that would be a pain.
To make Computer B always use Computer A as the default gateway would require installing DHCP on Computer A, which I don't want to go into in this answer.