Linux provides many command-line tools to help sysadmins manage, configure, and troubleshoot network settings. Show
Posted: August 26, 2020 |%t min read| by Ricardo Gerardi (Sudoer, Red Hat) Image Image by Michael Schwarzenberger from Pixabay More Linux resources
Networking configuration and troubleshooting are crucial tasks that sysadmins need to perform regularly. Some of these tasks can be challenging. However, when dealing with connectivity issues, using the right tools will assist you in achieving the results in a faster and consistent way. The ip commandThe 2 command is an all-around utility to show and manipulate network objects on your Linux system, including IP addresses, routes, and ARP tables. It's a useful tool to configure the network, as well as to troubleshoot network connectivity issues.The 2 command replaces the functionality of many commands provided with the old 4 package such as 5, 6, and 7, but it adds many other features.In its most basic form, you can just run 2 and provide a network object to manipulate, such as an address, link, or route, and a subcommand to perform an action. If you do not give a subcommand, many objects default to the 9 subcommand to display information related to that object.Here is the basic syntax:
For example, to see the link status on all network devices, run 0:
Because 9 is the default subcommand, you can also obtain the same result by running 2 or even 3 (many objects recognize an abbreviation).The 2 command manages many objects. The main ones are:
You can see a full list of objects and commands by running 3.Some useful examples of the ip commandShow network statistics 4 in human readable format 5 for a specific network interface:
Show the IP addresses of all interfaces:
Show the IP address of a single interface e.g., enp1s0:
Add another IP address to an interface (requires 6 or 7 user):
Display the routing table:
Add a route (default gateway):
The 2 command is a lower-level interface to configure network options on your Linux system. While it's useful as a troubleshooting tool, it may be harder to set the network with it. For this reason, many distributions provide a higher-level interface to accomplish the same task. Next, let's take a look at the Network Manager configuration tool 9, which provides an integrated way to configure the network.The nmcli toolNetwork Manager is a network configuration application available by default with many Linux distributions, including RHEL and Fedora. Network Manager runs as a daemon, and its goal is to provide a higher-level interface to make network configuration easier and more automated. It's common for users of desktop Linux or servers with a graphical interface to use Network Manager GUI clients to configure the network. For cases where you work with headless servers or if you want to automate configuration via shell scripts, the 9 tool comes in handy.Network Manager and 9 are a versatile combination that allow you to verify and configure many network options. The basic syntax for 9 is:
The most common objects are:
It's impossible to cover all the options on a single blog post. Let's check some examples of how to use 9 for common network configurations tasks. For more examples, consult the official nmcli-examples page or the man pages with 9.Check the status of network devices:
Show all connection profiles: 0Show details about a specific connection (e.g., enp1s0): 1Retrieve specific parameters from a connection (e.g., IP address and DNS): 2Modify connection parameters, e.g., switch from DHCP to manual connection: 3Restart the connection to enable new options: 4Add a new connection profile: 5 9 also allows you to edit a connection profile interactively. This interface provides help and auto-completion via the Tab key, which guides you through the many options available. Activate the editor using 1: 6
2 command. Use the Tab key auto-completion to see all available options: 7Then you can 3 the current values: 8When you finish your changes, 4 them to the connection and 5 to complete the operation: 9Finally, restart the connection to make the changes effective. Network Manager and 9 are a complete solution for network configuration. If you have never used it before, start with some of the basic commands and gradually move to more complex settings. Consult the man pages and examples to execute specific tasks.Next, let's review some commands that help you with network troubleshooting, starting with name resolution. The nslookup commandWhen managing connectivity issues, DNS name resolution is often a source of headaches. The 7 utility helps you check and troubleshoot DNS name resolution.This command is available with the 8 package on RHEL8 and Fedora systems. Install it with 9: 0To quickly check the name resolution for a particular host, use 7 with the hostname as an argument. The command uses the default DNS configuration for the name resolution: 1If the name resolution fails, you can use an alternative name server for the resolution by providing its address as the third argument: 2This information is useful for troubleshooting as it helps to identify whether the issue is local due to a specific server, or something more extensive. You can also use it to run reverse DNS queries by providing the IP address instead of a hostname: 3The 7 utility is a useful tool to help troubleshoot network issues related to DNS name resolution. Next, let's take a look at troubleshooting local network sockets.The ss utilityAnother common task when troubleshooting network connectivity issues is determining whether a connection is established or a particular service is available on a server. The 2 command, short for socket statistics, is a convenient tool that displays network socket information. It's the modern replacement for 3 that provides similar functionality, but includes a few extra features.Use 2 with no options to see the complete list of all established network sockets for socket types TCP, UDP, and UNIX. 4Since the default command displays all established network connections, this list can be extensive on a busy machine, with over a thousand entries. To help you with troubleshooting, 2 provides several filtering options.You can display socket information for specific socket types with the following command-line parameters: 6 for TCP, 7 for UDP, and 8 for UNIX.For example, display TCP socket information with 9: 5You can also filter the list by source or destination hostname or IP address. For example, here is a list of established connections for destination IP address 192.168.122.1: 6These commands are useful to troubleshoot network connectivity in general or between specific hosts in the network. Another practical application for 2 is to verify whether network services are listening on the local machine with the correct address and port. To verify listening sockets, use the option 1: 7You can use the same filtering options described above to filter specific socket types. For example, to list all listening TCP sockets enter: 8Instead of displaying the service name, like 2 or 3, 2 can display port numbers by using the 5 option: 9Finally, another useful option is 6 to display process related information such as user name and process ID (PID). Some services may require elevated privileges via 6 or as 7 to list process information: 0The 2 tool is an essential command in the sysadmin toolbox for network troubleshooting tasks. Next, let's take a look at 00 to trace network connectivity between hosts.The tracepath commandThe 00 command is a network troubleshooting tool that displays the network connectivity path between the local host and a remote host, identifying all routers used to route the traffic between them.In case you're unable to connect to a network service in a remote host, 00 helps you determine where the issue is. 00 is a replacement for 04, offering similar functionality. The main difference is that 00 uses random UDP ports instead of the ICMP protocol for the trace, thus not requiring elevated privileges to run.For the basic usage, provide the hostname or IP address of the destination host. You can also provide the option 5 to display IP addresses for the routers instead of their names: 1If 00 cannot connect to a network hop, it displays no reply. By default, the maximum number of hops it tries is 30, which is usually enough. You can change that with the option 08.Suppose it receives no replies after a particular hop. That is a good indicator where to go next for your troubleshooting task. 00 information is not definitive, as the traffic could be blocked for several reasons. However, it helps you narrow down the issue and focus on the resolution efforts.For security reasons, many routers on the Internet block traffic, so 00 may not be as useful for tracing connectivity with Internet services. It's still useful for local network troubleshooting.What's next?In this article, we explored five essential network configuration and troubleshooting tools for Linux systems. These tools are powerful and provide many options that are hard to cover in a single post. We encourage you to check them out and look at documentation and man pages to see how you can incorporate them into your workflow. There are other useful Linux network tools, such as 11, 12, and 13. These tools are covered in other Enable Sysadmin articles.[ Network hard to manage? Check out Network Automation for Everyone, a free book from Red Hat. ] What to read nextImage My go-to Linux network troubleshooting commands Every sysadmin needs a good troubleshooting strategy, and you can't fix a problem if you cannot identify it. These are my favorite commands to quickly filter through the possibilities of a given problem. Posted: November 29, 2019 Author: Tyler Carrigan (Editorial Team, Red Hat) Image A beginner's guide to network troubleshooting in Linux Every system administrator needs to have at least a basic understanding of network troubleshooting. And the first rule of network troubleshooting to remember is, "Packets don't lie." Posted: September 24, 2019 Author: Anthony Critelli (Sudoer) Image Becoming friends with NetworkManager Need to configure a Linux machine with NetworkManager? Learn how, and why. Posted: August 5, 2019 Author: Francesco Giudici (Red Hat) Topics: Networking Linux Ricardo GerardiRicardo Gerardi is a Senior Consultant at Red Hat Canada where he specializes in IT automation with Ansible and OpenShift. More about me Red Hat Summit 2022: On DemandGet the latest on Ansible, Red Hat Enterprise Linux, OpenShift, and more from our virtual event on demand. Register for free Related ContentImage Learn how Unix influenced Linux, understand Ansible lists and dictionaries, and more tips for sysadmin What is the Linux command to display network connections?netstat command – It is used to display network connections, routing tables, interface statistics, masquerade connections, and multicast memberships. ifconfig command – It is used to display or configure a network interface. nmcli command – A command to show or configure a network interface on Linux.
How can I check WiWireless connection troubleshooter. Open a Terminal window, type lshw -C network and press Enter . ... . Look through the information that appeared and find the Wireless interface section. ... . If a wireless device is listed, continue on to the Device Drivers step.. How to connect to a wireless network in Linux commandBelow you will see Steps to connect to a wireless network using the command line.. Determine your Network Interface. ... . Turn on your Wireless Interface. ... . Scan for available wireless access points. ... . Create a WPA supplicant configuration file. ... . Find name of your wireless driver. ... . Connect to the internet.. Which command will show the configuration details of a wireless connection in Linux?iwconfig
Linux iwconfig is used to configure the wireless network interface. It is used to set and view the basic WI-FI details like SSID and encryption. To know more about this command, refer to the man page.
|