🌐 🇵🇱 Polski · 🇬🇧 EN
Sometimes network issues arise, and the information available from the system is insufficient. In such cases, more detailed data about what is happening on the network is needed. The best approach is to use a packet capture tool to see all the raw data transmitted through the machine's interfaces. The "tcpdump" tool will help with this.
tcpdump command syntax: # tcpdump [options]
tcpdump command options
- -i INTERFACE - Details regarding the listening interface
- -r FILE - Details regarding captured packets read from a file
- -w FILE - Definition of the file to save console output
For example, if we want to check if the system is correctly resolving DHCP addresses, we can monitor connections from the eth0 interface and verify if the DHCP server is responding correctly.
Step 1 - Run the tcpdump command and define which interface should be examined. Let's save the data to a file.
# tcpdump –i eth0 –w pkt_capture
Step 2 - While packet capturing is enabled, from a new console, invoke the dhclient tool to request a new IP address from the DHCP server.
# dhclient
Step 3 - After the new IP address request is complete, return to the first console and stop the tcpdump tool using Ctrl+C. You can now review the information by invoking the tcpdump tool again:
# tcpdump –r pkt_capture | less
DNS CONFIGURATION AND TROUBLESHOOTING
DNS CONFIGURATION AND TROUBLESHOOTING
While working with IP addresses and assigning them to machines is fine, it becomes somewhat impractical if we have to do it for a larger number of machines (servers and clients). Instead, you can use hostnames (system names), which can be used in place of IP addresses. Searching for and translating a hostname to an IP address will be performed automatically thanks to the DNS server located on your network. The topic discussed here does not cover DNS in its entirety; instead, it focuses on DNS client-side issues and how to resolve them. There are several files in the system responsible for DNS name resolution, and they are:
- /etc/sysconfig/network - contains the system's host name
- /etc/resolv.conf - Contains the IP address of the DNS server
- /etc/hosts - Contains local mapping of IP addresses to hostnames
- /etc/nsswitch.conf - Contains the order in which local accounts query the DNS server
Along with these files, there are also several commands we can use on the client side:
- hostname - Sets or returns the system's hostname
- nslookup - Query the domain name where the system is located
- ping - Test the connection between two systems
When DNS problems occur, it is usually clear what we are dealing with because an appropriate error message informs us, e.g., "Can't be resolved" or "Unable to lookup". Although a given message does not always point to the solution, it is a good hint on where to start searching for the error and fixing it.
Let's check the hostname of the system we are on:
# hostname
RHEL01
We can also obtain hostname information from the /etc/sysconfig/network file
# cat /etc/sysconfig/network
NETWORKING=yes
NETWORKING_IPV6=no
HOSTNAME=RHEL01
You can edit this file if you want to change the system's hostname. If you need to use a Fully Qualified Domain Name (FQDN), you do so in this file as well. You can use RHEL01.example.com as the full domain name for RHEL01. If you know the system's hostname, you should enforce the setting of where the server should send a query if it needs to know the name of another host. Two files contain information enabling DNS lookups:
- /etc/hosts
Structure of the /etc/hosts file :
<IP> <fully qualified domain name> <alias>
Let's see the current /etc/hosts file :
# cat /etc/hosts
# Do not remove the following line, or various programs
# that require network functionality will fail.
127.0.0.1 RHEL01 RHEL01 localhost.localdomain localhost
::1 localhost6.localdomain6 localhost6
We can see that at the moment, there is nothing in the file other than local entries. However, if a small environment (five or more machines) is running, using /etc/hosts will make more sense. You will need to add entries for each machine (remembering that this file is located locally on the machine). Here you can immediately see that such an approach can quickly get out of control, especially if you had to update the /etc/hosts file on many machines. Therefore, it becomes logical to use a DNS server to which queries will be directed instead of the local /etc/hosts file. The DNS server address is contained in the /etc/resolv.conf file. This solution allows querying the DNS server in the same way as with the local /etc/hosts file.
Let's see what the /etc/resolv.conf file currently looks like :
# cat /etc/resolv.conf
; generated by /sbin/dhclient-script
nameserver 172.168.1.1
The result of this command shows that the RHEL01 machine sends all DNS queries to the DNS server at address 172.168.1.1, i.e., to itself. Although we do not have a DNS server installed yet, this exercise will show how to configure the client correctly. The /etc/resolv.conf file can also look like this:
# cat /etc/resolv.conf
search example.com
nameserver 192.168.1.1
nameserver 172.168.1.1
The search option specifies the domain name that will be searched by default. If a client machine is trying to gain access and the hostname is not qualified as RHEL01.example.com, and the DNS server returns an error stating it could not find the host, let's try adding the domain option to the search. This is a typical configuration when client machines belong to a domain. Secondly, let's look at the list of servers available in the second DNS server if a given name is not available in the first one.
Okay, we have the /etc/hosts and /etc/resolv.conf files configured. Now the question surely arises: where does the client query first? Naturally, there is a third file defining the search order in a single line. This file can be one of the last two, but it is usually the latter.
Older file :
# cat /etc/host.conf
order hosts,bind
Newer file :
# cat /etc/nsswitch.conf | grep hosts
hosts: files dns
By default, the nsswitch.conf file is used, and for good reason. Sometimes in a specific environment, we want to look up a specific host and connect to it, and there is no need for all other hosts on the network to see it; for this purpose, we can easily use /etc/hosts. Once all files have been configured correctly, you can start testing whether names are being resolved correctly. The test can be performed in two ways - the first is using the "ping" command from one host to another, the next way is the "nslookup" command, querying for an IP address and receiving the associated hostname.
Using the ping command by hostname :
# ping RHEL02
Using the nslookup command :
# nslookup RHEL02
Network troubleshooting can be torture if you don't know what to look for and if you don't understand how networking works.
Using the ping command by hostname :
# ping RHEL02
Using the nslookup command :
# nslookup RHEL02
Network troubleshooting can be torture if you don't know what to look for and if you don't understand how networking works.
Comments