Sounds to me like you want to have a read of the documents at
http://www.netfilter.org and a look at the IP Masquerading HOWTO which is available on
http://www.tldp.org. This will explain the worst of it, give it a shot and come back to us with specific questions. The IP Masq howto will talk you through sharing the connection I would start there if I were you. Then go onto the netfilter docs.
HTH
Jamie...