# Forcing MAC on boot

## Barvinok

Hi.

My laptop firmware has a bug -- default MAC of the NIC is FF:FF:FF:FF:FF:FF.

 *Quote:*   

> Dolphin ~ # dmesg | grep -i eth
> 
> [    1.595332] jme: JMicron JMC2XX ethernet driver version 1.0.8
> 
> [    1.598134] netif_napi_add() called with weight 128 on device eth%d
> ...

 

Consequently, the interface is not getting up, not getting IP address assigned by the DHCP and so on.

A year ago, when net.lo and net.eth0 were still there and in effect, I solved this problem by adding mac_eth0="..correct mac here...", and everything worked well.

Then (a week ago) I had to replace hard drive on this laptop and reinstall Gentoo on it.

Before that I did the Gentoo install to two other laptops. Somehow they don't seem to have net.lo and all the stuff I got used to, they have empty /etc/conf.d/net but still their network interfaces were automagically up and running well.

But not this beast  :Sad: 

I wrote mac_eth0 entry to /etc/conf.d/net as before but it didn't work -- the interface got invalid mac on reboot. I noticed the interface got renamed to enp3s0f5 and wrote mac_enp3s0f5 to the /etc/conf.d/net but to no avail. I even tried net.ifaces=0 for kernel to avoid renaming, thinking udev may be intervening. But no. I feel like /etc/conf.d/net isn't respected anymore  :Sad: 

here's what ifconfig -a says

 *Quote:*   

> enp3s0f5: flags=4098<BROADCAST,MULTICAST>  mtu 1500
> 
> ether ff:ff:ff:ff:ff:ff  txqueuelen 1000  (Ethernet)
> 
>         RX packets 0  bytes 0 (0.0 B)
> ...

 

What is the proper MODERN way to force a MAC on a NIC ? By modern I mean having all that netifrc-whatever stuff taken into account.

Thanks in advance.

----------

## chiefbag

To switch to the old naming convention do the following, it will probably make things easier to understand.

```
touch /etc/udev/rules.d/80-net-name-slot.rules
```

----------

## Barvinok

 *chiefbag wrote:*   

> To switch to the old naming convention do the following, it will probably make things easier to understand.
> 
> ```
> touch /etc/udev/rules.d/80-net-name-slot.rules
> ```
> ...

 

I'm sorry, I don't see how this can change MAC address from incorrect to the correct one  :Rolling Eyes: 

In general I don't care how my interfaces are named. I just need a working way to set a MAC.

----------

## John R. Graham

See the examples in "/usr/share/doc/openrc-0.11.8/net.example.bz2", specifically, "mac_eth0" and friends. These go in your /etc/conf.d/net file.   :Wink: 

- John

----------

## Barvinok

 *John R. Graham wrote:*   

> See the examples in "/usr/share/doc/openrc-0.11.8/net.example.bz2", specifically, "mac_eth0" and friends. These go in your /etc/conf.d/net file.   

 

As I said in my first post

 *Barvinok wrote:*   

> I wrote mac_eth0 entry to /etc/conf.d/net as before but it didn't work -- the interface got invalid mac on reboot. I noticed the interface got renamed to enp3s0f5 and wrote mac_enp3s0f5 to the /etc/conf.d/net but to no avail.

 

Besides, I don't have /usr/share/doc/openrc-0.11.8/ despite both openrc and baselayout installed.

This is my /etc/conf.d/net

```
#

mac_enp3s0f5="00:1A:7F:B0:CD:34"

mac_eth0="00:1A:7F:B0:CD:34"

#
```

What do I do now to make sure the /etc/conf.d/net settings are respected?

----------

## John R. Graham

Well, first of all, you should have /usr/share/doc/openrc-0.11.8/net.example.bz2. Observe:

```
~ # equery list -i openrc

 * Searching for openrc ...

[IP-] [  ] sys-apps/openrc-0.11.8:0

~ # equery files openrc | grep 'net\.example'

/usr/share/doc/openrc-0.11.8/net.example.bz2
```

Perhaps you should re-emerge (--oneshot) openrc.

Second, could you post your /etc/conf.d/net file, please, and also report the version of openrc you're using?

- John

----------

## Barvinok

Problem solved.

The cause for /etc/conf.d/net not working was that I set "newnet" flag for openrc, thereby invalidating "oldnet" ways of setting custom MAC.

But newnet approach through setting in /etc/conf.d/network is also not suitable since I use DHCP, because I was told that /etc/conf.d/network is for static addresses.

Finally, I had to write custom dhcpcd hook that reset interface mac before dhcpcd takes over. Here it is

```
Dolphin ~ # cat /etc/dhcpcd.enter-hook

# Custom hook to fix wrong MAC on an interface

if [ "$reason" = PREINIT ]; then

        if [ "$interface" = "enp3s0f5" ]; then

                ifconfig $interface hw ether 00:1B:8C:7A:F0:28

                ifconfig $interface up

        fi

fi

```

Also I made sure to not add /etc/init.d/network to rc-update and to add /etc/init.d/dhcp to it.

And everything finally worked as expected.

----------

## Barvinok

 *John R. Graham wrote:*   

> Well, first of all, you should have /usr/share/doc/openrc-0.11.8/net.example.bz2. Observe:
> 
> ```
> ~ # equery list -i openrc
> 
> ...

 

```
Dolphin ~ # equery list -i openrc

 * Searching for openrc ...

[IP-] [  ] sys-apps/openrc-0.11.8:0

Dolphin ~ # equery files openrc | grep 'net\.example'

Dolphin ~ #
```

I was told these files (examples and net.lo) were moved to net-misc/netifrc for migration to newnet.

 *John R. Graham wrote:*   

> Perhaps you should re-emerge (--oneshot) openrc.

 

That does not help. Still no examples.

Besides, I do not need examples, because I'm perfectly aware of the method to set custom mac in /etc/conf.d/net -- I've been using it many times before.

The original question was absolutely unrelated to your suggestion.

 *John R. Graham wrote:*   

> Second, could you post your /etc/conf.d/net file, please, and also report the version of openrc you're using?

 

0.11.8, and my /etc/conf.d/net was posted in the message above yours, exactly one line prior.

Forgive me for being rude, but, really, it helps a lot if you read question before answering.

Thanks anyway.

----------

## John R. Graham

Well your post didn't look like your entire /etc/conf.d/net file, which is what I meant to ask for; sorry if I wasn't clear. Also, just the plain net_interfacename="mac-address" Works for Me™, so I was assuming you had made a syntax error somewhere and would benefit from the examples.

Glad you got it working, but I continue to believe there's a simpler solution.

- John

----------

