Dushyant Tyagi - Linux Basic Networking
  Home
  Abt Dushyant
  Linux File System
  Linux Basic Networking
  Contact
  Ur's Feedback
  Poll / Vote
  Gallery

Linux Basic Networking

___________________________________________________________________________________________

Here we are going to discuss how to make your Linux box work in a network. We will try to learn every aspect of networking that is associated with the Linux. We will cover the procedures for starting and stopping the interfaces, and some basic routing principles.

Load the Necessary Drivers

An Operating system need to know the devices that are attached to the system to work properly. Device drivers are the piece of software that details the device's operational parameters. It needs to be loaded into the kernel before the devices will function effectively.

To load the device drivers automatically, they are placed into the /etc/modprobe.conf file so the modprobe application can load the drivers into the kernel in an intelligent fashion as required; normally by starting the network service.

Open the /etc/modprobe.conf to see your ethernet interface and it's aliases. Device drivers may be added manually as extra devices are installed latter.

Network Devices and It's Configuration

The configuration files  that initializes the network devices are located in the/etc/sysconfig/network-scripts directory, and can easily be edited to adjust the parameters for each device. A general setup of the eth0 ( the first ethernet card) looks like the fillowing. You need to open it in a text editor:

# vi /etc/sysconfig/network-scripts/ifcfg-eth0

# Internal Ethernet Device (STATIC)
DEVICE=eth0
TYPE=Ethernet
IPADDR=192.168.0.1
NETMASK=255.255.255.0
ONBOOT=yes
USERCTL=no
BOOTPROTO=static
PEERDNS=no
HWADDR=00:0D:61:67:D0:B2
IPV6INIT=no


Here,

ONBOOT
Specifies whether the devices should start when the system starts (depending on network service)
USERCTL
Directs that only root, or all system users can control the device
BOOTPROTO
The protocol type used to initialise the device (static | dhcp | none)
PEERDNS
Import the DNS nameserver settings into /etc/resolv.conf (careful if running own DNS)
HWADDR
Binds the physical MAC address of the device - see caution below

The /etc/sysconfig/network file contains basic information about the network in general. The GATEWAYDEV variable should specify which network device will be the gateway to the Internet when the network is fully functional. Open the file in a editor

# vi /etc/sysconfig/network

# Network Details
NETWORKING=yes
HOSTNAME=mybox.example.com
GATEWAYDEV=eth1


Here I have assumed that, our gateway will be on another interface eth1 (Second ethernet interface of the same box). The system being used as the gateway server will require at least two networking devices if the internal (private) network is going to be separated from the Internet, this will maintain a level of security for the private network. The external device may be another network card, broadband DSL/Cable modem, or other capable device. The second interface will be almost same except the the MAC address and the IP. It will be different.

Starting the Interface


After the networking devices have been configured on the system, its time to start the interfaces to test if they are functioning properly. Network devices can be brought to the 'up' (active) state by using either of the following two commands if assigned a static IP address.

# ifup eth0
# ifconfig eth0 up

If we need to get our IP address dynamically, we can do the following.

# ifup eth0
# ifconfig eth0 dynamic up

The devices can also be put in the 'down' (inactive) state using either of these two commands:

# ifdown eth0
# ifconfig eth0 down

If all the procedures are fine then you can verify the /var/log/messages file to see if the interface is working fine or not. Type the 

# ifconfig eth0

to see if the device got its ip or not and ping to a different system to get a response.

If you have configured everything properly and think that everything is fine then there is another point you must be careful about. Make sure that the networking is up each and every time you reboot. To make sure type

# chkconfig --level 2345 network on
# service network restart

If you want to configure your eth0 with a static ip through command line type:

# ifconfig eth0 inet 192.168.0.1 broadcast 192.168.0.255 netmask  255.255.255.0 up
# service network restart

Alternatively you can type 

# netconfig

to get a graphical screen to configure. Do not forget to restart the network after your configuration. 

If you are confused about the details that you need to put here, there is another solution to that. To know about various parameters about the ethernet interface, type the following to learn more,

To know about the default subnet mask for an IP address :

# ipcalc -m  <your-ip-address>

To know about the  the network address :

# ipcalc -n  <your-ip-address> <your-subnet-mask>

To know the broadcast address of the network :

# ipcalc -b  <your-ip-address> <your-subnet-mask>

IP Routing table

Before you send a letter to your mate, you must write the destination address on the front of the envelope so that postal workers know where it needs to be sent. You also need to place your own address on the back of the envelope so the sender can reply to your letter, or in case it needs to be returned for some reason.

Sending packets of information across the Internet is based on the same principle; the packets need a destination and source address so the communicating entities can exchange data. When your local workstation sends a packet of information, it checks its local routing table to see if the packet's destination address is directly connected to any of its interfaces, if so it sends the packet directly out the correct interface and onto that host. If the packet is not destined for the local network, then the workstation searches the routing table for a routing device (gateway) that will take the packet for further processing; possibly outside and off to the Internet. If a gateway does not exist in the routing table, then the local workstation has no option but to reject sending the packet because it does not know where to send it.

Below is a basic diagram showing a server with two network devices, each connected to separate networks; eth0 to the private internal network, and eth1 to the ISP which is connected to the Internet.

                            /-----------------------\
 /-----------------\ | Server (Routing) | /-----------------\
 | Private Network |------| eth0 : 192.168.0.1 | | ISP Connection |
  | 192.168.0.0/24 | |-----------------------| | REMOTE IP ADDR |---> INTERNET
  \-----------------/ | 220.224.98.56 : eth1 |------| 220.224.98.99 |
\-----------------------/ \-----------------/

If the server need to send a packet to the 192.168.0.9, it will deliver the packet out eth0 directly to the host in the private network. However, if the server now needs to send a packet to the 12.12.xxx.xxx network, then it can not decide which interface to send the packet, so it will be rejected.

At this point of time we can see that there is no gateway defined in the system by seeing the kernel routing table.

# route -n

Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
10.214.64.0     0.0.0.0         255.255.255.0   U     0      0        0 eth1
192.168.0.0     0.0.0.0         255.255.255.0   U     0      0        0 eth0
169.254.0.0     0.0.0.0         255.255.0.0     U     0      0        0 eth0

This can be fixed by providing the routing table with a known gateway device using the following command.

# route add default gw 220.224.98.99 dev eth1

Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
10.214.64.0     0.0.0.0         255.255.255.0   U     0      0        0 eth1
192.168.1.0     0.0.0.0         255.255.255.0   U     0      0        0 eth0
169.254.0.0     0.0.0.0         255.255.0.0     U     0      0        0 eth0
0.0.0.0         220.224.98.99   0.0.0.0         UG    0      0        0 eth1      <-- Default Gateway

Now the system has been configured with a gateway device, so any packet of information that will not be delivered locally, will be transferred to the ISPs router at 220.224.98.99 for further processing. The ISPs router will then check its routing table and so forth through the Internet until the packet reaches its final destination.

During the configuration of the global network settings, each attached device (ethernet, modem, etc..) can be configured to act as a default gateway when the device is in the active state.


This is an introductory document to learn about the  GNU/Linux Basic Networking. This document brings together the information you will need to get started. After reading this, you should have clear idea of what is possible, what is available and how to configure.

There are things that must be omitted to keep this simple and manageable. If you have any comments, suggestions, or corrections, I would appreciate hearing from you. 

You can contact me through dushyant.tyagi@gmail.com. Please let me know about any error you find, as well as suggestions

Today, there have been 1 visitors (7 hits) on this page!
This website was created for free with Own-Free-Website.com. Would you also like to have your own website?
Sign up for free