Saturday, October 29, 2011

Sharing Internet Modem via Lan on Backtrack (Linux)



To get internet form other computer, first we set our ip, gateway and DNS in our computer.

The text which blue color is our computer (computer A). And the red color is the other computer which connect to the internet (computer I).

1. First, in computer I we look for network information about ppp0.

# ifconfig ppp0
ppp0 Link encap:Point-to-Point Protocol
inet addr:10.77.221.111 P-t-P:192.168.11.10 Mask:255.255.255.255
UP POINTOPOINT RUNNING NOARP MULTICAST MTU:1500 Metric:1
RX packets:21275 errors:4 dropped:0 overruns:0 frame:0
TX packets:21823 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:3
RX bytes:24204058 (24.2 MB) TX bytes:2716284 (2.7 MB)


The conclusion, ip ppp0 computer I is 10.77.221.111.

2. We set ip for our computer. In my computer:

Ip : 192.168.100.2
Gateway : 192.168.100.1
Prefered DNS server : 10.4.22.1
Alternate DNS server : 10.4.21.3
(we can see for DNS from Computer I with "cat /etc/resolv.conf")

And than, on linux we can set like this:

# ifconfig eth0 down
# ifconfig eth0 192.168.100.2 netmask 255.255.255.0
# route add default gw 192.168.100.1 eth0
# nano /etc/resolv.conf
nameserver 10.4.22.1
nameserver 10.4.21.3
# ifconfig eth0 up


3. In computer I, we must set ip interface for eth0 (lan network)

# ifconfig eth0 192.168.100.1


4. For shared internet, we set the rule and ipforward via eth0,

# iptables -A FORWARD -i eth0 -p ALL -s 192.168.100.2/24 -d 10.77.221.111 -j ACCEPT


then set NAT (Network Addres Translation):

# iptables -t nat -A POSTROUTING -s 192.168.100.1/24 -j MASQUERADE


so we can give the last command for ip forward

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


Finally we can check the network from our computer (computer A) to access the internet.


4 comments:

  1. Hello, nice post.
    But I have a doubt my guest computer(Computer A here) is windows and my host Computer (Computer I here) is linux.
    So, I can forward ip, but how to connect to this computer from windows?
    Or can I use any softwares which can do this?

    Plz help

    Regards

    ReplyDelete
    Replies
    1. Thanks..
      Actually, i haven't do it on windows..
      I tried search with google, and the result that most of articles get topic about sharing internet
      Try this:
      http://www.google.co.id/search?q=sharing+internet+windows+xp
      And yes, i think you can shared internet on windows without software.. ^

      Delete