Solved

Shellscript for MAC-check.

Posted on 2004-04-16
7
295 Views
Last Modified: 2010-04-20
i need a sh-script which will issue a reboot unless the MAC adress of eth0 and eth1 are the correct ones.

(For some reason, a system we have swaps eth0 and eth1 around about once in every 20 reboots.)
0
Comment
Question by:j2
7 Comments
 
LVL 45

Expert Comment

by:sunnycoder
ID: 10841252
Hi j2,

> (For some reason, a system we have swaps eth0 and eth1 around about once in every 20 reboots.)
Are you sure ? MAC addresses are hardcoded into the device :o)

Linux on booting names the dvices sequentially (if they have not been already named) ... I guess you are being troubled by that naming

Sunnycoder
0
 
LVL 1

Expert Comment

by:ipuschner
ID: 10841263
Hi!

Why that complicated?! How about this script:
<script>

#! /bin/bash
#Idea by Igor Puschner
ifconfig eth0 down
ifconfig eth1 down
ifconfig eth0 hw ether XX:XX:XX:XX:XX:XX
ifconfig eth1 hw ether YY:YY:YY:YY:YY:YY
ifconfig eth0 up
ifconfig eth1 up

</script>


Just replace XX:XX:XX:XX:XX:XX with the Mac Adress for eth0, and YY:YY:YY:YY:YY:YY with the MAc adress for eth1.
It should work fine, as long as eth0 and eth1 have both the same speed (i guess so).
No reboot needed!

Greets Igor
0
 
LVL 20

Accepted Solution

by:
Gns earned 50 total points
ID: 10841410
just for completeness... The very simple "check-n-reboot" script:
#!/bin/bash
ETH0MAC="......"
REALMAC="$(/sbin/ifconfig eth0 | awk '$0 ~ /HWaddr/ {print $NF}')"

if [ "$ETH0MAC" != "$REALMAC" ]
then
  echo "REBOOTING DUE TO MAC MISSMATCH"
  sleep 3
  /sbin/reboot
fi
# End of script

Needs to run after network initialization... perhaps from /etc/rc.local (or similar construct that come very late in the bootup process).

-- Glenn
0
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
LVL 12

Author Comment

by:j2
ID: 10841545
ipuschner: Sorry, that is not what i want. For more then one reason, i _need_ the system to reboot when it happens.

Gns: Thanks, i realize that i simply do not master the "if" statement in shell programming. Thanks.
0
 
LVL 12

Author Comment

by:j2
ID: 10841563
sunny coder: Well, whatever the reason is, some times the "wrong" NIC becomes eth0, which can be a nuisance since the system is a firewall.
0
 
LVL 20

Expert Comment

by:Gns
ID: 10841771
:-) j2.
One not to uncommon solution is to have heterogenous NICs... So that you actually load different modules for the different interfaces.
I have a nagging feeleing I've seen something very nice for this with homogenous NICs (very likely would be completely driver dependant)... Oh for better memory...:-)

-- Glenn
0
 
LVL 12

Author Comment

by:j2
ID: 10844046
Nope, Two different NIC's, different line-speeds, and 802.11q enabled on one :)

I figure that running your script as an "up" script (debian) for eth1 should take care of it.

Have a pleasent weekend!
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

In this tutorial I will explain how to make squid prevent malwares in five easy steps: Squid is a caching proxy for the Web supporting HTTP, HTTPS, FTP, and more. It reduces bandwidth and improves response times by caching and reusing frequently-…
The purpose of this article is to demonstrate how we can use conditional statements using Python.
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now