Thursday, 12 April 2012

Connecting to LAN Internet using Linux OS

If you're reading this, its most likely that you have no clue how to connect to the LAN Internet (also referred as Cable connection) using your brand new Linux operating system. Don't feel bad, you're not alone.

Everybody had to ask few questions on how to get the freakin' internet work, and without the help of some folks on the online, I would have still been using Microsoft's Windows because connecting to the internet with it is so easy.

Internet is an important element when it comes to general computing, so if someone wants to introduce a new computer system such as Linux, at least let it run the most used service.

Now remember, you will not connect directly to the internet. Basically I'm going to teach you how to connect to a network that will enable you to use the internet. I'm not going teach how to use a certain Distro, or a certain GUI. Distro's network settings sometimes differ, so what I'm going to help you with is ignoring all the distro's default settings and write your own internet .sh script that would let you connect to the internet as easy as 1, 2, 3... So lets see what you have: A cable coming down from outside directly plugged to your NIC (Network Card), normally if you have one NIC, it would be named: eth0 (ethX -> X will change if you have more than one NIC). In this example we're gonna use only one NIC to enable Internet on one station only. General internet connection requirements:
  • an IP address + netmask
  • a Gateway address
  • a DNS address
  • and sometimes a Proxy server address.
Know what you need. It's important to know what you need to connect to your ISP's (Internet Service Provider) network. You will definitely not guess those. While having a nice conversation with your ISP, ask them for the following:
  • Your personal external IP address + netmask (will use and netmask: as example)
  • Your network address (If your IP is then your network address would be - The gateway's (Server) internal IP address (will use as example)
  • Your DNS (usually same as the gateway) internal IP address (will use
  • and finally, ask him if he uses a proxy server, write down it's IP address and port if the ISP uses one. (Will use port 8080 as example; don't get shocked if the proxy's ip address is the same as the gateway and/or DNS).
You also need to know the following:
  • Path for Ifconfig
  • Path for Route
To do that do the following, open a terminal and write down:
haytham@sadusbox:/$ whereis ifconfig && whereis route

You'll get something similar to:
haytham@sadusbox:/$ whereis ifconfig && whereis route
ifconfig: /sbin/ifconfig /lib/ifconfig ...
route: /sbin/route /usr/share/man....

We're just interested in these:
ifconfig: /sbin/ifconfig
route: /sbin/route

Now that you gathered enough information, open your favorite editor,
(will use VIM here, know how to use your editor for the following commands, open,
save as, close)

Write down what is written in the box, and change the variables to your needs
(Variables start from the START EDIT comment to the END EDIT comment)

#-------START EDIT--------
#Setting some variables
echo "Setting Variables..."
#-------END EDIT--------

#Initialize external NIC IP address
echo "Initialize external NIC ($NICNAME) IP address"

#Setting Network and Gateway Settings
echo "Setting Network and Gateway Settings"

$ROUTE add default gw $GATEWAYIP eth0
$ROUTE add -host lo

#Adding a DNS server
echo "Adding a DNS"
echo " " > /etc/resolv.conf
echo nameserver $DNSIP > /etc/resolv.conf

#Detecting default route settings, this may take 5 seconds of wait
echo "Detecting pre-default route settings, this may take 5 seconds for probing"
$ROUTE | grep default

echo "..."
echo "Internet is enabled, happy surfing..."

Save this file as: in your /home/user/ directory and then set its 
permissions to 755 by doing the following command:
haytham@sadusbox:/$ chmod 755 /home/user/

You can now login as SuperUser and just write:
haytham@sadusbox:/$ su
root@sadusbox:/$ sh
Internet should be smiling at you. If your ISP uses a proxy server address don't
forget to add the proxy server's address ( and port 8080) inside your
favorite web browser so that you would be able to surf the pages and most importantly
in your .bashrc script so that it would let you connect to the proxy from bash.To do
that open with your favorite editor the file .bashrc and write the following in the
first lines:

export http_proxy=
export ftp_proxy=
Hope you enjoyed reading this comprehensive guide to help you connect to the Internet on Linux using your cable.

No comments:

Post a Comment