logoCndocs
Other Tools

arp Command

Introduction

The arp command is a networking utility used to display and modify the Address Resolution Protocol (ARP) cache in Linux and Unix-like operating systems. ARP is a crucial protocol that maps IP addresses to MAC (Media Access Control) addresses, enabling communication between devices on a local network.

The ARP cache serves as a lookup table that helps devices find each other on a network without having to repeatedly use the ARP protocol for every packet. By maintaining this cache, network performance is significantly improved as devices can quickly determine the hardware address associated with an IP address they need to communicate with.

arp Command Output

Understanding ARP

Before diving into the command itself, it's important to understand what ARP does:

  1. Purpose: ARP translates IP addresses (logical addresses) to MAC addresses (physical hardware addresses)
  2. Layer: It operates between the Data Link Layer (Layer 2) and the Network Layer (Layer 3) of the OSI model
  3. Process:
    • When a device wants to communicate with another device on the local network, it needs the MAC address
    • If the MAC address isn't in the ARP cache, the device broadcasts an ARP request
    • The device with the matching IP address responds with its MAC address
    • Both devices update their ARP caches with this information

Basic Syntax

The basic syntax of the arp command is:

arp [options] [hostname]

Where:

  • options: Various flags that modify the behavior of the command
  • hostname: The hostname or IP address to look up or modify in the ARP cache

Installation

The arp command is typically included in the net-tools package, which may not be installed by default on newer Linux distributions. To install it:

Debian/Ubuntu-based Systems

sudo apt update
sudo apt install net-tools

Red Hat/CentOS/Fedora Systems

# For CentOS/RHEL
sudo yum install net-tools
 
# For Fedora
sudo dnf install net-tools

Arch Linux

sudo pacman -S net-tools

Basic Usage

Displaying the ARP Cache

To display the entire ARP cache:

arp

This shows all entries in the ARP cache, including IP addresses, MAC addresses, interface names, and entry types.

Displaying the ARP Cache in Numeric Format

To display the ARP cache with numeric addresses instead of resolving hostnames:

arp -n

This is useful when you want to see the actual IP addresses or when DNS resolution is slow.

Displaying the ARP Cache for a Specific Host

To display the ARP entry for a specific host:

arp hostname

Or using an IP address:

arp 192.168.1.1

Displaying the ARP Cache in Verbose Mode

For more detailed information:

arp -v

The verbose mode provides additional information about each entry in the ARP cache.

Advanced Usage

Adding an ARP Entry

To manually add an entry to the ARP cache:

sudo arp -s 192.168.1.100 00:11:22:33:44:55

This creates a static ARP entry mapping the IP address 192.168.1.100 to the MAC address 00:11:22:33:44:55.

Deleting an ARP Entry

To remove an entry from the ARP cache:

sudo arp -d 192.168.1.100

This deletes the ARP entry for the specified IP address.

Adding Multiple ARP Entries from a File

To add multiple ARP entries from a file:

sudo arp -f /path/to/file

The file should contain entries in the format:

hostname  hw_addr  [temp]

For example:

192.168.1.100  00:11:22:33:44:55
192.168.1.101  00:11:22:33:44:56  temp

Specifying the Hardware Type

To specify the hardware address type:

arp -H ether

Common hardware types include:

  • ether (Ethernet)
  • ax25 (AMPR AX.25)
  • arcnet (ARCnet)
  • netrom (AMPR NET/ROM)
  • rose (AMPR ROSE)
  • dlci (Frame Relay DLCI)
  • fddi (Fiber Distributed Data Interface)
  • hippi (HIPPI)
  • irda (IrLAP)

Specifying the Interface

To display ARP entries for a specific network interface:

arp -i eth0

This shows only the ARP entries associated with the specified interface.

Common Options

OptionDescription
-a, --allDisplay all entries in the ARP cache
-n, --numericDisplay numeric addresses instead of resolving hostnames
-v, --verboseDisplay verbose information
-d, --deleteDelete an entry from the ARP cache
-s, --setCreate a new ARP entry
-f, --fileRead new entries from a file
-H, --hw-typeSpecify the hardware address type
-i, --deviceSpecify the network interface
-eDisplay the ARP cache in Linux/Unix format
-D, --use-deviceUse the hardware address of the specified interface

