Publishers of technology books, eBooks, and videos for creative people

Home > Articles

  • Print
  • + Share This
This chapter is from the book

Reference 23.2 Use Terminal to Troubleshoot Network Issues

macOS provides several network identification and diagnostic commands that you can access in Terminal. This includes, but isn’t limited to, the following:

arrow-a.jpg ifconfig (interface configuration)—Inspect details regarding hardware network interfaces.

arrow-a.jpg netstat (network status)—View routing information and network statistics.

arrow-a.jpg ping—Test network connectivity and latency.

arrow-a.jpg nslookup, dig, host, and dscacheutil—Test DNS resolution.

arrow-a.jpg traceroute—Analyze how your network connections are routed to their destination.

arrow-a.jpg nc (netcat)—Check whether a network device has specific services available.

You can also open Terminal when you start your Mac from macOS Recovery (as covered in Lesson 5, “Use macOS Recovery”) by choosing Utilities > Terminal. In macOS Recovery you can access the Wi-Fi status menu to use a different Wi-Fi network.

ifconfig

The ifconfig command enables you to view the detailed status of any network interface. Each network interface has a short UNIX-given name; for example, the default Wi-Fi interface for Mac portable computers is en0.

If you run ifconfig by itself, it returns the status of all network interfaces, even ones that aren’t configured and that don’t appear in Network preferences. The following figure displays only a portion of the result of running the command. en7 is the name of an Apple USB Ethernet Adapter that’s connected to the MacBook Pro with a USB-C adapter. The name for a network interface may vary depending on the configuration of your Mac, including the other network interfaces you’ve configured for your Mac.

ifconfig is often run with the name of a single network interface. For example, the following figure illustrates running the command ifconfig en0, which returns information about the default Wi-Fi interface.

The entire extent of the output of the command is outside the scope of this guide, but some of the key pieces of information include:

arrow-a.jpg ether—MAC address

arrow-a.jpg inet6—IPv6 address

arrow-a.jpg inet—IPv4 address

arrow-a.jpg netmask—Subnet mask

arrow-a.jpg media—Connection speed and characteristics

arrow-a.jpg status—Active or inactive

netstat

The netstat command enables you to view even more detailed status of any network interface. One example is netstat -di -I, followed by the interface name. The options include:

arrow-a.jpg -di—Show the number of dropped packets

arrow-a.jpg -I (name of interface)—Show information only about that specific interface

For example, the following figure illustrates running the command netstat -di -I en7, which returns information about a connected Apple USB Ethernet Adapter.

The -I option provides a table with cumulative counts of network packets transferred, errors, and collisions. The -di option adds a count of dropped packets as well. Here are some of the values in the table:

arrow-a.jpg Name—Name of the interface

arrow-a.jpg Address—MAC address, IPv6 address, or IPv6 address; it’s common to see each interface have three addresses listed

arrow-a.jpg Ipkts—Number of packets received by the interface

arrow-a.jpg Ierrs—Number of errors related to packets received by the interface

arrow-a.jpg Opkts—Number of packets sent by the interface

arrow-a.jpg Oerrs—Number of errors related to packets sent by the interface

arrow-a.jpg Coll—Number of collisions detected

arrow-a.jpg Drop—Number of dropped packets detected

You can also use netstat to analyze network transfer statistics. If you open an app like Safari to cause some network traffic, then run the netstat command again, you can verify that packets are being sent and received from this interface. In the following example, there were initially 1,276 received packets; Safari was then used to generate network traffic; then there were 16,100 received packets. It’s safe to conclude that Safari used the en7 interface for network traffic.

If the transfer statistics indicates activity but you still experience problems, the issue is probably a network or service problem and not the network interface. Or, if this interface is experiencing transfer errors, a local network hardware connectivity issue may be the root of your problem.

To resolve hardware network interface issues, check the physical connection. With wired networks, try different network ports or cabling to rule out physical connection issues. With wireless networks, double-check the Wi-Fi settings and the configuration of any wireless base stations. If the Mac network hardware isn’t working, contact an Apple Authorized Service Provider.

