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:
(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): 192.168.0.0 - 192.168.255.0 : 255.255.255.0
- Class B (less than 65535 clients): 172.16.0.0 - 172.31.0.0 : 255.255.0.0
- Class A (more than 65535 clients): 172.16.0.0 - 172.31.0.0 : 255.255.0.0
Note that: If you simply want to configure networks applications, without any clients on the same network. You can use the loopback interface (127.0.0.1).
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:
The following shall be displayed:
# ifconfig lo
lo Link encap Local loopback
inet addr 127.0.0.1 Bcast [NONE SET] Mask 255.0.0.0
UP BROADCAST LOOPBACK RUNNING MTU 2000 Metric 1
RX packets 0 errors 0 dropped 0 overrun 0
TX packets 0 errors 0 dropped 0 overrun 0
Otherwise use this command:
# ifconfig lo 127.0.0.1
We must now enter this interface in the routing table
# route add 127.0.0.1
Now that the loopback interface is configured, test it using the ping command:
# ping 127.0.0.1
PING localhost (127.0.0.1): 56 data bytes
64 bytes from 127.0.0.1: icmp_seq=0 ttl=32 time=1 ms
64 bytes from 127.0.0.1: 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 192.168.0.1 netmask 255.255.255.0
# /sbin/ifconfig eth0
eth0 Link encap:Ethernet HWaddr 00:01:03:48:77:56
inet addr:192.168.0.1 Bcast:192.168.0.255 Mask:255.255.255.0
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
Interrupt:11 Base address:0x1000
We must add the ethernet interface in the routing table:
# route add -net 192.168.0.0
You should already see the "lo" (loopback) interface: ifconfig lo 127.0.0.1
# ping 192.168.0.1
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 192.168.0.1
PING 192.168.1.223 (192.168.0.1): 56 data bytes
64 bytes from 192.168.0.1: icmp_seq=0 ttl=128 time=0.5 ms
64 bytes from 192.168.0.1: icmp_seq=1 ttl=128 time=0.3 ms
--- 192.168.0.1 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.
192.168.0.1 Albert.einstein.net Albert
#End of file /etc/hosts.
# ping localhost
# ping Jak
Orginal document published by Rémy Pouchain
Published by jak58
Latest update on April 22, 2013 at 07:18 AM by jak58.