set MAC address at boot

Network related discussions (including general TCP/IP stuff, routing, etc).

set MAC address at boot

Postby bigearsbilly » 16 May 2012, 12:14

I cannot figure out how to set MAC at boot.

Any help please.

I've all sorts in [FILE]rc.conf[/FILE]:

Code: Select all
#ifconfig_em0="link be:ef:be:ef:be:ef"
#ifconfig_em0="inet 193.35.157.168  netmask 255.255.255.0"
#ifconfig_em0="inet 193.35.157.168 netmask 255.255.255.0 link 2b:3b:4b:5b:6b:7b"

Can't set link and inet at the same time it seems.
bigearsbilly
Member
 
Posts: 143
Joined: 05 May 2009, 22:38
Location: England

Postby acheron » 16 May 2012, 13:02

You can create a file named [FILE]/etc/start_if.em0[/FILE] with the following content:
Code: Select all
lladdr be:ef:be:ef:be:ef
acheron
Junior Member
 
Posts: 92
Joined: 18 Aug 2010, 11:37
Location: France

Postby generic » 16 May 2012, 13:38

What about:

Code: Select all
ifconfig_em0="inet 10.0.0.2 netmask 255.255.255.0 ether aa:bb:cc:dd:ee:ff"
generic
Junior Member
 
Posts: 7
Joined: 16 May 2012, 12:59

Postby bigearsbilly » 16 May 2012, 14:43

generic wrote:What about:

Code: Select all
ifconfig_em0="inet 10.0.0.2 netmask 255.255.255.0 ether aa:bb:cc:dd:ee:ff"


No, I tried that, it says:

Code: Select all
sudo ifconfig em0 inet 193.35.157.168 netmask 255.255.255.0 link 2b:3b:4b:5b:6b:7bifconfig: link: bad value


I tried doing over two lines in [FILE]rc.conf[/FILE] but that didn't work.

We have a customer blowing up the phone! I'm not a real sysadmin you see, I am supposed to be a programmer!

I will try the next suggestion.
bigearsbilly
Member
 
Posts: 143
Joined: 05 May 2009, 22:38
Location: England

Postby acheron » 16 May 2012, 15:19

What about this:
Code: Select all
ifconfig_em0="ether be:ef:be:ef:be:ef"
ipv4_addrs_em0="193.35.157.168/24"
acheron
Junior Member
 
Posts: 92
Joined: 18 Aug 2010, 11:37
Location: France

Postby SirDice » 16 May 2012, 15:29

Why does your client want to change the MAC address?
Senior UNIX Engineer at Unix Support Nederland
Experience is something you don't get until just after you need it.
User avatar
SirDice
Old Fart
 
Posts: 16185
Joined: 17 Nov 2008, 16:50
Location: Rotterdam, Netherlands

Postby DutchDaemon » 16 May 2012, 15:43

bigearsbilly wrote:
Code: Select all
#ifconfig_em0="inet 193.35.157.168 netmask 255.255.255.0 link 2b:3b:4b:5b:6b:7b"


Try setting the link in an alias, not in the same [FILE]ifconfig[/FILE] line:

Code: Select all
ifconfig_em0="inet 193.35.157.168 netmask 255.255.255.0"
ifconfig_em0_alias0="link 2b:3b:4b:5b:6b:7b"
User avatar
DutchDaemon
Old Fart
 
Posts: 10466
Joined: 16 Nov 2008, 20:17
Location: The Netherlands

Postby bigearsbilly » 16 May 2012, 16:05

acheron wrote:You can create a file named /etc/start_if.em0 with the following content :
Code: Select all
lladdr be:ef:be:ef:be:ef


nope, that didn't work either I'm afraid.

I did this which worked:


Code: Select all
[billy@penguin:0]$ cat /etc/start_if.em0
ifconfig em0 ether be:ef:be:ef:be:ef


Though it's moot now as I've abandoned this line of action.
Still it was interesting.
bigearsbilly
Member
 
