Apple optimize

Diagnose Mac networking problems with these three commands

Erik Eckel explains how to use three common commands to find networking issues and troubleshoot them.

The Mac's Systems Preferences Network applet enables configuring network settings, while the Network Utility (found within Applications\Utilities) provides a graphical interface for troubleshooting network errors. As Mac users and administrators develop greater skill and experience, however, they typically graduate to seeking specific Terminal commands to more quickly diagnose and repair network errors.

The Mac Terminal, of course, provides direct access to the underlying OS. As previously reviewed, the Mac command line helps unlock the power of the command line, enter basic directory commands, navigate the Mac shell, simplify networking and more. Three critical network commands, however, potentially provide the most powerful network diagnostic and troubleshooting assistance. They are ifconfig, ipconfig and traceroute.

ifconfig

The ifconfig command reveals critical information regarding a Mac's network interfaces, whether the network interface is a wired or wireless connection. Use the hostname command to confirm the system's computer name. Numerous ifconfig command options are available, and most are well beyond the scope of such an overview as is found here.

Users and administrators new to the ifconfig command should begin simply by familiarizing themselves with the wealth of information the basic ifconfig command returns when entered from the OS X Terminal. In addition to revealing each network interface's MAC address, ifconfig reveals each network interface's active IP address, hexadecimal netmask, and media duplex status.

The ifconfig command also enables assigning a specific IP address to a specific network interface. For example, the following command assigns a LAN IP address of 192.168.1.2 to interface en0 (the wired Ethernet port on my MacBook Pro) using a subnet mask of 255.255.255.0:

ifconfig en0 inet 192.168.1.2 netmask 255.255.255.0

The en1 network interface, meanwhile, serves as the wireless network interface on newer OS X systems, by default.

ipconfig

The ipconfig command enables displaying such critical Mac network interface information as the LAN IP, subnet mask, DNS servers, and router (often the DHCP server source) information. The command can also configure network settings. However, it may be better for users and administrators familiar with the Windows ipconfig command to think of the OS X ifconfig command as the Windows' ipconfig counterpart. Apple does not recommend using the OS X ipconfig command for any purpose other than debugging and testing.

To display a Mac network interface's IP address (for the wireless network interface, denoted by en1), enter this command:

ipconfig getifaddr en0

To display a Mac network interface's subnet mask, enter this command:

ipconfig getoption en1 subnet_mask

To determine the DNS server a Mac's network interface is set to leverage, enter this command:

ipconfig getoption en1 domain_name_server

To determine the router and DHCP information supplied to a Mac's network interface, enter this command:

ipconfig getpacket en1

The getpacket option returns much information. The router address is listed toward the very end.

It should be noted, too, that all the ipconfig options work with OS X's wired network interface, too. By default OS X Mountain Lion labels the wired network interface en0.

traceroute

One of the more trying network failures to diagnose and repair is failed network connectivity outside the organization. Such scenarios can prove maddening.

For example, a client once experienced difficulty connecting to a critical cloud-based service. No Mac within the client's office could connect to the cloud-based server. A support call to the cloud services provider quickly confirmed that the cloud services were operating properly; the problem was somewhere else. A "trace route" diagnosed the problem immediately; connection attempts from Louisville to the California-based cloud server were being dropped in Salt Lake City. The problem existed with the ISP, whose Utah-based routers were experiencing DNS errors.

To run a trace route command testing the connection from your Mac's location to the destination resource, enter this command (substituting your intended destination address for google.com):

traceroute google.com

The traceroute command prints on screen the results of each step of the network path from your local Mac to the destination address, noting the IP addresses the path crosses along the way and the latency delays (in milliseconds) encountered at each stop. By identifying the location at which a connection fails or experiences undue delays, administrators and end users can determine where network failures are occurring.

About

Erik Eckel owns and operates two technology companies. As a managing partner with Louisville Geek, he works daily as an IT consultant to assist small businesses in overcoming technology challenges and maximizing IT investments. He is also president o...

2 comments
shiv.skumar008
shiv.skumar008

Where are the commands? I have found few issues on wireless MAC.. We are using Bluesocket 1500 WAPs and running MAC Lion OS. The wireless drops intermittently.. Any idea what could be the reason?

Gisabun
Gisabun

Either no one cares about Macs or Macs never have any problems in the enterprise [hah!].