ARP with Shell

Discussion of programming on Linux, including shell scripting, perl, python, c/c++, mono, java. Whatever tickles your fancy.
Post Reply
mudasir
Captain
Posts: 565
Joined: Tue Oct 17, 2006 5:23 am
Location: Dubai
Contact:

ARP with Shell

Post by mudasir »

AOA,

How can i delete all ARP entries and disable Dynamic ARP.

I have made a script to make static arp entries

Code: Select all

cat arp.address | while read arps
do
ip=`echo $arps | awk '{print $2}'`
mac=`echo $arps | awk '{print $1}'`
arp -i eth0 -s $ip $mac
done
The main thing i want to know is how to delete all ARP entries and Disable Dynamic ARP, that ARP should not get any Dynamic entry.

On a website i read that arp can be disabled and enabled like this ifconfig eth0 -arp. After executing this command when i run arp, it does nothing. Its like arp is turned off.

I dont want to disable arp, i just want to disable the Dynamic Entries of ARP, like ARP should not be able to get Dynamic Entry.

I tried the following script to delete all arp entries.

Code: Select all

arp -i eth0 | while read arps
do
ip=`echo $arps | awk {'print $1}'`
arp -i eth0 -d $ip
done
Kind Regards
Mudasir Mirza (RHCE)
(+971)55-1045754
http://www.crystalnetworks.org
http://www.diglinux.com
nayyares
Battalion Quarter Master Havaldaar
Posts: 237
Joined: Tue Dec 13, 2005 10:47 pm
Location: JNB, SA
Contact:

Post by nayyares »

Hi,

Try,

Code: Select all

#echo 0 > /proc/sys/net/ipv4/neigh/eth0/mcast_solicit
Cheers
Nayyar Ahmad
RHCE, CCNA, OCP DBA
nayyares aT fedoraproject DoT org
blogs: nayyares.blogspot.com
mudasir
Captain
Posts: 565
Joined: Tue Oct 17, 2006 5:23 am
Location: Dubai
Contact:

Post by mudasir »

AOA,

Dear Nayyares,

Can you please explain what this will do. Like what is the function of this command.
Kind Regards
Mudasir Mirza (RHCE)
(+971)55-1045754
http://www.crystalnetworks.org
http://www.diglinux.com
nayyares
Battalion Quarter Master Havaldaar
Posts: 237
Joined: Tue Dec 13, 2005 10:47 pm
Location: JNB, SA
Contact:

Post by nayyares »

Hi,
mcast_solicit: Maximum number of retries for multicast solicitation.
if it is set to zero, kernel avoid ARP broadcast. any other digital value is the number of time it will retry to resolve a MAC.

Cheers
Nayyar Ahmad
RHCE, CCNA, OCP DBA
nayyares aT fedoraproject DoT org
blogs: nayyares.blogspot.com
mudasir
Captain
Posts: 565
Joined: Tue Oct 17, 2006 5:23 am
Location: Dubai
Contact:

Post by mudasir »

AOA,

Thanks alot Dear Nayyares.

Can you please also tell me how can i delete all arp entries after executing your stated command.

I read some where that we can do something like arp -d 2>> /dev/null ...i dont know exectly how to achieve this.
Kind Regards
Mudasir Mirza (RHCE)
(+971)55-1045754
http://www.crystalnetworks.org
http://www.diglinux.com
nayyares
Battalion Quarter Master Havaldaar
Posts: 237
Joined: Tue Dec 13, 2005 10:47 pm
Location: JNB, SA
Contact:

Post by nayyares »

Hi,
mudasir wrote:AOA,

Thanks alot Dear Nayyares.

Can you please also tell me how can i delete all arp entries after executing your stated command.

I read some where that we can do something like arp -d 2>> /dev/null ...i dont know exectly how to achieve this.
try:

Code: Select all

# ip nei flush all
Cheers
Nayyar Ahmad
RHCE, CCNA, OCP DBA
nayyares aT fedoraproject DoT org
blogs: nayyares.blogspot.com
mudasir
Captain
Posts: 565
Joined: Tue Oct 17, 2006 5:23 am
Location: Dubai
Contact:

Post by mudasir »

AOA,

Dear nayyares,

I entered the command you told me
# ip nei flush all
It didnt worked....so i googled about this command...i found that there was a syntax error, the correct command is

Code: Select all

# ip neighbor flush dev eth0
From
http://linux-ip.net/html/tools-ip-neighbor.html

I thought it might be good to share this.
Kind Regards
Mudasir Mirza (RHCE)
(+971)55-1045754
http://www.crystalnetworks.org
http://www.diglinux.com
mudasir
Captain
Posts: 565
Joined: Tue Oct 17, 2006 5:23 am
Location: Dubai
Contact:

Post by mudasir »

AOA,

I asked all this information, because i was creating a script that delete all ARP entries, disable ARP Broadcast and will create Static entries of Known IP and MAC Addresses.

I have made the script but not have tested it, will be testing it very soon. The script is as fllows.

Code: Select all

#!/bin/sh

#set -x

# Disabling ARP Broadcast...

echo 0 > /proc/sys/net/ipv4/neigh/eth0/mcast_solicit

# Flushing all Arp Entries...

ip neighbor flush dev eth0

# Making Static Entries in ARP Table

file=/macs/arp.addresses

cat $file | while read arps 
do 
ip=`echo $arps | awk '{print $2}'` 
mac=`echo $arps | awk '{print $1}'` 
arp -i eth0 -s $ip $mac 
done 
Please let me know how can i make this script more efficient...
Kind Regards
Mudasir Mirza (RHCE)
(+971)55-1045754
http://www.crystalnetworks.org
http://www.diglinux.com
nayyares
Battalion Quarter Master Havaldaar
Posts: 237
Joined: Tue Dec 13, 2005 10:47 pm
Location: JNB, SA
Contact:

Post by nayyares »

Hi,
mudasir wrote: AOA,

Dear nayyares,

I entered the command you told me
# ip nei flush all
It didnt worked....so i googled about this command...i found that there was a syntax error, the correct command is

Code: Select all

# ip neighbor flush dev eth0
What was the error in executing command? second mentioning device will shorten your script scope to just eth0, what if machine has other interfaces !

Cheers
Nayyar Ahmad
RHCE, CCNA, OCP DBA
nayyares aT fedoraproject DoT org
blogs: nayyares.blogspot.com
mudasir
Captain
Posts: 565
Joined: Tue Oct 17, 2006 5:23 am
Location: Dubai
Contact:

Post by mudasir »

AOA,

Dear Nayyares,

Thanks again for clearing all the confusions i was having regarding these commands.
Kind Regards
Mudasir Mirza (RHCE)
(+971)55-1045754
http://www.crystalnetworks.org
http://www.diglinux.com
Post Reply