# MAC address

## Xerxes83

Is it possible to configure Gentoo to automatically assign one of my network cards a specific MAC address? Currently I use a special init script, but it would  be much neater if the mac address was re-assigned after I stop/start the interface. I figured the place for the configuration would be /etc/conf.d/net, but nothing there.

----------

## UberLord

Baselayout-1.11.6-r1 provides the facility to change your mac address easily. You need to emerge net-analyzer/macchanger

Then you can do mac_eth0="00:11:22:33:44:55" in /etc/conf.d/net

You may need to consult Bug #71929

----------

## Xerxes83

Thanks for your reply. But why is macchanger required? The code "ifconfig eth0 hw ether AA:FF:EE:00:00:00" seems to suffice for me. And is it safe to upgrade to Baselayout-1.11.6-r1 (it's marked ~x86)?

----------

## UberLord

macchanger has plently more options besides just setting a given mac address. For example you can request a random MAC of a given hardware vendor.

Also, we try and make the interface configuation relatively abstract so we can support other configuration methods - such as iproute2. iproute2 does a much better job of configuring your network than ifconfig et all - but it does not support the changing of a mac address.

If you don't like going to ~x86 baselayout, you can always put the following in /etc/conf.d/net for the same effect

```

preup() {

   [[ ${IFACE} == eth0 ]] && ifconfig eth0 hw ether AA:FF:EE:00:00:00

}
```

----------

## Xerxes83

Thanks for the solutions and for explaining why macchanger is required. Everything works now.

----------

## DarKRaveR

 *UberLord wrote:*   

> iproute2 does a much better job of configuring your network than ifconfig et all - but it does not support the changing of a mac address.
> 
> 

 

Humm, really ? I thought ip link set address LLADDR should change the link layer (and thus MAC, for ethernet) adress ???

----------

## UberLord

 *DarKRaveR wrote:*   

>  *UberLord wrote:*   iproute2 does a much better job of configuring your network than ifconfig et all - but it does not support the changing of a mac address.
> 
>  
> 
> Humm, really ? I thought ip link set address LLADDR should change the link layer (and thus MAC, for ethernet) adress ???

 

I didn't know that :/

----------

## UberLord

As a result, baselayout-1.12.0 will support changing mac address to a specific address without macchanger being installed  :Smile: 

Don't ask when it's going to even hit unstable though ....

----------

## DarKRaveR

Short update: I tried setting the mac with iproute2 and it works like a charm.

side from that: Sometimes it's nice to name interfces after the mac adress, to have more symbolic interface names.

since iproute2 supports this, it might be nice to implement that too.

If I am correct the card has it's normal MAC after reboot, so maybe it would be best to name the interface after the mac (first) to make sure each card has the symbolic name desired an then change the mac (since this needs an interface name).

I am not sure though if the order really makes sense.

With bst wishes

-DarKy

----------

## UberLord

The problem I have with this is that the net.eth1 script is currently running as eth1 ..... so the script cannot do this - unless the script starts net.newname and stops net.oldname.

But whats the point of that when udev does such a good job of device naming by itself?

----------

## DarKRaveR

Mmmh, good point indeed.

Didn't think about this - or rather, didn't really look into udev yet.

My fault   :Wink:  .

----------

