How to add or remove a static ARP entry on Linux

ARP (short for "Address Resolution Protocol") is a network protocol used to map an IP network address to a corresponding hardware MAC address. When host X wants to communicate host Y, X first broadcasts an ARP request on its local network, to obtain Y's MAC address. Once X receives ARP reply containing Y's MAC address, X uses the information to construct Ethernet frames destined for Y.

The IP/MAC address mapping information so obtained is cached in local ARP table, so that ARP query process can be omitted subsequently.

Problems can arise when for whatever reason, host X does not receive ARP replies for a destination host Y with which it wishes to communicate. In other cases, ARP replies come in, but contain a MAC address associated with an incorrect host Z. Such corrupted ARP replies will result in traffic hijacking, where traffic that should have been sent to Y ends up arriving at host Z.

When dealing with these kinds of ARP-induced abnormal situations, it's useful to be able to add static ARP entries manually on locally cached ARP table. When a MAC address of a destination host Y is found in local ARP table, there is no need to send out ARP requests.

To add a static ARP entry to local ARP table:

$ sudo arp -s 00:0c:29:c0:94:bf

This commands tells local ARP table that the host with IP address has MAC address 00:0c:29:c0:94:bf. Once you have configured a static ARP entry, you can verify that.

$ arp -a -n
? ( at e0:db:55:ce:13:f1 [ether] on eth0
? ( at 00:e0:b1:cb:07:30 [ether] on eth0
? ( at 00:0c:29:c0:94:bf [ether] PERM on eth1

As you can see above, the statically configured ARP entry correctly shows up, marked as "PERM" in the ARP table.

To delete a static ARP entry from local ARP table:

$ sudo arp -d
$ arp -a -n
? ( at e0:db:55:ce:13:f1 [ether] on eth0
? ( at 00:e0:b1:cb:07:30 [ether] on eth0
? ( at <incomplete> on eth1

Add Static ARP Entries Permanently on Linux

Note that any ARP entry added by arp command at run time like above does not remain persistently across reboots. In order to add a static ARP entry permanently, what you can do is to load ARP entries from an external file automatically when a network interface is up. For that, first create a file that contains static ARP entries.

$ sudo vi /etc/ethers
. . . .

The arp command allows you to load any external file using "-f" option.

$ sudo arp -f /etc/ethers

Now you need to set the above command to be run automatically when a given network interface (e.g., eth0) is up. There are distribution-specific ways to run a startup command for network interfaces. Following are distribution-specific examples.

Here I assume that you are not using NetworkManager on your Linux system. So if you are using NetworkManager, you will have to disable it first.

On Ubuntu, Debian or Mint, add the following entry in /etc/network/interfaces:

iface wlan0 inet dhcp
. . .
post-up arp -f /etc/ethers

On CentOS, RHEL or Fedora, create the following executable script:

$ sudo vi /sbin/ifup-local
if [[ "$1" == "eth0" ]]
arp -f /etc/ethers
$ sudo chmod +x /sbin/ifup-local

Subscribe to Xmodulo

Do you want to receive Linux FAQs, detailed tutorials and tips published at Xmodulo? Enter your email address below, and we will deliver our Linux posts straight to your email box, for free. Delivery powered by Google Feedburner.

Support Xmodulo

Did you find this tutorial helpful? Then please be generous and support Xmodulo!

The following two tabs change content below.
Dan Nanni is the founder and also a regular contributor of He is a Linux/FOSS enthusiast who loves to get his hands dirty with his Linux box. He likes to procrastinate when he is supposed to be busy and productive. When he is otherwise free, he likes to watch movies and shop for the coolest gadgets.

2 thoughts on “How to add or remove a static ARP entry on Linux

  1. The Centos version of persisting the arp entries creates a script named ifup-local via:
    $ sudo vi /sbin/ifup-local

    Then makes another file executable:
    $ sudo chmod +x /sbin/ifup-pre-local

    Minor typo.



Leave a comment

Your email address will not be published. Required fields are marked *