Asuming that:
- PC1 has a working internet connection which we want to share with PC2.
- PC1 is connected to PC2 with a cross-over cable or a switch
- 192.168.0.1 is the IP address we assign to PC1
- 192.168.0.2 is the IP address we assign to PC2
- 10.0.0.2 is the IP address for the nameserver used by PC1 (
cat /etc/resolve.conf on PC1 )
ON PC1:
eth0 is the network interface that connects to PC2
# configure eth0
ifconfig eth0 192.168.0.1 netmask 255.255.255.0
ifconfig eth0 up
# enable forwarding
echo 1 > /proc/sys/net/ipv4/ip_forward
# forward with iptables
iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
/etc/rc.d/iptables save
/etc/rc.d/iptables start
ON PC2:
eth0 is the interface that connects to PC1
# enable eth0
ifconfig eth0 192.168.0.2 netmask 255.255.255.0
ifconfig eth0 up
# route through other pc
route add default gw 192.168.0.1
# specify nameserver
echo "nameserver 10.0.0.2" >> /etc/resolve.conf
See Internet Share for reference.