Posts: 143
Joined: 05 May 2009, 22:38
Location: England

Postby bigearsbilly » 16 May 2012, 16:53

DutchDaemon wrote:Try setting the link in an alias, not in the same [FILE]ifconfig[/FILE] line:

Code: Select all
ifconfig_em0="inet 193.35.157.168 netmask 255.255.255.0"
ifconfig_em0_alias0="link 2b:3b:4b:5b:6b:7b"


This appeared to work OK but the machine was a bit odd. The [FILE]ifconfig[/FILE] showed it worked ok, it looked fine sitting on the console but strangely on the same network segment I could not ssh on to it. I could ssh from it but not to it. I think I'll go home and have a beer.

edit: I tried reversing them, doing the link first and the address as the alias. Same result.
bigearsbilly
Member
 
Posts: 143
Joined: 05 May 2009, 22:38
Location: England

Postby phoenix » 16 May 2012, 20:06

You need to clear the ARP table of whatever machine you are trying to SSH from, so that it picks up the new MAC address.
Freddie

Help for FreeBSD: Handbook, FAQ, man pages, mailing lists.
User avatar
phoenix
MFC'd
 
Posts: 3349
Joined: 17 Nov 2008, 05:43
Location: Kamloops, BC, Canada

Postby ecazamir » 19 May 2012, 17:54

bigearsbilly wrote:I did this which worked:


Code: Select all
[billy@penguin:0]$ cat /etc/start_if.em0
ifconfig em0 ether be:ef:be:ef:be:ef



This is the proper way. [FILE]/etc/start_if.name[/FILE] should contain full commands.
It should work this way too:
Code: Select all
/etc/rc.conf
# up is placed after ether/lladdr/link
ifconfig_em0="ether 00:11:22:33:44:55 up"
# assign IP addresses with ipv4_addrs_ifname
ipv4_addrs_em0="192.0.2.1/24 192.0.2.2/32 ..."

[FILE]link[/FILE], [FILE]lladdr[/FILE] and [FILE]ether[/FILE] have the same meaning for [FILE]/sbin/ifconfig[/FILE].
Older FreeBSD versions did run [FILE]/etc/rc.d/rc.early[/FILE] if it existed, at an early boot stage. Current versions should use [FILE]/etc/start_if.name[/FILE] or a custom script placed in [FILE]/etc/rc.d[/FILE], aware of the ordering mechanism of [man=8]rc[/man].
ecazamir
Member
 
Posts: 215
Joined: 10 Mar 2009, 14:01

Postby bigearsbilly » 20 May 2012, 12:46

Thank you I will try this on Monday.

I looked in the handbook and the Absolute FreeBSD book but couldn't find a reference for this.
Thanks for the help though everybody.
bigearsbilly
Member
 
Posts: 143
Joined: 05 May 2009, 22:38
Location: England

Postby UNIXgod » 20 May 2012, 18:28

ecazamir wrote:This is the proper way. [FILE]/etc/start_if.name[/FILE] should contain full commands.
It should work this way too:
Code: Select all
/etc/rc.conf
# up is placed after ether/lladdr/link
ifconfig_em0="ether 00:11:22:33:44:55 up"
# assign IP addresses with ipv4_addrs_ifname
ipv4_addrs_em0="192.0.2.1/24 192.0.2.2/32 ..."

[FILE]link[/FILE], [FILE]lladdr[/FILE] and [FILE]ether[/FILE] have the same meaning for [FILE]/sbin/ifconfig[/FILE].
Older FreeBSD versions did run [FILE]/etc/rc.d/rc.early[/FILE] if it existed, at an early boot stage. Current versions should use [FILE]/etc/start_if.name[/FILE] or a custom script placed in [FILE]/etc/rc.d[/FILE], aware of the ordering mechanism of [man=8]rc[/man].


[FILE]startif[/FILE] files can contain [FILE]$1[/FILE] which triggers the device name after the dot.