Practical Examples

Example 1: Checking if a Device is on the Network

To check if a device with a specific IP address is on the network:

ping -c 1 192.168.1.100
arp -n | grep 192.168.1.100

This sends a single ping to the IP address and then checks if an ARP entry was created.

Example 2: Detecting IP Address Conflicts

To check if multiple devices are using the same IP address:

arp -an | grep -i duplicate

This looks for duplicate entries in the ARP cache, which can indicate IP address conflicts.

Example 3: Securing Against ARP Spoofing

To create a static ARP entry for critical devices (like your default gateway):

sudo arp -s 192.168.1.1 00:11:22:33:44:55

This helps protect against ARP spoofing attacks by ensuring that the IP-to-MAC mapping for important devices doesn't change.

Example 4: Troubleshooting Network Connectivity

If you're having trouble connecting to a device:

# First, try to ping it
ping -c 1 192.168.1.100
 
# Then check if an ARP entry was created
arp -n | grep 192.168.1.100
 
# If no entry was created, there might be a network issue

Example 5: Clearing the ARP Cache

To clear the entire ARP cache (requires root privileges):

sudo ip -s -s neigh flush all

Note: This uses the ip command, which is the modern replacement for many networking utilities including arp.

The ARP cache information is stored in the kernel and can be accessed through:

  • /proc/net/arp: Contains the current ARP table
  • /etc/ethers: Can be used to configure static ARP entries

Comparison with Modern Alternatives

arp vs. ip neighbor

The ip neighbor command from the iproute2 package is the modern replacement for arp:

arp Commandip neighbor Equivalent
arpip neighbor show
arp -nip -n neighbor show
arp -s 192.168.1.100 00:11:22:33:44:55ip neighbor add 192.168.1.100 lladdr 00:11:22:33:44:55 dev eth0
arp -d 192.168.1.100ip neighbor del 192.168.1.100 dev eth0

The ip neighbor command offers more features and is actively maintained, while arp is considered legacy.

Troubleshooting

Common Issues

Incomplete ARP Entries

If you see entries marked as "incomplete":

192.168.1.100 (incomplete) eth0

This means that an ARP request was sent, but no response was received. Possible causes include:

  • The device is turned off
  • The device is not connected to the network
  • A firewall is blocking ARP requests or responses
  • Network interface issues

Stale ARP Entries

ARP entries can become stale if a device's MAC address changes (e.g., after replacing a network card). To fix this:

sudo arp -d 192.168.1.100
ping -c 1 192.168.1.100

This removes the stale entry and forces a new ARP request.

Permission Denied

If you get "Permission denied" when trying to modify the ARP cache:

SIOCSARP: Operation not permitted

You need to run the command with root privileges using sudo.

Security Considerations

ARP Spoofing

ARP spoofing (or ARP poisoning) is a type of attack where an attacker sends fake ARP messages to associate their MAC address with the IP address of another device, such as the default gateway. This can lead to:

  • Man-in-the-middle attacks
  • Denial of service
  • Session hijacking

To protect against ARP spoofing:

  • Use static ARP entries for critical devices
  • Consider using ARP monitoring tools
  • Implement network segmentation
  • Use encrypted protocols (HTTPS, SSH, etc.)

Best Practices

  1. Regularly Monitor ARP Cache: Check for unexpected or suspicious entries
  2. Use Static ARP Entries: For critical infrastructure devices
  3. Keep Systems Updated: Ensure your operating system and network tools are up to date
  4. Consider Network Security Tools: Tools like Arpwatch can monitor for ARP changes

Conclusion

The arp command is a fundamental networking tool for viewing and manipulating the ARP cache in Linux systems. While it's gradually being replaced by more modern tools like ip neighbor, understanding arp is still valuable for network troubleshooting, diagnostics, and security monitoring.

By mastering the arp command, system administrators and network engineers can effectively manage IP-to-MAC address mappings, troubleshoot network connectivity issues, and help secure their networks against ARP-based attacks.

Test Your Knowledge

Take a quiz to reinforce what you've learned

Exam Preparation

Access short and long answer questions for written exams

Share this page