How to Use Mac Terminal to Identify Network Settings.
While macOS offers an easy-to-use menu for network settings in the System Preferences menu, the Terminal app is where you need to be if you want to quickly find or check your network configuration information. You can use it to find your IP address, find your location, check your system firewall, etc.
Your network settings can be accessed using some common terminal commands, which for the most part require very little configuration to use. We still recommend that you use the System Preferences app to configure (if you don’t like using Terminal), but it is easy to define the network settings for a Mac terminal.
Use Network Setting
The Network Configuration Tool offers a wealth of information about the current Mac network configuration. You can use it to find your computer name, IP address, current Wi-Fi network, and more. As the name suggests, you can also use it to change settings, but we still recommend using system settings for that.
You can view a complete list of possible Mac terminal network commands using the network setup tool by typing networksetup -help in terminal. A help list opens with various examples of using the tool to view and change various network settings.
Examples of networksetup commands you can use to view network information include:
- To view the name of your Mac: networksetup -getcomputername.
- To list all Mac network connections: networksetup – listallhardwareports
- To display the currently connected Wi-Fi network: networksetup -getairportname deviceid. Replace deviceid with the device ID from the networksetup -listallhardwareports command.
Use ipconfig
The ipconfig tool is common for Windows and macOS computers, but unlike the Windows version, it is not the most useful tool for changing network settings. However, where it can be useful, there is a list of information about your current network configuration.
–
By typing ipconfig in a terminal, you will see a list of all the available commands, but they include:
- To view the current network IP address: ipconfig getifaddr deviceid. Replace deviceid with the correct network device identifier (e.g. en0). Enter networksetup -listallhardwareports if you don’t know.
- To view the current network DNS server: ipconfig getoption deviceid domain_name_server (replacing deviceid with your network device ID).
Use ifconfig
The ifconfig command is another network configuration tool available to macOS and Linux PC users. However, unlike ipconfig, ifconfig is a much more powerful tool for viewing and modifying your network settings.
However, you only need to enter ifconfig on the terminal to see a detailed list of information about all network devices connected or integrated into your Mac. This includes IP and MAC addresses, current device status, and more.
You can view specific information by specifying the device ID instead (e.g. ifconfig en0).
Using ping
While you cannot use it to view any network information, you can use the ping command to check if you can establish contact with another network device. This could be a device on your network (such as a network router), a website domain, or an Internet IP address to test your Internet connection.
You will want to use ping as a troubleshooting tool when your device is having problems connecting to another device on your local network or to a device or website on the Internet. It will show the time it took to send and return information and will run continuously until you decide to stop it.
To use it, enter the ping address, replacing the address with the IP address or domain name. The usual target for testing is google.com. If you can’t open Google, you probably don’t have an internet connection.
Likewise, ping 192.168.1.1 will check the IP address of many routers on the LAN (192.168.1.1).
using netstat
The netstat tool displays information about your current inbound and outbound network connections. With this tool, you can view a list of any connections to your Mac. Windows and Linux PCs also use netstat, but with some differences, with different flags available for Mac users.
There are several ways to use netstat to view your current network settings or connections. These include:
- For a current list of all active Internet connections: netstat
- To view connection details for an interface: netstat -l deviceid, replacing deviceid with the name of your network interface (for example, netstat -l en0).
- To view the IP routing table: netstat -nr or netstat -r
- To display all network statistics: netstat -s and netstat -i
For more information on how to use the netstat command and help decipher some of the tricky technical terms, enter man netstat to view and read the accompanying netstat man page.
with lsof
You can use the lsof command as a way to view any running processes on your Mac that have active network connections. This replaces similar functionality that you can find using the netstat command on a Windows or Linux PC.
There are several ways to use the lsof Mac terminal command to view network data. These include:
- To view all open network connections: lsof -i
- To see which software is using which ports: lsof -n -i4TCP
For more information, type man lsof to view the man page for the lsof command.
using arp
If you want to see a list of all active devices on the local network, you can use the arp tool. It will list the IP and MAC addresses of all devices that your Mac has discovered on your network, based on the ARP (Address Resolution Protocol) broadcasts made by those devices.
Typing arp -a on a terminal will list these devices.
You can then combine the information found here with other commands such as ping to determine if these devices are active and can be contacted from your Mac.
Initializing Mac Network Settings
With these tools, you can define the network settings of your Mac terminal that you can change (or change). For example, you may need to spoof the MAC address on your Mac to bypass the MAC filtering on the guest Wi-Fi.
It can also help you pinpoint problems, especially if your Mac drops Wi-Fi connection regularly. If your Mac is having problems, apps like OnyX for Mac can help you get things back up quickly.
–