ping

If your network settings are properly configured and the hardware network interface appears to be working correctly but you still experience network issues, test network connectivity using the ping command.

The word ping refers to several concepts:

arrow-a.jpg The name of a command

arrow-a.jpg A kind of network packet

arrow-a.jpg The act of using the ping command to send a ping packet

The ping command determines whether your Mac can successfully send and receive data to another network device. Your Mac sends a ping data packet to the destination IP address, and the other device returns the ping packet to indicate connectivity.

To use ping, type ping, then a space, then an IP address to a device on the LAN that should always be accessible, such as the network router; then press Return. Using a domain name assumes that your Mac is properly communicating with a DNS server, which might not be the case if you’re troubleshooting connectivity issues.

If the ping command is successful, it returns the amount of time it took for the ping to travel to the network device and back. This round trip typically takes a few milliseconds. You can use the -c option (count) with a number of packets to send, or if you omit the -c option, the ping command will repeatedly send packets until you stop the ping command by pressing Control-C or Command-Period.

After you stop the ping command, the ping command returns how many packets ping transmitted, how many packets were received by the remote device, and a percentage of packet loss.

Some network administrators configure their firewalls to block pings or to set up their network devices not to respond to network pings.

After you establish successful pings to local devices, branch out to WAN or internet addresses. Using ping, you may find that everything works except for the one service you were looking for that prompted you to start troubleshooting the network.

Lookup

If you are able to successfully ping other network devices by their IP address but you can’t connect to another device by its hostname, you likely have issues related to DNS. Several commands are available that let you test name resolution against your DNS server. This section covers the following commands, each listed here along with the description from the name section of its man page:

arrow-a.jpg host—DNS lookup utility

arrow-a.jpg dig—DNS lookup utility

arrow-a.jpg nslookup—Query internet name servers interactively

arrow-a.jpg dscacheutil—Gather information and statistics and initiate queries to the Directory Services cache

To verify DNS, use one of the commands in this section to query the hostname of a device or service in your local domain. If you can resolve local hostnames but not internet hostnames, your local DNS server is resolving local names but isn’t properly connecting to the worldwide DNS network. If you don’t have a local domain, use any internet hostname.

To start the network lookup process with the host command (DNS lookup utility), type host, a space, then an IP address or hostname; then press Return.

The following figure illustrates a successful forward lookup, which returns the IP address of the hostname you entered.

The following figure illustrates a successful reverse lookup, which returns the hostname of the IP address you entered.

The nslookup command returns a bit more information, which might be useful for your troubleshooting. The following figure illustrates using nslookup for a forward lookup and then a reverse lookup.

The dig command returns even more information. Use the -x option to perform a reverse lookup. The following figures illustrate using dig for forward and reverse lookups.

And finally, for this section, you can use the dscacheutil command for more advanced DNS troubleshooting.

For a DNS lookup, use two dscacheutil options followed by the hostname or IP address you want to look up. Here are the two options, along with arguments you should use for a DNS lookup:

  • arrow-a.jpg -q—This is the type of query, like user, group, or host. For DNS lookups, use -q host.

  • arrow-a.jpg -a—This is the key to look up. For forward lookups, use -a name; for reverse lookups, use -a ip_address. And as a bonus, to use an IPv6 reverse lookup, use -a ipv6_address.

To perform a forward DNS lookup, type dscacheutil, a space, -q host -a name, a space, and the hostname; then press Return.

To perform a reverse DNS lookup, type dscacheutil, a space, -q host -a ip_address, a space, and the IPv4 address; then press Return.

If you are unable to successfully return lookups, it’s possible that your Mac isn’t connecting to the DNS server. Use the ping command to test for basic connectivity to the DNS server IP address.

traceroute

If you are able to connect to some network resources but not others, use traceroute to determine where the connection fails. WAN and internet connections often require the data to travel through many network routers to reach their destination. The traceroute command examines every network hop between routers by sending packets with low time-to-live (TTL) fields to determine where connections fail or slow down.

