Mac OS X Network Diagnostic command, macos

Source: Internet
Author: User

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.

 

Basic tools

The first step in Network diagnosis is to understand your devices, such as interfaces and IP addresses.

Ifconfig

Displays network interface information. Such as the interface name, interface type, interface IP address, and hardware MAC address.

 

ARP

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.

Arp-

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.

 

Sudo arp-scan-l

Queries the MAC addresses of all IP addresses in the LAN.

 

Sudo tcpdump-I en0 arp

Listen to arp communication for the en0 Interface

 

Network Layer

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.

Ping 192.168.1.1

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.

Ping 192.168.1.255

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.

 

Routing

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.

Netstat-nr

The route table is displayed. From the routing table, you can find the Gateway ). A gateway is the egress to a wider area network.

 

Traceroute 74.125.128.99

Tracks the full route to the IP address destination.

Traceroute-I 74.125.128.99

Use the ICMP protocol to track routes. ICMP is often disabled, so a "*" string is returned.

Sudo traceroute-T-p 80 74.125.128.99

Trace the route through the TCP protocol and port 80. The default port 80 of TCP is rarely disabled.

 

Network listener

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.

Host www.sina.com.cn

DNS domain name resolution. Returns the IP address of the domain name.

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.