Discovering the principles behind IPv4 addresses requires setting up
a minimal network architecture to serve as a basis for a few
experiments.
Here is the diagram of the architecture that you will build:
In a terminal on your host system, enter the command
s7nsa_hub_switch.py h:9991 h:9992 and leave this terminal
open.
You have just created the two virtual
hubs shown in the
diagram
The use of hubs is now an obsolete practice, but it is retained in
this tutorial to make experimentation easier.
Later in this tutorial, these hubs will be turned into switches;
these are the more modern devices that have replaced hubs.
.
The numbers associated with them do not correspond to anything in practice;
they can be regarded as labels attached to the casing of these devices
to distinguish them.
In another terminal on your host system, enter the following commands,
taking care not to swap the arguments
In a physical environment, this would be equivalent to crossing
cables and therefore not following the diagram.
:
- s7nsa_machine.py A1A2 9991 9992:
the virtual machine named A1A2 is created,
its first network interface (eth0) is connected to the
hub labelled 9991,
its second network interface (eth1) is connected to the
hub labelled 9992.
- s7nsa_machine.py B1 9991:
the virtual machine named B1 is created,
its network interface (eth0) is connected to the
hub labelled 9991.
- s7nsa_machine.py B2 9992:
the virtual machine named B2 is created,
its network interface (eth0) is connected to the
hub labelled 9992.
- s7nsa_machine.py C1 9991:
the virtual machine named C1 is created,
its network interface (eth0) is connected to the
hub labelled 9991.
- s7nsa_machine.py C2 9992:
the virtual machine named C2 is created,
its network interface (eth0) is connected to the
hub labelled 9992.
In the terminal that was used to create the hubs, enter the command
list and verify that each of the two hubs is indeed connected
to three cables, as shown in the diagram.
Note that the dotted lines in the diagram suggest that it would be possible
to connect many more devices to these hubs.
Log in to each of these five virtual machines and, on each of them, enter
the command
ip addr.
You should find the network interfaces named
eth0 or
eth1
On systems used in practice, the naming of network interfaces is
generally very different.
To make this series of tutorials easier to understand, the virtual
machines have been configured to use the naming convention eth0,
eth1, eth2... according to the order of the virtual cables
specified on the command line.
as shown in the diagram:
B1,
C1,
B2, and
C2 each
have an
eth0 interface, while
A1A2 has the
eth0 and
eth1 interfaces.
Also note that all these machines have an additional interface named
lo:
the
“loopback” interface.
In general, network devices designed to use
IP addresses include such
an interface, which is not connected to any other device and is configured
as
127.0.0.1/8.
The
“loopback” interface is used to allow applications on a single machine
to communicate with each other as though they were interacting remotely
over the network; they refer to each other using the address
127.0.0.1, which corresponds to the local machine.
Using the command
ping 127.0.0.1, you should observe that each system
responds to itself; stop this command with the
Ctrl c key
combination.
The
ip addr command showed that, unlike the
lo interface, none of
the
eth0 or
eth1 network interfaces on your machines had yet
been assigned an
IP address.
On your
A1A2 machine, configure the
eth0 and
eth1 network
interfaces as follows
For convenience, these lines can be edited in a
SHARED/script.sh file on the host system and then executed
with bash SHARED/script.sh from the virtual machine.
:
cat <<EOF >>/etc/custom/10_network_setup.sh
ip addr add 192.168.10.1/24 dev eth0
ip addr add 192.168.20.1/24 dev eth1
EOF
/etc/custom/10_network_setup.sh
Immediately check with
ip addr that the addresses chosen in the diagram
have been correctly assigned to the interfaces.
Use the same approach to configure:
- the eth0 interface of B1 with 192.168.10.2/24,
- the eth0 interface of B2 with 192.168.20.2/24,
- the eth0 interface of C1 with 192.168.10.3/24,
- the eth0 interface of C2 with 192.168.20.3/24,
and verify with
ip addr that all these interfaces are configured
according to the diagram.
From the
C1 machine, use
ping 192.168.10.3 to verify that it
responds to itself using the address that has just been assigned to
it
You can, of course, do the same with each of your machines.
.
Then use
ping 192.168.10.2 and
ping 192.168.10.1 to
verify that the three IP addresses assigned to the devices connected to
hub
9991 can all reach each other.
Use a similar approach to verify connectivity between the three addresses
assigned to the devices connected to hub
9992.