To verify a network TCP/IP route, use traceroute followed by an IP address of a device on the LAN that should always be accessible, such as the network router. Using a domain name assumes that your Mac is properly communicating with a DNS server, which might not be the case if you’re troubleshooting connectivity issues.

If traceroute is successful, it returns a list of routers required to complete the connection and the amount of time it took for the test packets to travel to each network router. It sends three probes at each distance, so three times are listed for each hop. The delay is typically measured in milliseconds; experiencing delay times of any longer than a full second is unusual. If traceroute doesn’t get a reply from a particular router at all, it shows an asterisk rather than listing the router address, but this could be because the network equipment is configured not to respond to network requests.

Once you’ve established successful routes to local devices, you can branch out to WAN or internet addresses. Using the traceroute command, you may find that a specific network router is the cause of the problem.

For more information about any of the commands in this lesson, use the man page for the command.

  • + Share This
  • 🔖 Save To Your Account

Peachpit Promotional Mailings & Special Offers

I would like to receive exclusive offers and hear about products from Peachpit and its family of brands. I can unsubscribe at any time.

Overview


Pearson Education, Inc., 221 River Street, Hoboken, New Jersey 07030, (Pearson) presents this site to provide information about Peachpit products and services that can be purchased through this site.

This privacy notice provides an overview of our commitment to privacy and describes how we collect, protect, use and share personal information collected through this site. Please note that other Pearson websites and online products and services have their own separate privacy policies.

Collection and Use of Information


To conduct business and deliver products and services, Pearson collects and uses personal information in several ways in connection with this site, including:

Questions and Inquiries

For inquiries and questions, we collect the inquiry or question, together with name, contact details (email address, phone number and mailing address) and any other additional information voluntarily submitted to us through a Contact Us form or an email. We use this information to address the inquiry and respond to the question.

Online Store

For orders and purchases placed through our online store on this site, we collect order details, name, institution name and address (if applicable), email address, phone number, shipping and billing addresses, credit/debit card information, shipping options and any instructions. We use this information to complete transactions, fulfill orders, communicate with individuals placing orders or visiting the online store, and for related purposes.

Surveys

Pearson may offer opportunities to provide feedback or participate in surveys, including surveys evaluating Pearson products, services or sites. Participation is voluntary. Pearson collects information requested in the survey questions and uses the information to evaluate, support, maintain and improve products, services or sites; develop new products and services; conduct educational research; and for other purposes specified in the survey.

Contests and Drawings

Occasionally, we may sponsor a contest or drawing. Participation is optional. Pearson collects name, contact information and other information specified on the entry form for the contest or drawing to conduct the contest or drawing. Pearson may collect additional personal information from the winners of a contest or drawing in order to award the prize and for tax reporting purposes, as required by law.

Newsletters

If you have elected to receive email newsletters or promotional mailings and special offers but want to unsubscribe, simply email ask@peachpit.com.

Service Announcements

On rare occasions it is necessary to send out a strictly service related announcement. For instance, if our service is temporarily suspended for maintenance we might send users an email. Generally, users may not opt-out of these communications, though they can deactivate their account information. However, these communications are not promotional in nature.

Customer Service

We communicate with users on a regular basis to provide requested services and in regard to issues relating to their account we reply via email or phone in accordance with the users' wishes when a user submits their information through our Contact Us form.

Other Collection and Use of Information


Application and System Logs

Pearson automatically collects log data to help ensure the delivery, availability and security of this site. Log data may include technical information about how a user or visitor connected to this site, such as browser type, type of computer/device, operating system, internet service provider and IP address. We use this information for support purposes and to monitor the health of the site, identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents and appropriately scale computing resources.

Web Analytics

Pearson may use third party web trend analytical services, including Google Analytics, to collect visitor information, such as IP addresses, browser types, referring pages, pages visited and time spent on a particular site. While these analytical services collect and report information on an anonymous basis, they may use cookies to gather web trend information. The information gathered may enable Pearson (but not the third party web trend services) to link information with application and system log data. Pearson uses this information for system administration and to identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents, appropriately scale computing resources and otherwise support and deliver this site and its services.

