Linux Internet Connection



If you are running Ubuntu Linux, then there's a program running in the background called Network Manager that automatically configures your network connections. You will have to disable this Network Manager if you want to configure your connections manually at the command line:

sudo service network-manager stop
OK, now you can configure your connections manually. You can get a list of all network cards in your system by doing the following:

sudo ifconfig -a
Choose which network card you want to use. If you decide to use "wlan0", you need to enable it as follows:

sudo ifconfig wlan0 up
Before you can even think about connecting to the Internet, you need to make sure you can communicate with your local Ethernet network, also known as the LAN (Local Area Network).

To connect to a LAN using an Ethernet cable, all you need to do is simply plug the Ethernet cable into your computer, there's nothing more you need to do.

For a wireless connection however, you must associate with the access point. You associate with a WEP access point as follows:

sudo iwconfig wlan0 mode managed
sudo iwconfig wlan0 essid YourNetworkNameHere key 01234567
(If you want to connect to WPA, find out about "wpa_supplicant", it won't be discussed here)

So at this point, I'm going to assume you're connected to the Ethernet network. From this point on, everything works the same way for wired and wireless connections.

The next thing you want to do is set the following info for your connection:

If you're lucky, your network will contain a DHCP server which will set all this stuff for you automatically. Here's how you get the DHCP server to set everything for you automatically:
sudo dhclient wlan0
If the DHCP worked, then your internet connection should be ready to go.

However, if the DHCP didn't work, you have to set all this stuff manually :-D

So here goes. . .

Set your IP address and subnet mask:

sudo ifconfig wlan0 192.168.1.123 netmask 255.255.255.0
After having set your IP address and subnet mask, you should be able to communicate using the Internet Protocol with other computers on the same LAN. You can try ping another computer on the LAN:
ping 192.168.1.1
Next, to access the internet, you need to add an entry to your Routing Table which tells your computer where it should send packets that are destined for the internet. The router which provides a route to the internet is commonly referred to as the "default gateway". Here's how you set it:
sudo route add default gateway 192.168.1.1
Now you should be able to communicate using the Internet Protocol with computers all over the world. Try to ping a computer on the Internet:
ping 208.67.222.222
We're nearly finished. The next thing to do is provide your computer with a way of turning a website address like "www.virjacode.com" into an IP address. We use a thing called a DNS server to turn host names into IP addresses. There's a free DNS server on the internet called OpenDNS, and its IP address is 208.67.222.222. You set your computer to use this DNS server as follows:
sudo sh -c "echo nameserver 208.67.222.222 > /etc/resolv.conf"
All done. Now your Internet connection should be good to go. Try to ping the Virjacode web server:
ping virjacode.com
Finally, open up your web browser and type "virjacode.com" into the address bar and hit Return. With any luck, the Virjacode website will appear.

So altogether, those steps were:

sudo ifconfig wlan0 up
sudo iwconfig wlan0 mode managed
sudo iwconfig wlan0 essid MyNet key 01234567
sudo ifconfig wlan0 192.168.1.123 netmask 255.255.255.0
sudo route add default gateway 192.168.1.1
sudo sh -c "echo nameserver 208.67.222.222 > /etc/resolv.conf"
What might complicate things a little, is if you need to go through a proxy server. Going through a proxy server is not an Operating System setting, but rather a Web Browser setting. So if you're using Firefox, you need to go to: Edit->Preferences->Advanced, and then click on the "Settings" button beside where it says "Configure how Firefox connects to the Internet". This will bring up a dialogue box, and you enter your proxy settings in this dialogue box.

If you do have to go through a proxy server, then the DNS requests you make to 208.67.222.222 will more than likely be blocked, so you'll have to use a DNS server which exists on the LAN (the DNS server on the LAN usually has the same IP address as the default gateway).



Virjacode Home