A few words of thanks would be greatly appreciated.

Setting up a TCP/IP network on Linux


This article describes the implementation of a TCP/IP network for all Linux distributions. It does not address the implementation of network startup files.

Assigning the hostname

For most network applications, it is often important to define a hostname.
For this you can use the hostname command:
hostname YourMachine

For example
hostname Jak

(Where "Jak" is the name of my machine)

Assigning IP addresses

First you shall ask yourself what you intend to do with this network and how users it can support. Indeed the number of client determines the IP address range to choose from.
  • Class C (less than 255 clients): - :
  • Class B (less than 65535 clients): - :
  • Class A (more than 65535 clients): - :

Note that: If you simply want to configure networks applications, without any clients on the same network. You can use the loopback interface (

The loopback interface

Now we will configure your network. All the commands must be entered as root:
On most Linux distributions, the loopback interface is already configured. You can check it using the following command:
# /sbin/ifconfig

The following shall be displayed:
# ifconfig lo
lo		Link encap Local loopback
		  inet addr Bcast [NONE SET] Mask
		  RX packets 0 errors 0 dropped 0 overrun 0
		  TX packets 0 errors 0 dropped 0 overrun 0

Otherwise use this command:
# ifconfig lo

We must now enter this interface in the routing table
# route add

Now that the loopback interface is configured, test it using the ping command:
# ping
PING localhost ( 56 data bytes
64 bytes from icmp_seq=0 ttl=32 time=1 ms
64 bytes from icmp_seq=0 ttl=32 time=0 ms

Your loopback interface is properly configured.

The Ethernet interface

The configuration of the Ethernet interface make use of the same tools and the same methods as the Loopback interface.
We will configure this interface with a class C for 254 clients.
But you can change the IP address according to the table mentioned above. Before you do this, you must insert network module corresponding to your network card.
# ifconfig eth0 netmask

# /sbin/ifconfig eth0
eth0	  Link encap:Ethernet  HWaddr 00:01:03:48:77:56
		  inet addr:  Bcast:  Mask:
		  UP BROADCAST RUNNING  MTU:1500  Metric:1
		  RX packets:0 errors:0 dropped:0 overruns:1 frame:0
		  TX packets:0 errors:0 dropped:0 overruns:0 carrier:4
		  collisions:0 txqueuelen:0
		  Interrupt:11 Base address:0x1000

We must add the ethernet interface in the routing table:
# route add -net

You should already see the "lo" (loopback) interface: ifconfig lo
# ping
1 packets transmitted, 1 packets received, 0% packet loss
rOund-trip min/avg/max = 0.1/0.1/0.1 ms
bash-2.04$ ping
PING ( 56 data bytes
64 bytes from icmp_seq=0 ttl=128 time=0.5 ms
64 bytes from icmp_seq=1 ttl=128 time=0.3 ms
--- ping statistics ---
2 packets transmitted, 2 packets received, 0% packet loss
round-trip min/avg/max = 0.3/0.4/0.5 ms

Your interfaces are now configured correctly.
You can now edit your /etc/hosts file:
#Start of /etc/hosts. localhost Albert.einstein.net Albert
#End of file /etc/hosts.

Try to:
# ping localhost
# ping Jak

Orginal document published by Rémy Pouchain on CommentcaMarche.net

A few words of thanks would be greatly appreciated.

Ask a question
CCM is a leading international tech website. Our content is written in collaboration with IT experts, under the direction of Jeff Pillou, founder of CCM.net. CCM reaches more than 50 million unique visitors per month and is available in 11 languages.


This document, titled « Setting up a TCP/IP network on Linux », is available under the Creative Commons license. Any copy, reuse, or modification of the content should be sufficiently credited to CCM (ccm.net).