Cookies and Related Technologies

This site uses cookies and similar technologies to personalize content, measure traffic patterns, control security, track use and access of information on this site, and provide interest-based messages and advertising. Users can manage and block the use of cookies through their browser. Disabling or blocking certain cookies may limit the functionality of this site.

Do Not Track

This site currently does not respond to Do Not Track signals.

Security


Pearson uses appropriate physical, administrative and technical security measures to protect personal information from unauthorized access, use and disclosure.

Children


This site is not directed to children under the age of 13.

Marketing


Pearson may send or direct marketing communications to users, provided that

  • Pearson will not use personal information collected or processed as a K-12 school service provider for the purpose of directed or targeted advertising.
  • Such marketing is consistent with applicable law and Pearson's legal obligations.
  • Pearson will not knowingly direct or send marketing communications to an individual who has expressed a preference not to receive marketing.
  • Where required by applicable law, express or implied consent to marketing exists and has not been withdrawn.

Pearson may provide personal information to a third party service provider on a restricted basis to provide marketing solely on behalf of Pearson or an affiliate or customer for whom Pearson is a service provider. Marketing preferences may be changed at any time.

Correcting/Updating Personal Information


If a user's personally identifiable information changes (such as your postal address or email address), we provide a way to correct or update that user's personal data provided to us. This can be done on the Account page. If a user no longer desires our service and desires to delete his or her account, please contact us at customer-service@informit.com and we will process the deletion of a user's account.

Choice/Opt-out


Users can always make an informed choice as to whether they should proceed with certain services offered by Adobe Press. If you choose to remove yourself from our mailing list(s) simply visit the following page and uncheck any communication you no longer want to receive: www.peachpit.com/u.aspx.

Sale of Personal Information


Pearson does not rent or sell personal information in exchange for any payment of money.

While Pearson does not sell personal information, as defined in Nevada law, Nevada residents may email a request for no sale of their personal information to NevadaDesignatedRequest@pearson.com.

Supplemental Privacy Statement for California Residents


California residents should read our Supplemental privacy statement for California residents in conjunction with this Privacy Notice. The Supplemental privacy statement for California residents explains Pearson's commitment to comply with California law and applies to personal information of California residents collected in connection with this site and the Services.

Sharing and Disclosure


Pearson may disclose personal information, as follows:

  • As required by law.
  • With the consent of the individual (or their parent, if the individual is a minor)
  • In response to a subpoena, court order or legal process, to the extent permitted or required by law
  • To protect the security and safety of individuals, data, assets and systems, consistent with applicable law
  • In connection the sale, joint venture or other transfer of some or all of its company or assets, subject to the provisions of this Privacy Notice
  • To investigate or address actual or suspected fraud or other illegal activities
  • To exercise its legal rights, including enforcement of the Terms of Use for this site or another contract
  • To affiliated Pearson companies and other companies and organizations who perform work for Pearson and are obligated to protect the privacy of personal information consistent with this Privacy Notice
  • To a school, organization, company or government agency, where Pearson collects or processes the personal information in a school setting or on behalf of such organization, company or government agency.

Links


This web site contains links to other sites. Please be aware that we are not responsible for the privacy practices of such other sites. We encourage our users to be aware when they leave our site and to read the privacy statements of each and every web site that collects Personal Information. This privacy statement applies solely to information collected by this web site.

Requests and Contact


Please contact us about this Privacy Notice or if you have any requests or questions relating to the privacy of your personal information.

Changes to this Privacy Notice


We may revise this Privacy Notice through an updated posting. We will identify the effective date of the revision in the posting. Often, updates are made to provide greater clarity or to comply with changes in regulatory requirements. If the updates involve material changes to the collection, protection, use or disclosure of Personal Information, Pearson will provide notice of the change through a conspicuous notice on this site or other appropriate way. Continued use of the site after the effective date of a posted revision evidences acceptance. Please contact us if you have questions or concerns about the Privacy Notice or any objection to any revisions.

Last Update: November 17, 2020