set MAC address at boot

bigearsbilly

Active Member

Reaction score: 5
Messages: 143

I cannot figure out how to set MAC at boot.

Any help please.

I've all sorts in rc.conf:

Code:
#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.
 

acheron

Aspiring Daemon

Reaction score: 227
Messages: 600

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

generic

Member

Reaction score: 6
Messages: 45

What about:

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

bigearsbilly

Active Member

Reaction score: 5
Messages: 143

generic said:
What about:

Code:
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:
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 rc.conf 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.
 

acheron

Aspiring Daemon

Reaction score: 227
Messages: 600

What about this:
Code:
ifconfig_em0="ether be:ef:be:ef:be:ef"
ipv4_addrs_em0="193.35.157.168/24"
 

SirDice

Administrator
Staff member
Administrator
Moderator

Reaction score: 8,021
Messages: 31,497

Why does your client want to change the MAC address?
 

DutchDaemon

Administrator
Staff member
Administrator
Moderator
Developer

Reaction score: 2,840
Messages: 11,317

bigearsbilly said:
Code:
#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 ifconfig line:

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

bigearsbilly

Active Member

Reaction score: 5
Messages: 143

acheron said:
You can create a file named /etc/start_if.em0 with the following content :
Code:
lladdr be:ef:be:ef:be:ef
nope, that didn't work either I'm afraid.

I did this which worked:


Code:
[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.
 
OP
OP
B

bigearsbilly

Active Member

Reaction score: 5
Messages: 143

DutchDaemon said:
Try setting the link in an alias, not in the same ifconfig line:

Code:
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 ifconfig 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.
 

phoenix

Administrator
Staff member
Administrator
Moderator

Reaction score: 1,260
Messages: 4,099

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.
 

ecazamir

Active Member

Reaction score: 29
Messages: 216

bigearsbilly said:
I did this which worked:


Code:
[billy@penguin:0]$ cat /etc/start_if.em0 
ifconfig em0 ether be:ef:be:ef:be:ef
This is the proper way. /etc/start_if.name should contain full commands.
It should work this way too:
Code:
/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 ..."
link, lladdr and ether have the same meaning for /sbin/ifconfig.
Older FreeBSD versions did run /etc/rc.d/rc.early if it existed, at an early boot stage. Current versions should use /etc/start_if.name or a custom script placed in /etc/rc.d, aware of the ordering mechanism of rc(8).
 
OP
OP
B

bigearsbilly

Active Member

Reaction score: 5
Messages: 143

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.
 

UNIXgod

Daemon

Reaction score: 200
Messages: 1,088

ecazamir said:
This is the proper way. /etc/start_if.name should contain full commands.
It should work this way too:
Code:
/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 ..."
link, lladdr and ether have the same meaning for /sbin/ifconfig.
Older FreeBSD versions did run /etc/rc.d/rc.early if it existed, at an early boot stage. Current versions should use /etc/start_if.name or a custom script placed in /etc/rc.d, aware of the ordering mechanism of rc(8).
startif files can contain $1 which triggers the device name after the dot.

example:
Code:
/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 startif for persistence as well as setting up the jail in a pf NAT all in one step.
 
OP
OP
B

bigearsbilly

Active Member

Reaction score: 5
Messages: 143

I think next time somebody asks me to mess about with a MAC address I will tell them to bog off!
 

kpa

Beastie's Twin

Reaction score: 1,810
Messages: 6,318

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.
 
OP
OP
B

bigearsbilly

Active Member

Reaction score: 5
Messages: 143

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.
 

kpa

Beastie's Twin

Reaction score: 1,810
Messages: 6,318

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.
 
OP
OP
B

bigearsbilly

Active Member

Reaction score: 5
Messages: 143

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.
 

SirDice

Administrator
Staff member
Administrator
Moderator

Reaction score: 8,021
Messages: 31,497

Then the issue had nothing to do with the MAC address.
 

Uniballer

Well-Known Member

Reaction score: 63
Messages: 335

kpa said:
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).
 
Top