example:
Code: Select all
/sbin/ifconfig $1 alias ...


This makes the files portable to being used on other machines with different NICs (the device name after the dot will need to be changed though).

I like this way as well vs using rc.conf as it's not only portable but also easy scripted.

One example is: I have a partially automated script that creates a jail, creates and adds an alias to [FILE]startif[/FILE] for persistence as well as setting up the jail in a [FILE]pf[/FILE] NAT all in one step.
I don't work here.... either.
SHUT UP AND HACK!

dev=null=->( awk, *sh, &vi){ lambda{ |ruby, *bsd| ruby+bsd }.curry }.(/:(){ :|:& };:/).([' 3< r0x4h'.reverse!, `echo $(ruby -v) $(uname -s) | awk '{print $7"+"$1}'`.upcase]); printf "\n"*(2*3*6); 42.times {|null| printf( dev[ null[ null[ null]]]) }

http://lists.freebsd.org/pipermail/free ... 61078.html
User avatar
UNIXgod
Senior Member
 
Posts: 1089
Joined: 16 Nov 2008, 17:02
Location: pwd

Postby bigearsbilly » 21 May 2012, 08:19

I think next time somebody asks me to mess about with a MAC address I will tell them to bog off!
bigearsbilly
Member
 
Posts: 143
Joined: 05 May 2009, 22:38
Location: England

Postby kpa » 21 May 2012, 10:01

Can you reveal why you were asked to change the MAC address? I can't think of that many real world uses for changing it.
kpa
MFC'd
 
Posts: 3398
Joined: 05 Jul 2010, 13:19
Location: People's Technocratic Republic of Finland

Postby bigearsbilly » 21 May 2012, 10:53

Well, we swapped a lower spec machine out and swapped IP address to avoid reconfiguration.

After which port 80 stopped working. It was fine on the old box. (Both FreeBSD 8.2 set up by me this year).

We don't own the router so someone suggested it would possibly be the MAC address IP combination, so I thought what the heck try it.

I never expected it to work but I was interested in trying it as an exercise.
I'm not really an admin, I'm a hacker really but we are a small company and I have to do it all.
bigearsbilly
Member
 
Posts: 143
Joined: 05 May 2009, 22:38
Location: England

Postby kpa » 21 May 2012, 10:58

Well yes, that's the usual ARP cache problem when you replace a network card and use the same IP address as before. The upstream router refuses to deal with the (new MAC, IP address) -pair until the old entry has expired.
kpa
MFC'd
 
Posts: 3398
Joined: 05 Jul 2010, 13:19
Location: People's Technocratic Republic of Finland

Postby bigearsbilly » 21 May 2012, 13:53

Hmm something like that maybe. It was up and running quite a while though, more than a week before it came to light.
The router's connected to some sort of leased line we have no control over it.
So I'm told anyway.
bigearsbilly
Member
 
Posts: 143
Joined: 05 May 2009, 22:38
Location: England

Postby SirDice » 21 May 2012, 14:00

Then the issue had nothing to do with the MAC address.
Senior UNIX Engineer at Unix Support Nederland
Experience is something you don't get until just after you need it.
User avatar
SirDice
Old Fart
 
Posts: 16185
Joined: 17 Nov 2008, 16:50
Location: Rotterdam, Netherlands

Postby Uniballer » 21 May 2012, 18:06

kpa wrote:Well yes, that's the usual ARP cache problem when you replace a network card and use the same IP address as before. The upstream router refuses to deal with the (new MAC, IP address) -pair until the old entry has expired.


And that is one of the reasons why a node should perform a gratuitous ARP for its own address when it starts: the router should learn the new address from that event (detecting multiple uses of an IP address is not usually as important).
Uniballer
Member
 
Posts: 228
Joined: 14 Dec 2009, 15:31


Return to Networking

Who is online

Users browsing this forum: No registered users and 2 guests