Implementing the Network¶
In this chapter you will learn how to work with and manage the network.
Objectives: In this chapter you will learn how to:
Configure a workstation to use DHCP;
Configure a workstation to use a static configuration;
Configure a workstation to use a gateway;
Configure a workstation to use DNS servers;
Troubleshoot the network of a workstation.
network, linux, ip
Knowledge:
Complexity:
Reading time: 30 minutes
Generalities¶
To illustrate this chapter, we will use the following architecture.
It will allow us to consider:
- integration in a LAN (local area network);
- the configuration of a gateway to reach a remote server;
- the configuration of a DNS server and the implementation of name resolution.
The minimum parameters to be defined for the machine are:
- the name of the machine;
- the IP address;
- the subnet mask.
Example:
pc-rocky
;192.168.1.10
;255.255.255.0
.
The notation called CIDR is more and more frequent: 192.168.1.10/24
IP addresses are used for the proper routing of messages (packets). They are divided into two parts:
- network bits - The part associated with consecutive "1s" in the binary subnet mask
- host bits - The part associated with consecutive "0s" in the binary subnet mask
|<- host bits ->|
|<-- network bits -->|
192.168.1.10 ==> 11000000.10101000.00000001.00001010
255.255.255.0 ==> 11111111.11111111.11111111.00000000
The subnet mask is used to define the network bits and host bits of an IP address. By using subnet mask, we can determine the current IP address:
- the network address (NetID or SubnetID) by performing a bitwise logical AND between the IP address and the mask;
- the host address (HostID) by performing a bitwise logical AND between the IP address and the complement of the mask.
192.168.1.10 ==> 11000000.10101000.00000001.00001010
255.255.255.0 ==> 11111111.11111111.11111111.00000000
NetID 11000000.10101000.00000001.00000000
192 . 168 . 1 . 0
HostID 00000000.00000000.00000000.00001010
0 . 0 . 0 . 10
Legitimate subnet mask - In order from left to right, consecutive 1s can be defined as valid subnet masks.
legitimate 11111111.11111111.11111111.00000000
illegitimate 11001001.11111111.11111111.00000000
Tip
The IP address and subnet mask must appear in pairs, which is determined by the basic principles of network communication.
There are also specific addresses within a network, which must be identified. The first address of a range as well as the last one have a particular role:
-
The first address of a range is the network address. It is used to identify networks and to route information from one network to another. This address can be obtained through Logic and Operations.
192.168.1.10 ==> 11000000.10101000.00000001.00001010 255.255.255.0 ==> 11111111.11111111.11111111.00000000 network address 11000000.10101000.00000001.00000000 192 . 168 . 1 . 0
Logic and Operations - When both are true (1), the result is true (1); otherwise, it is false (0)
-
The last address of a range is the broadcast address. It is used to broadcast information to all the machines on the network. Keep the network bits unchanged and replace all host bits with 1 to obtain the this address.
192.168.1.10 ==> 11000000.10101000.00000001.00001010 255.255.255.0 ==> 11111111.11111111.11111111.00000000 broadcast address 11000000.10101000.00000001.11111111 192 . 168 . 1 . 255
Tip
These two addresses that play special roles cannot be assigned to the terminal machine for use.
MAC address and IP address¶
A MAC address is a physical identifier written in the factory onto the device. This is sometimes referred to as the hardware address. It consists of 6 bytes often given in hexadecimal form (for example 5E:FF:56:A2:AF:15).
These 6 bytes respectively represent:
- The first three bytes represent manufacturer identifier . This identifier is called OUI (Organizationally Unique Identifier).
- The last three bytes represent the serial number allocated by the manufacturer.
Warning
The MAC address is hardcoded when the hardware leaves the factory. There are two main methods to modify it:
- Firmware-level modification (permanent): Requires advanced tools that can directly rewrite the MAC address in the network card's ROM. Such tools are typically only available to hardware manufacturers.
- Software-level spoofing (temporary): Modifies how the MAC address appears to the operating system. These changes are usually reset after a system reboot. The MAC address of the virtual network card in the virtual host is also implemented through spoofing.
An Internet Protocol (IP) address is an identification number permanently or temporarily assigned to each device connected to a computer network using the Internet Protocol. The IP address and subnet mask must appear in pairs, which is determined by the basic principles of network communication. Through the subnet mask, we can know the current IP address:
- network bits and host bits
- NetID or SubnetID
- HostID
- network address
- broadcast address
IP addresses are classified based on the version field in the packet as follows:
-
IPv4 - (4 bits, 0100). The available quantity of IPv4 is 232 (known from the source and destination address fields in IPv4 packets). Specifically divided into:
- Class A address. Its range is from 0.0.0.0 to 127.255.255.255
- Class B address. Its range is from 128.0.0.0 to 191.255.255.255
- Class C address. Its range is from 192.0.0.0 to 223.255.255.255
- Class D address. Its range is from 224.0.0.0 to 239.255.255.255
- Class E address. Its range is from 240.0.0.0 to 255.255.255.255
Among them, Class A addresses, Class B addresses, and Class C addresses all have their own private address ranges. 0.0.0.0 is a reserved address and is not assigned to the host. Class D addresses are used for multicast communication and are not assigned to hosts. Class E addresses are reserved and not used for regular networks.
-
IPv6 - (4 bits, 0110). The available quantity of IPv6 is 2128 (known from the source and destination address fields in IPv6 packets). Specifically divided into:
- Unicast address. Include Link-local unicast address (LLA), Unique local address (ULA), Global unicast address (GUA), Loopback address, Unspecified address
- Anycast address
- Multicast address
Description of writing format for 128 bits IPv6:
-
Preferred writing format - X:X:X:X:X:X:X:X. In this writing format, 128 bit IPv6 addresses are divided into 8 groups, each represented by 4 hexadecimal values (0-9, A-F), separated by colons (
:
) between groups. Each "X" represents a set of hexadecimal values. For example 2001:0db8:130F:0000:0000:09C0:876A:130B.- Omitting the leading 0 - For the convenience of writing, the leading "0" in each group can be omitted, so the above address can be abbreviated as 2001:db8:130F:0:0:9C0:876A:130B.
- Use double colon - If the address contains two or more consecutive groups that are both 0, a double colon can be used instead. So the above address can be further abbreviated as 2001:db8:130F::9C0:876A:130B. Attention! A double colons can only appear once in an IPv6 address.
-
Compatible with writing formats - X:X:X:X:X:X:d.d.d.d. In a mixed network environment, this format ensures compatibility between IPv6 nodes and IPv4 nodes. For example 0:0:0:0:0:ffff:192.1.56.10 and ::ffff:192.1.56.10/96.
In a web address or URL (Uniform Resource Locator), an IP address can be followed by a colon and the port address (which indicates the application to which the data is destined). Also to avoid confusion in a URL, the IPv6 address is written in square brackets (For example [2001:db8:130F::9C0:876A:130B]:443
).
As mentioned earlier, subnet masks divide IPv4 addresses into two parts: network bits and host bits. In IPv6, subnet masks also have the same function, but the name has changed ("n" represents the number of bits occupied by the subnet mask):
- Network prefix - It is equivalent to the network bits in an IPv4 address. According to the subnet mask, occupy "n" bits.
- Interface ID - It is equivalent to the host bits in an IPv4 address. According to the subnet mask, occupy "128-n" bits.
For example 2001:0db8:130F:0000:0000:09C0:876A:130B/64:
Network prefix
|<- 64 bits ->|
Interface ID
|<- 64 bits ->|
2001:0db8:130F:0000 : 0000:09C0:876A:130B
In the same network, IP addresses must be unique, which is a fundamental rule of network communication. In the same LAN (Local Area Network), the MAC address must be unique.
IPv4 packet structure¶
IPv4 packets contain both header and data parts:
Version: Help routers identify protocol versions. For IPv4, the value here is 0100 (Binary 0100 is equivalent to decimal 4)
IHL: A field used to control the length of the header. When the "Options" field is not included, the minimum value is 5 (Namely binary 0101), at this time, the head occupies 20 bytes. The maximum value is 15 (Namely binary 1111), and the length of the header is 60 bytes.
The actual length of IPv4 header = The value of the IHL field * 4
Type of Service: This field is used to define the QoS (Quality Of Service) and priority of data packets. This field is now mainly used for DSCP (Differentiated Services Code Point) and ECN (Explicit Congestion Notification).
Total Length: Represents the total length of the entire IPv4 datagram (IPv4 packet) in bytes.
Note
IP packet and IP datagram are technically different expressions of the same concept, both referring to data units transmitted at the network layer.
Identification: Identifies all fragments of an IPv4 datagram. All fragments from the same original datagram share the same Identification value to enable correct reassembly.
Flags: It is used to control the behavior of IPv4 datagram fragmentation. In order from left to right:
- The first bit - Not used, value 0
- The second bit - DF (Don’t Fragment). If DF=1, it means that the IPv4 datagram must be transmitted in its entirety. If it exceeds MTU, it is discarded and an ICMP error is returned (such as "Fragmentation Needed"). If DF=0, the router splits the IPv4 datagram into multiple fragments, each of which carries the same Identification field value
- The third bit - MF (More Fragment). If MF=1, it means that the current fragment is not the last one and there are other fragments; If MF=0, it means this is the last fragment
Fragment Offset: Indicate the relative position of the fragment in the original IPv4 datagram, in units of 8 bytes. This field is mainly used for fragment reassembly.
TTL (Time To Live): This field is used to limit the maximum survival time or maximum hop count of datagrams in the network. The initial value is determined by the sender, and the TTL decreases by 1 every time it passes through the router. When TTL=0, the datagram is discarded.
Protocol: Indicates the protocol type used by the data carried in this datagram. Its value range is 0-255.For example, the protocol number of TCP is 6, that of UDP is 17, that of ICMP is 1.
Header Checksum: This field will be recalculated every time the datagram passes through the router, mainly due to the decreasing TTL field causing changes in the header. This field only verifies the header (excluding the data part). If other fields remain unchanged and only the TTL changes, the checksum will be updated to a new value (non-zero) to ensure that the header has not been tampered with or damaged during transmission.
Source address: IPv4 address of the datagram sender
Destination address: IPv4 address of the datagram receiver
Options: Optional field, with a length range of 0-40 bytes. It is only used when the IHL is greater than 5. The length of this field must be an integer multiple of 4 bytes (if the length is less than 4 bytes, use the padding field for padding).
Tip
Bit has two meanings. In information theory, it refers to the fundamental unit of information, representing one binary choice (0 or 1). In computer science, it is the smallest unit of data storage, where 8 bits typically equal 1 byte unless specified otherwise.
IPv6 packet structure¶
IPv6 datagrams consist of three parts:
- Basic Header
- Extension Header
- Upper Layer Protocol Data Unit
In some books, the Extended Header and Upper Layer Protocol Data Unit are collectively referred to as the Payload.
The fixed length of the Basic Header is 40 bytes and it is fixed to 8 fields:
Version: Help routers identify protocol versions. For IPv6, the value here is 0110 (Binary 0110 is equivalent to decimal 6).
Traffic Class: Equivalent to the TOS (Type Of Service) field in IPv4 datagrams. This field is used to define the QOS (Quality Of Service) and priority of data packets.
Flow Label: This IPv6 new field is used to control packet flow. A non-zero value in this field means that the packet should be treated specially; i.e., the packet should not be sent through different routes to reach the destination but rather use the same path. An advantage to this is that the receiving end doesn’t have to reorder the package, thus speeding the process. This field helps avoid reordering data packets and is specifically designed for streaming media/live media.
Payload Length: Indicate the size of the payload. This field can only represent a Payload with a maximum length of 65535 bytes. In case the length of the payload is greater than 65535 bytes, then the payload length field will be set to 0 and the jumbo payload option is used in the Hop-by-Hop Options Extension Header.
Next Header: Used to indicate the type of packet header after the basic header. If there is a first extension header, it represents the type of the first extension header. Otherwise, it represents the protocol type used by the upper layer, such as 6 (TCP) and 17 (UDP).
Hop Limit: This field is equivalent to Time To Live (TTL) in IPv4 datagrams.
Source Address: This field represents the address of the IPv6 datagram sender.
Destination Address: This field represents the address of the IPv6 datagram receiver.
In IPv4 datagrams, the IPv4 header contains optional fields such as Options, which include Security, Timestamp, Record Route, etc. These Options can expand the length of the IPv4 header from 20 bytes to 60 bytes. During the forwarding process, handling IPv4 datagrams carrying these Options can consume a significant amount of device resources, so it is rarely used in practice.
IPv6 removes these Options from the IPv6 basic header and places them in the extension header, which is placed between the IPv6 Basic Header and the Upper Layer Protocol Data Unit.
An IPv6 packet can contain 0, 1, or multiple extension headers, which are only added by the sender when special processing is required by the device or destination node.
Unlike the IPv4 Options field (which can be extended up to 40 bytes and requires continuous storage), the IPv6 Extension Header adopts a chain structure and has no fixed length limit, making it more scalable in the future. Its 8 byte alignment mechanism is implemented through the Next Header field, which ensures processing efficiency and avoids fragmentation overhead.
Next Header: This field has the same function as the Next Header field in the Basic Header.
Extension Header Len: Indicate the length of the extension header (excluding the length of the Next Header).
Extension Head Data: The content of the Extension Header is a combination of a series of option fields and padding fields.
Currently, RFC defines the following types of Extension Headers:
- Hop-by-Hop Options header (Next Header Field Value is 0) - Must be handled by all routers in the path.
- Destination Options header (Next Header Field Value is 60) - Only processed by the destination node.
- Routing header (Next Header Field Value is 43) - This Extension Header is similar to the Loose Source and Record Route options in IPv4.
- Fragment header (Next Header Field Value is 44) - Like IPv4 packets, the length of IPv6 packets to be forwarded cannot exceed the maximum transmission unit (MTU). When the packet length exceeds the MTU, the packet needs to be fragmented. In IPv6, the Fragment header is used by an IPv6 source node to send a packet larger than the MTU.
- Authentication header (Next Header Field Value is 51) - IPSec uses this header to provide data origin authentication, data integrity check, and packet anti-replay functions. It also protects some fields in the IPv6 basic header.
- Encapsulating Security Payload header (Next Header Field Value is 50) - This header provides the same functions as the Authentication header plus IPv6 packet encryption.
RFC specifies that when multiple extension headers are used in the same datagram, it is recommended that these headers appear in the following order:
- IPv6 Basic Header
- Hop-by-Hop Options header
- Destination Options header
- Routing header
- Fragment header
- Authentication header
- Encapsulating Security Payload header
- Destination Options header
- Upper-layer protocol header
Except for the Destination Option Header which may appear once or twice (once before the Routing Extension header and once before the Upper-layer protocol header), all other extension headers can only appear once.
DNS Domain¶
Client machines can be part of a DNS (Domain Name System, e.g., mydomain.lan
) domain.
The fully qualified machine name (FQDN) becomes pc-rocky.mydomain.lan
.
A set of computers can be grouped into a logical, name-resolving, set called a DNS domain. A DNS domain is not, of course, limited to a single physical network.
In order for a computer to be part of a DNS domain, it must be given a DNS suffix (here mydomain.lan
) as well as servers that it can query.
Reminder of the OSI model¶
Memory aid
To remember the order of the layers of the OSI model, remember the following sentence: Please Do Not Touch Steven's Pet Alligator.
Layer | Protocols |
---|---|
7 - Application | POP, IMAP, SMTP, SSH, SNMP, HTTP, FTP, ... |
6 - Presentation | ASCII, MIME, ... |
5 - Session | TLS, SSL, NetBIOS, ... |
4 - Transport | TLS, SSL, TCP, UDP, ... |
3 - Network | IPv4, IPv6, ARP, ... |
2 - Data Link | Ethernet, WiFi, Token Ring, ... |
1 - Physical | Cables, optical fibers, radio waves, ... |
Layer 1 (Physical) supports transmission over a communication channel (Wifi, Optical fiber, RJ cable, etc.). Unit: the bit.
Layer 2 (Data Link) supports network topology (token-ring, star, bus, etc.), data splitting and transmission errors. Unit: the frame.
Layer 3 (Network) supports end-to-end data transmission (IP routing = Gateway). Unit: the packet.
Layer 4 (Transport) supports service type (connected or unconnected) encryption and flow control. Unit: the segment or the datagram.
Layer 5 (Session) supports the communication between two computers.
Layer 6 (Presentation) represents the area that is independent of data at the application layer. Essentially this layer translates from network format to the application format, or from the application format to the network format.
Layer 7 (Application) represents the contact with the user. It provides the services offered by the network: http, dns, ftp, imap, pop, smtp, etc.
The naming of interfaces¶
lo is the "loopback" interface which allows TCP/IP programs to communicate with each other without leaving the local machine. This enables testing if the network module of the system is working properly and also allows pinging the localhost. All packets that enter through localhost leave through localhost. The packets received are the packets sent.
The Linux kernel assigns interface names with a specific prefix depending on the type. Traditionally, all Ethernet interfaces, for example, began with eth. The prefix was followed by a number, the first being 0 (eth0, eth1, eth2...). The wifi interfaces were given a wlan prefix.
On Rocky8 Linux distributions, systemd will name interfaces with the new following policy where "X" represents a number:
enoX
: on-board devicesensX
: PCI Express hotplug slotenpXsX
: physical/geographical location of the connector of the hardware- ...
Using the ip
command¶
Forget the old ifconfig
command! Think ip
!
Note
Comment for administrators of older Linux systems:
The historical network management command is ifconfig
. This command has been replaced by the ip
command, which is already well known to network administrators.
The ip
command is the only command to manage IP address, ARP, routing, etc..
The ifconfig
command is no longer installed by default in Rocky8.
It is important to get into good habits now.
The hostname¶
The hostname
command displays or sets the host name of the system
hostname [-f] [hostname]
Option | Description |
---|---|
-f |
Displays the FQDN |
-i |
Displays the system's IP address information |
Tip
This command is used by various network programs to identify the machine.
To assign a host name, it is possible to use the hostname
command, but the changes will not be retained at the next boot. The command with no arguments displays the host name.
To set the host name, the file /etc/sysconfig/network
must be modified:
NETWORKING=yes
HOSTNAME=pc-rocky.mondomaine.lan
The RedHat boot script also consults the /etc/hosts
file to resolve the host name of the system.
When the system boots, Linux evaluates the HOSTNAME
value in the /etc/sysconfig/network
file.
It then uses the /etc/hosts
file to evaluate the main IP address of the server and its host name. It deduces the DNS domain name.
It is therefore essential to fill in these two files before any configuration of network services.
Tip
To know if this configuration is well done, the commands hostname
and hostname -f
must answer with the expected values.
/etc/hosts file¶
The /etc/hosts
file is a static host name mapping table, which follows the following format:
@IP <hostname> [alias] [# comment]
Example of /etc/hosts
file:
127.0.0.1 localhost localhost.localdomain
::1 localhost localhost.localdomain
192.168.1.10 rockstar.rockylinux.lan rockstar
The /etc/hosts
file is still used by the system, especially at boot time when the system FQDN is determined.
Tip
RedHat recommends that at least one line containing the system name be filled in.
If the DNS service (Domain Name Service) is not in place, you must fill in all the names in the hosts file for each of your machines.
The /etc/hosts
file contains one line per entry, with the IP address, the FQDN, then the host name (in that order) and a series of aliases (alias1 alias2 ...). The alias is an option.
/etc/nsswitch.conf
file¶
The NSS (Name Service Switch) allows configuration files (e.g., /etc/passwd
, /etc/group
, /etc/hosts
) to be substituted for one or more centralized databases.
The /etc/nsswitch.conf
file is used to configure the name service databases.
passwd: files
shadow: files
group: files
hosts: files dns
In this case, Linux will first look for a host name match (hosts:
line) in the /etc/hosts
file (files
value) before querying DNS (dns
value)! This behavior can simply be changed by editing the /etc/nsswitch.conf
file.
Of course, it is possible to imagine querying an LDAP, MySQL or other server by configuring the name service to respond to system requests for hosts, users, groups, etc.
The resolution of the name service can be tested with the getent
command that we will see later in this course.
/etc/resolv.conf
file¶
The /etc/resolv.conf
file contains the DNS name resolution configuration.
#Generated by NetworkManager
domain mondomaine.lan
search mondomaine.lan
nameserver 192.168.1.254
Tip
This file is historical. It is no longer filled in directly!
Newer generations of distributions have generally integrated the NetworkManager
service. This service allows you to manage the configuration more efficiently, either in graphical or console mode.
It allows for the addition of DNS servers from the configuration file of a network interface. It then dynamically populates the /etc/resolv.conf
file which should never be edited directly, otherwise the configuration changes will be lost the next time the network service is started.
ip
command¶
The ip
command from the iproute2
package allows you to configure an interface and its routing table.
Display interfaces:
[root]# ip link
Display interfaces information:
[root]# ip addr show
Display the information of an interface:
[root]# ip addr show eth0
Display the ARP table:
[root]# ip neigh
All historical network management commands have been grouped under the ip
command, which is well known to network administrators.
DHCP configuration¶
The DHCP protocol (Dynamic Host Control Protocol) allows you to obtain a complete IP configuration via the network. This is the default configuration mode of a network interface under Rocky Linux, which explains why a system connected to the network of an Internet router can function without additional configuration.
The configuration of interfaces under Rocky Linux is done in the /etc/sysconfig/network-scripts/
folder.
For each Ethernet interface, a ifcfg-ethX
file allows for the configuration of the associated interface.
DEVICE=eth0
ONBOOT=yes
BOOTPROTO=dhcp
HWADDR=00:0c:29:96:32:e3
- Interface name: (must be in the file name)
DEVICE=eth0
- Automatically start the interface:
ONBOOT=yes
- Make a DHCP request when the interface starts up:
BOOTPROTO=dhcp
- Specify the MAC address (optional but useful when there are several interfaces):
HWADDR=00:0c:29:96:32:e3
Tip
If NetworkManager is installed, the changes are taken into account automatically. If not, you have to restart the network service.
- Restart the network service:
[root]# systemctl restart NetworkManager
Static configuration¶
The static configuration requires at least:
DEVICE=eth0
ONBOOT=yes
BOOTPROTO=none
IPADDR=192.168.1.10
NETMASK=255.255.255.0
- Here we are replacing "dhcp" with "none" which equals static configuration:
BOOTPROTO=none
- IP Address:
IPADDR=192.168.1.10
- Subnet mask:
NETMASK=255.255.255.0
- The mask can be specified with a prefix:
PREFIX=24
Warning
You must use NETMASK OR PREFIX - Not both!
Routing¶
DEVICE=eth0
ONBOOT=yes
BOOTPROTO=none
HWADDR=00:0c:29:96:32:e3
IPADDR=192.168.1.10
NETMASK=255.255.255.0
GATEWAY=192.168.1.254
The ip route
command:
[root]# ip route show
192.168.1.0/24 dev eth0 […] src 192.168.1.10 metric 1
default via 192.168.1.254 dev eth0 proto static
It is a good idea to know how to read a routing table, especially in an environment with multiple network interfaces.
-
In the example shown, the
192.168.1.0/24
network is reachable directly from theeth0
device, so there is a metric at1
(does not traverse a router). -
All other networks than the previous one will be reachable, again from the
eth0
device, but this time the packets will be addressed to a192.168.1.254
gateway. The routing protocol is a static protocol (although it is possible to add a route to a dynamically assigned address in Linux).
Name resolution¶
A system needs to resolve:
- FQDNs into IP addresses
www.free.fr = 212.27.48.10
- IP addresses into names
212.27.48.10 = www.free.fr
- or to obtain information about an area:
MX de free.fr = 10 mx1.free.fr + 20 mx2.free.fr
DEVICE=eth0
ONBOOT=yes
BOOTPROTO=none
HWADDR=00:0c:29:96:32:e3
IPADDR=192.168.1.10
NETMASK=255.255.255.0
GATEWAY=192.168.1.254
DNS1=172.16.1.2
DNS2=172.16.1.3
DOMAIN=rockylinux.lan
In this case, to reach the DNS, you have to go through the gateway.
#Generated by NetworkManager
domain mondomaine.lan
search mondomaine.lan
nameserver 172.16.1.2
nameserver 172.16.1.3
The file has been updated by NetworkManager.
Troubleshooting¶
The ping
command sends datagrams to another machine and waits for a response.
It is the basic command for testing the network because it checks the connectivity between your network interface and another.
Syntax of the ping
command:
ping [-c numerical] destination
The -c
(count) option allows you to stop the command after the countdown in seconds.
Example:
[root]# ping –c 4 localhost
Tip
Validate connectivity from near to far
-
Validate the TCP/IP software layer
[root]# ping localhost
"Pinging" the inner loop does not detect a hardware failure on the network interface. It simply determines whether the IP software configuration is correct.
-
Validate the network card
[root]# ping 192.168.1.10
To determine the functionality of the network card, we must ping its IP address. If the network cable is not connected to the network card, it should be in a "down" state.
If the ping does not work, first check the network cable to your network switch and reassemble the interface (see the
if up
command), then check the interface itself. -
Validate the connectivity of the gateway
[root]# ping 192.168.1.254
-
Validate the connectivity of a remote server
[root]# ping 172.16.1.2
-
Validate the DNS service
[root]# ping www.free.fr
dig
command¶
The dig
command is used to query the DNS server.
The dig
command syntax:
dig [-t type] [+short] [name]
Examples:
[root]# dig +short rockylinux.org
76.223.126.88
[root]# dig -t MX +short rockylinux.org ✔
5 alt1.aspmx.l.google.com.
...
The dig
command is used to query DNS servers. It is verbose by default, but the +short
option can change this behavior.
It is also possible to specify a DNS record type to resolve, such as an MX type to get information about the mail exchangers for a domain.
getent
command¶
The getent
(get entry) command gets an NSSwitch entry (hosts
+ dns
)
Syntax of the getent
command:
getent hosts name
Example:
[root]# getent hosts rockylinux.org
76.223.126.88 rockylinux.org
Querying only a DNS server may return an erroneous result that does not consider the contents of a hosts
file, although this should be rare nowadays.
To take the /etc/hosts
file into account, the NSSwitch name service must be queried, which will take care of any DNS resolution.
ipcalc
command¶
The ipcalc
(ip calculation) command calculates the address of a network or broadcast from an IP address and a mask.
Syntax of the ipcalc
command:
ipcalc [options] IP <netmask>
Example:
[root]# ipcalc –b 172.16.66.203 255.255.240.0
BROADCAST=172.16.79.255
Tip
This command is interesting, followed by a redirection to fill in the configuration files of your interfaces automatically:
[root]# ipcalc –b 172.16.66.203 255.255.240.0 >> /etc/sysconfig/network-scripts/ifcfg-eth0
Option | Description |
---|---|
-b |
Displays the broadcast address. |
-n |
Displays the network address and mask. |
ipcalc
is a simple way to calculate a host's IP information. The various options indicate what information ipcalc
should display on the standard output. You can specify multiple options. You must specify an IP address on which to operate. Most operations also require a network mask or CIDR prefix.
Option short | Option long | Description |
---|---|---|
-b |
--broadcast |
Displays the broadcast address of the given IP address and the network mask. |
-h |
--hostname |
Displays the hostname of the IP address given via DNS. |
-n |
--netmask |
Calculates the network mask for the given IP address. Assumes that the IP address is part of a complete class A, B, or C network. Many networks do not use default network masks, in which case an incorrect value will be returned. |
-p |
--prefix |
Indicates the prefix of the mask/IP address. |
-n |
--network |
Indicates the network address of the given IP address and mask. |
-s |
--silent |
Does not display any error messages. |
ss
command¶
The ss
(socket statistics) command displays the listening ports on the network.
Syntax of the ss
command:
ss [-tuna]
Example:
[root]# ss –tuna
tcp LISTEN 0 128 *:22 *:*
The commands ss
and netstat
(to follow) will be very important for the rest of your Linux life.
When implementing network services, it is common to check with one of these two commands that the service is listening on the expected ports.
netstat
command¶
Warning
The netstat
command is now deprecated and is no longer installed by default on Rocky Linux. You may still find some Linux versions that have it installed, but it is best to move on to using ss
for everything that you would have used netstat
for.
The netstat
command (network statistics) displays the listening ports on the network.
Syntax of the netstat
command:
netstat -tapn
Example:
[root]# netstat –tapn
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 2161/sshd
IP or MAC address conflicts¶
A misconfiguration can cause multiple interfaces to use the same IP address. This can happen when a network has multiple DHCP servers, or the same IP address is manually assigned numerous times.
When the network is malfunctioning, and when an IP address conflict could be the cause, it is possible to use the arp-scan
software (requires the EPEL repository):
dnf install arp-scan
Example:
$ arp-scan -I eth0 -l
172.16.1.104 00:01:02:03:04:05 3COM CORPORATION
172.16.1.107 00:0c:29:1b:eb:97 VMware, Inc.
172.16.1.250 00:26:ab:b1:b7:f6 (Unknown)
172.16.1.252 00:50:56:a9:6a:ed VMWare, Inc.
172.16.1.253 00:50:56:b6:78:ec VMWare, Inc.
172.16.1.253 00:50:56:b6:78:ec VMWare, Inc. (DUP: 2)
172.16.1.253 00:50:56:b6:78:ec VMWare, Inc. (DUP: 3)
172.16.1.253 00:50:56:b6:78:ec VMWare, Inc. (DUP: 4)
172.16.1.232 88:51:fb:5e:fa:b3 (Unknown) (DUP: 2)
Tip
As the above example shows, MAC address conflicts are possible! Virtualization technologies and the copying of virtual machines cause these problems.
Hot configuration¶
The ip
command can hot add an IP address to an interface.
ip addr add @IP dev DEVICE
Example:
[root]# ip addr add 192.168.2.10 dev eth1
The ip
command allows for the activation or deactivation of an interface:
ip link set DEVICE up
ip link set DEVICE down
Example:
[root]# ip link set eth1 up
[root]# ip link set eth1 down
The ip
command adds a route:
ip route add [default|netaddr] via @IP [dev device]
Example:
[root]# ip route add default via 192.168.1.254
[root]# ip route add 192.168.100.0/24 via 192.168.2.254 dev eth1
In summary¶
The files used in this chapter are:
A complete interface configuration could be this (file /etc/sysconfig/network-scripts/ifcfg-eth0
):
DEVICE=eth0
ONBOOT=yes
BOOTPROTO=none
HWADDR=00:0c:29:96:32:e3
IPADDR=192.168.1.10
NETMASK=255.255.255.0
GATEWAY=192.168.1.254
DNS1=172.16.1.1
DNS2=172.16.1.2
DOMAIN=rockylinux.lan
The troubleshooting method should go from closest to farthest:
- ping localhost (software test)
- ping IP-address (hardware test)
- ping gateway (connectivity test)
- ping remote server (routing test)
- DNS query (dig or ping)