ARP with Shell

Discussion of programming on Linux, including shell scripting, perl, python, c/c++, mono, java. Whatever tickles your fancy.

ARP with Shell

Postby mudasir » Thu Dec 27, 2007 9:18 am

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
mudasir
Captain
 
Posts: 565
Joined: Tue Oct 17, 2006 5:23 am
Website: http://www.crystalnetworks.org
Location: Dubai

Postby nayyares » Thu Dec 27, 2007 12:05 pm

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
nayyares
Battalion Quarter Master Havaldaar
 
Posts: 237
Joined: Tue Dec 13, 2005 10:47 pm
Website: http://fedoraproject.org/wiki/NayyarAhmad
WLM: nayyares@hotmail.com
Location: JNB, SA

Postby mudasir » Thu Dec 27, 2007 7:25 pm

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
mudasir
Captain
 
Posts: 565
Joined: Tue Oct 17, 2006 5:23 am
Website: http://www.crystalnetworks.org
Location: Dubai

Postby nayyares » Thu Dec 27, 2007 11:40 pm

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
nayyares
Battalion Quarter Master Havaldaar
 
Posts: 237
Joined: Tue Dec 13, 2005 10:47 pm
Website: http://fedoraproject.org/wiki/NayyarAhmad
WLM: nayyares@hotmail.com
Location: JNB, SA

Postby mudasir » Fri Dec 28, 2007 1:55 am

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
mudasir
Captain
 
Posts: 565
Joined: Tue Oct 17, 2006 5:23 am
Website: http://www.crystalnetworks.org
Location: Dubai

Postby nayyares » Fri Dec 28, 2007 11:05 am

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
nayyares
Battalion Quarter Master Havaldaar
 
Posts: 237
Joined: Tue Dec 13, 2005 10:47 pm
Website: http://fedoraproject.org/wiki/NayyarAhmad
WLM: nayyares@hotmail.com
Location: JNB, SA

Postby mudasir » Sat Dec 29, 2007 10:57 am

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
Website: http://www.crystalnetworks.org
Location: Dubai

Postby mudasir » Sat Dec 29, 2007 11:04 am

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
mudasir
Captain
 
Posts: 565
Joined: Tue Oct 17, 2006 5:23 am
Website: http://www.crystalnetworks.org
Location: Dubai

Postby nayyares » Sat Dec 29, 2007 11:22 am

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
nayyares
Battalion Quarter Master Havaldaar
 
Posts: 237
Joined: Tue Dec 13, 2005 10:47 pm
Website: http://fedoraproject.org/wiki/NayyarAhmad
WLM: nayyares@hotmail.com
Location: JNB, SA

Postby mudasir » Sat Dec 29, 2007 11:25 am

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
mudasir
Captain
 
Posts: 565
Joined: Tue Oct 17, 2006 5:23 am
Website: http://www.crystalnetworks.org
Location: Dubai


Return to “%s” Programming

Who is online

Users browsing this forum: No registered users and 2 guests

cron