3. Debian Networking

3.1. Topics

  • Overview of network protocols and TCP/IP in Linux.

  • Network configuration in Linux.

  • Network applications and services.

  • Network calculation with ipcalc

  • Sniffing network traffic with tcpdump


3.2. Computers on the intertnet

  • Network communication allows sending information, transfering files, and managing applications remotely between computers.

  • Networks are organized in a series of layers implemented on each machine.

  • The layers are independent and each layer offers a specific task to the neighboring layers above and below.

  • The communication between the layers is based on defined rules and procedures, called protocols.

  • Data is processed and passed through the layers from above to below, until the bottom layer is reached.

  • At the bottom layer, computers communicate with each other via sending and receiving network datagrams through - cables, switches and routers.


3.3. TCP/IP 5 layer protocol suit

Each layer has its own task:

TCP/IP Protocol Layer

Tasks

5. Application Layer: ssh, ftp, http …

Data segmentation by the application into Message Transfer Unit (MTU) segments. Typical MTU is 1.5 Kbyte

4. Transport Layer: TCP, UDP, ports

Connection management, quality, and ports to the applications

3. Internet Layer: IP addresses, subnets, routing

Addressing: each computer has a unique address on its network or subnet. Routing between networks.

2. Link Layer: Ethernet

Communication on the local network (subnet) through a switch. Media Access Card (MAC) address unique on the subnet. For example, 48:d2:4f:f4:d:fb, should be unique within a subnet. Address Resolution Protocol (ARP) matches the IP address to MAC on the subnet.

1. Physical Layer: NIC, hubs, switches, routers, cabling, wifi APs and cards

Electronic devices to send and receive signals between computers.


3.4. OSI 7 layer Network Stack Model

TCP/IP Protocol Layer

Task

7. Application Layer: ssh, ftp, http …

Data segmentation by the application into Message Transfer Unit (MTU) segments. Typical MTU is 1.5 Kbyte

6. Presentation Layer: SSL, libz, XDR

Data encryption, compression, and encoding/decoding

5. Session Layer: Remote Procedure Call (RPC)

Responsible for opening, using and closing sessions. Remote procedures.


3.5. TCP/IP and Kernel

The Link, Internet and Transport layers are implemented through kernel.


3.6. Packet Encapsulation

Data is processed in form of packet encapsulation and transmitted/received in form of Ethernet frames.


3.7. Hosts communication via TCP/IP


3.8. Wired connection checkup (Exercise)

  • Do these exercises on your node.

  • To see whether your node is connected to a network switch and at what speed, use command ethtool.

  • On your node, install package ethtool:

apt install ethtool
  • Also install package net-tools

apt install net-tools
  • See your network interfaces with command ifconfig or ip a:

ifconfig -a

or

ip a

The main network interface, connected to the Ethernet, is eno1. Run command below:

sudo ethtool eno1

In the output, among various parameters, the most important are:

  • Speed

  • Duplex

  • Link detected


3.9. Network IP configuration

  • Static configuration

    • IP address, gateway, and Dynamic Name Service (DNS) are configured on the host.

  • Dynamic Host Configuration Protocol (DHCP)

    • The settings are obtained from a DHCP server.


3.10. Environment for IP configuration on Debian, Ubuntu, and RedHat

ifupdown scripts

Network Manager service

Netplan networkd service Meaning

Old Debian/Ubuntu:

Ubuntu desktop, Debian:

Ubuntu server:

File: /etc/network/interfaces

Commands: nmtui, nmcli

File:/etc/netplan/00-installer-config.yaml

RedHat:

RedHat:

Command: netplan apply

File: /etc/sysconfig/network-scripts/ifcfg-ens3

File: /etc/sysconfig/network-scripts/ifcfg-ens3

Command:ifup ens3

Command: ifup ens3


3.11. Internet Control Message Protocol (ICMP) protocol (Exercises)

Implemented on hosts and gateways (routers) for:

Reporting the status of datagram processing. Diagnostics of connection and routing. Reporting errors in the processing of a datagram.

Example: ping

Exercise: command ping.

ping -c 5 node08
ping -c 5 engsoft.rutgers.edu
ping -c 5 google.com

If the systems respond, it means they are reachable on the network. Notice how varies the round-trip time and Time to Live (ttl) for packets between the hosts.

Example: traceroute

Time to leave (TTL) decrement. The TTL value of an IP packet represents the maximum number of IP routers that the packet can go through before being thrown away. You can expect each router in the Internet to decrement the TTL field by exactly one. The default TTL for traceroute on Linux is 30. It can be increased up to 255 maximum by using the -m command option.

Exercise: command traceroute.

sudo apt install traceroute
sudo traceroute lxc06
sudo traceroute engsoft.rutgers.edu
sudo traceroute google.com

This shows you all the gateways between the subnets your packet travels towards the destination. Notice the difference in the number of gateways between your desktop and the three remote hosts as well as the round trip times.


3.12. Network applications: ssh, sftp, scp, rsync (Exercises)

Configure SSH for private/public key authentication from the lxc container to the node. For SSH authentication, you can use either RSA or DSA public/private keys besides password. We’ll be using RSA in the exercises below. To generate an RSA key pair, type the following command at a shell prompt on your lxc:

ssh-keygen -t rsa

Accept the default file location of ~/.ssh/id_rsa. Enter a passphrase different from your account password and confirm it by entering it again. The public key is written to ~/.ssh/id_rsa.pub. The private key is written to ~/.ssh/id_rsa. Never distribute your private key to anyone. The contents of ~/.ssh/id_rsa.pub needs to be delivered onto the remote machine to which you want to connect, specifically the node, into file ~/.ssh/authorized_keys To accomplish the transfer task, here you can use one of the commands for file transfer. Commands scp and sftp come with ssh. We use interactive sftp command here, for example:

