Tuesday, March 10, 2009

Instant Internet Connection Sharing

Today I came Kandy for 5 days stay due to some functions lined up to attend. My office provided me a HSPA dongle to keep my self online during the stay. Nah.. it's not about the dongle. ;-). I wanted to share the Internet connection with another computer at home. I only had a crossover cable with me, which I always carry in my backpack. So I connected the two Laptops with it and shared my primary PPP connection with the guest Laptop. Both Laptops are runnung on GNU/Linux. The simple setup I had is as below.

Host PC Settings.

I already received an IP for my ppp0 connection from my ISP. So I only had to assign an IP to my LAN card (eth0)

# ifconfig eth0 10.0.0.1 netmask 255.255.255.0

(Don't need to set the default route in the host, cos it's already set to ppp0)

Enable NAT in Farewall and IP forwarding.

# iptables -P FORWARD ACCEPT
# iptables -t nat -A POSTROUTING -o ppp0 -j MASQUERADE

# echo 1 > /proc/sys/net/ipv4/ip_forwad

Guest Settings.

Set up the Interface.

# ifconfig eth0 10.0.0.2 netmask 255.255.255.0

Set the default route of the GUEST to HOST eth0 IP

# route add default gw 10.0.0.1

Put the name server IP which received to the HOST PC from ISP in the GUEST /etc/resolv.conf

# echo nameserver xxx.xxx.xxx.xxx > /etc/resolv.conf

That's all. I simply enabled Internet Connection Sharing in my Laptop.