Basic Linux Networking

After installing a linux server and playing with the basic command lines, the first thing we should be able to do is configure our network, without which of course there is no Internet. Most of the latest linux distributions ship with easy to use GUI for configuration and testing of the network. But here we’ll be using all command lines. Remember, these commands directly talk to the responsible programs without any intermediary (GUI), so obviously it’s fast, more powerful and have many options that are not available in GUI.

This guide will help you to configure your network and troubleshoot simple network problems using command lines.


ifconfig
This command is used to configure or view the information of network interfaces. E.g. if you want to configure the interface eth0 with an ip address 192.168.1.45, you should use the following command:
Ifconfig-4

The other useful and simple use of ifconfig is done with the switch -a, which displays the state of all the interfaces. It lists all the informations you need to know about your network card. In the following example you can see Hardware Address (Hwaddr), IP Address (inet addr), Broadcast Address (Bcast), Subnetmask (Mask) and many more.
Ifconfig-A-2

route

The second thing we need to configure after the ip address is default route or gateway. The following command will add a default gateway 192.168.1.1, which is accessible via interface eth0.
Route-Add-2
The default gateway can be deleted just by substituting the add with del in the above command.

You can check the default gateway and the whole routing table by executing simple route command.
Route-2

resolv.conf

After setting up the ip address and the default gateway, final thing you need do is configure the DNS servers. The DNS server information is stored in a text file /etc/resolv.conf. You can use your favourite text editor (e.g. vi or emacs) to edit the file. Following is a sample resolv.conf file, where two (primary and secondary) DNS servers are listed:

nameserver 202.67.194.35
nameserver 203.161.246.124

That’s it, congratulations! You’ve configured the network of a linux server, which should allow to go to the Internet.
Sooner or later you’ll either need to check simple connectivity issues or troubleshoot serious network problems. Here are some very useful and basic diagnostic commands that can help you along the way.

ping
I think ping is one of the most useful and widely used commands to check network connectivity. This command is used to test whether a particular host is rechable over an IP network. Ping uses ICMP packets to send an “echo request”, and the receiving host is required to answer back using “echo reply”. If you cannot reach the internet, the first thing you should do is ping your default gateway to make sure that you get an icmp reply.
Ping-2

traceroute

While ping helps to check the connectivity between two hosts, traceroute actually show the route between them. It lists the nodes (hosts/routers) that your packet will travel through to reach the destination. If the ping shows some packet loss, looking at the output of traceroute we can figure out which hosts (routers) along the way have problems. This can be determined looking at the latency at each host. From the following traceroute we can see that to reach Google, the packet needs to travel through 5 hops (hosts/routers).
Traceroute-2

netstat
This command is very useful when you want to see where your server is connected to and also who is connected back to your server and services from outside. netstat prints the active network connections, routing tables, interface statistics, masquerade connections, and multiĀ­cast memberships. E.g. when it’s invoked with the switch -a, it lists all the active network connections and services that this server is listening to.
Netstat-2

nslookup
This command is used to test DNS servers and domain names. E.g when executed with switch -q=any, it provides the ip address of the domain name we’re querying about, the name servers responsible for this domain and other parameters such as TTL and contact email address of the administrator.
Nslookup-2

Be Sociable, Share!
Posted in Admin, HowTo, Linux/Unix, Network, Technology
0 comments on “Basic Linux Networking
1 Pings/Trackbacks for "Basic Linux Networking"
  1. Your Most Powerful Network Marketing Tool…

    The internet is full of millions of self replicated websites, and if you’re a Network Marketer you probably have one too! So how do YOU get noticed in this sea of duplicated websites?? Well to be absolutely truthful you do not! Have you noticed that p…

Leave a Reply

Your email address will not be published. Required fields are marked *

*

Recent Comments

Buddha Boy attacked and injured a guy with his sword? – Media on 'Buddha Boy' on Buddha Boy attacked and injured a guy with his sword?: […] http://nirlog.com/2007/07/20/buddha-boy-attacked-and-injured-a-guy-with-his-sword/ […]…(June 11, 2017, 11:54 am)
Shishir bhattarai on Mahabir Pun — the man who brought WiFi to Himalayas: I fell pride to him and…(June 7, 2017, 2:17 pm)
Shishir bhattarai on Mahabir Pun — the man who brought WiFi to Himalayas: I fell pride to him and thanks…(June 7, 2017, 2:15 pm)
The light of Asia on Meeting Buddha Boy: DeAnna, what are you taking about? What…(March 30, 2017, 5:27 pm)
The light of Asia on Meeting Buddha Boy: Religious person don’t rape their disciple or…(March 30, 2017, 5:03 pm)