sftp  node03
Name (node03:hostadm): hostadm
sftp> cd .ssh
sftp> lcd .ssh
sftp> put id_rsa.pub authorized_keys
sftp>  quit

Command cd in the sftp> shell above is for stepping into the directory, .ssh, on the remote host, node03. Command lcd is for stepping into the directory, .ssh, on the local lxc server.

Now try to ssh to node03. You should be prompted to enter your passphrase.

If you have more than one key pair configured, you will be prompted for each one. When you log out, your passphrase(s) will be forgotten.

Run a remote command over ssh, for example:

ssh node08 "uname -a"

Beside sftp, command scp can be used for copying files from host to host. In scp, the first argument is the source_host:source_file, the second is destination_host:destination_dir. If the source_host or the destination_host is local, it is absent in the argumernt. The local directory is signified by .

Copy file /etc/hosts from lxc to the current directory on the node by using scp command:

scp node03:/etc/hosts .

Copy new file, somef.txt, from the local directory to the home directory on the node VM.

touch somef.txt
scp somef.txt node03:/home/$USER

You can also copy a group of files, for example, somef.txt and /etc/hosts, by placing them in block {}:

scp {somef.txt,/etc/hosts} node03:/home/$USER

Directories can be copied recursively with scp. For example, to copy /etc directory recursively from lxc to the user home directory on the node:

scp -r /etc node03:

Syncronizing directories between remote hosts by using rsync. This tool lets you copy files and directories between a local host and a remote host. Install rsync on both your lxc and the node:

apt-get install rsync

Creat a directory tree and copy it over to the node with rsync command.

mkdir -p dir1/dir2/dir3
rsync  -avz dir1 node03:/home/$USER

Option a stands for archive (preserve links and timestamps); v is for verbose and z is for data compression when sending-receiving.


3.13. Send/receive data with netcat (Exercises)

Netcat is a very useful tool to connect to any TCP and UDP port on a remote host, and send/receive data.

Step

On the node

On the LXC

1.

Install netcat: apt install netcat-traditional

apt install netcat-traditional

2.

Start netcat as a server, listening on port TCP/8080:

Connect to TCP/8080 port on node03:

netcat -l -p 8080

netcat node03  8080

3.

When the session is over, type Ctrl-C to stop the netcat server.

Start typing text. Hit ENTER key. The text should appear on the both terminals. Press Ctrl+D to close the UDP connection.

4.

Start the server on TCP/8080 to write into a file, outputfile.txt

Send file /etc/hosts to TCP/8080 on node03 via netcat

netcat -w 1 -l -p 8080 > outputfile.txt

netcat node03  8080 < /etc/hosts

5.

After the file is received, the connection closes itself. Check the content of the file:

less outputfile.txt


3.14. Subnets and routing

Example: Host A can communicate with both the hosts - B and C. Hosts B and C can’t communicate with each other. What is the problem?
Answer: the routing (gateway) is not defined on Host B.

3.15. Network calculation, gateway and routing

  • Computers connected to the same switch are on the same network/subnet and communicate with each other directly through the switch.

  • For computers located on the different networks/subnets, gateway/router is needed.

  • To define the local subnet, netmask is used.

  • Subnet mask defines the network and the host parts of the IP address

Network address = Host address (logical AND) Netmask:

Address

Decimal/Hexadecimal

Binary

IP address

192.168.5.10

11000000 10010100 00000101 00001010

Netmask

255.255.255.0

11111111 11111111 11111111 00000000

Network address

192.168.5.0

11000000 10010100 00000101 00000000

  • The network address is the smallest address on the network:

11000000 10010100 00000101 00000000 = 192.168.5.0

  • The broadcast address is the largest address on the network:

11000000 10010100 00000101 11111111 = 192.168.5.255

  • Max number of hosts on the subnet: 254 = 256 - 2 The gateway address should be on the same subnet with the host


3.16. IP calculator exercises

Network IP calculations with ipcalc On the LXC container, install ipcalc by using APT:

apt-get install ipcalc

Run ipcalc for network address 192.168.5.0 with subnet mask 255.255.255.0.

ipcalc 192.168.5.0/255.255.255.0

See the output for Address, Netmask, Network, HostMin, HostMax, Broadcast, Hosts/Net. Notice the same results for the same network and the different representation of the netmask:

ipcalc 192.168.5.0/24

Notice the same results for Netmask, Network, HostMin, HostMax, Broadcast, Hosts/Net if using the different IP addresses within the same network in ipcalc, for example:

ipcalc 192.168.5.15/24
ipcalc 192.168.5.34/24

Run ipcalc for subnets (networks) 192.168.5.0/25 and 192.168.5.128/25:

ipcalc 192.168.5.0/25
ipcalc 192.168.5.128/25

Notice the values for HostMin and HostMax in both the cases. By looking at the ranges [HostMin, HostMax], you can see, for example, that IP address 192.168.5.5 belongs to the first subnet and 192.168.5.250 to the second. You can verify that by running ipcalc on the IP addresses above and then comparing the Network values:

ipcalc 192.168.5.5/25
ipcalc 192.168.5.250/25

3.17. tcpdump command to see the traffic on NIC (Exercises)

When you need to see all the network traffic on a network card, you can run the command for the network interface. It helps to identify the subnet your system is connected to, and see all the active traffic.

On node03, install tcpdump:

apt install tcpdump

Run command tcpdump on the ethernet interface:

tcpdump -v -n -i eno1

On the LXC, start pingin the IP address of the node:

ping node03

See the output in tcpdump on the node. It should show some traffic related to echo request and reply from the LXC:

    192.168.5.103 > 192.168.5.3: ICMP echo request ...
    192.168.5.3 > 192.168.5.103: ICMP echo reply ...