Mac OS X Network Diagnostic command, macos
Below are some common network diagnostic commands for Mac OS X. They help us discover network problems. Refer to the Protocol forest for the protocols and network communication principles mentioned in this article.
Some tools, such as arping and arp-scan, must be installed using HomeBrew.
The first step in Network diagnosis is to understand your devices, such as interfaces and IP addresses.
Displays network interface information. Such as the interface name, interface type, interface IP address, and hardware MAC address.
ARP is used within a LAN. Borrow ARP protocol, the device can know the correspondence between the IP-MAC in the same LAN. When we access a local IP address, the device communicates with the corresponding MAC address based on the corresponding relationship. Through ARP tools, we can know whether the communication in the LAN is normal.
Show IP-MAC mappings for Local Storage
Sudo arping-I eth0 192.168.1.1
The eth0 interface sends an ARP request to query the MAC address of the device whose IP address is 192.168.1.1.
Queries the MAC addresses of all IP addresses in the LAN.
Sudo tcpdump-I en0 arp
Listen to arp communication for the en0 Interface
The network layer is a wide-area Internet, and devices on the Internet are identified by IP addresses. Ping sends an ICMP ECHO_REQUEST request to an IP address. The device that received the request will return an ICMP reply. If you ping an IP address, it means that the device of the IP address can successfully arrive at the network layer.
Send an ICMP request to the IP address 192.168.1.255. If the ICMP address is not disabled, the device on the Internet will reply.
Send an ICMP request to the broadcast address 192.168.1.255. If ICMP is not disabled, devices on the Internet will reply.
Note that many devices Disable ICMP. If you cannot ping a device, it is not necessarily a network-layer fault.
If the two devices have the same IP address, the IP address conflict will occur. In many networks, IP addresses are automatically assigned by the DHCP protocol, which greatly reduces the possibility of IP conflict. The DHCP server and the device reach an agreement, the device will occupy an IP address within a certain period of time, and the DHCP server will no longer assign this IP address to others.
Sudo ipconfig set en0 DHCP
Update the DHCP lease. The device releases the IP address and obtains the IP address again from the DHCP server.
Sudo ipconfig set en0 INFORM 192.168.0.120
Set the interface en0 to a static IP address.
A lan is connected to the wide-area Internet through a router. Communication over the Internet often goes through multiple routers. A Router failure on the way may cause an exception in Internet access.
The route table is displayed. From the routing table, you can find the Gateway ). A gateway is the egress to a wider area network.
Tracks the full route to the IP address destination.
Use the ICMP protocol to track routes. ICMP is often disabled, so a "*" string is returned.
Sudo traceroute-T-p 80 126.96.36.199
Trace the route through the TCP protocol and port 80. The default port 80 of TCP is rarely disabled.
Tcpdump is a network packet capture tool. It can listen to communications between different layers of network interfaces and filter out specific content, such as specific protocols and specific ports. We have used tcpdump to listen for ARP communication. Here we will look at more monitoring methods.
Sudo tcpdump-I en0
Listen to all communications of the en0 Interface
Sudo tcpdump-A-I en0
Display the communication content of the en0 interface with ASCII
Sudo tcpdump-I en0 'port 8080'
Display the communication between port 8080 of the en0 Interface
Sudo tcpdump-I eth1 src 192.168.1.200
Display eth1 interface, Communication from 192.168.1.200
Sudo tcpdump-I eth1 dst 192.168.1.101 and port 80
Display eth1 interface port 80, destination: 192.168.1.101 Communication
Sudo tcpdump-w record. pcap-I lo0
Store lo0 interface communication to file record. pcap
Domain name resolution
DNS is translated between the domain name and IP address. A dns failure will cause us to be unable to access a website through the domain name.
DNS domain name resolution. Returns the IP address of the domain name.