1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

set MAC address at boot

Discussion in 'Networking' started by bigearsbilly, May 16, 2012.

  1. bigearsbilly

    bigearsbilly New Member

    Messages:
    143
    Likes Received:
    0
    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.
     
  2. acheron

    acheron Member

    Messages:
    114
    Likes Received:
    0
    You can create a file named /etc/start_if.em0 with the following content:
    Code:
    lladdr be:ef:be:ef:be:ef
     
  3. generic

    generic New Member

    Messages:
    16
    Likes Received:
    0
    What about:

    Code:
    ifconfig_em0="inet 10.0.0.2 netmask 255.255.255.0 ether aa:bb:cc:dd:ee:ff"
     
  4. bigearsbilly

    bigearsbilly New Member

    Messages:
    143
    Likes Received:
    0
    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.
     
  5. acheron

    acheron Member

    Messages:
    114
    Likes Received:
    0
    What about this:
    Code:
    ifconfig_em0="ether be:ef:be:ef:be:ef"
    ipv4_addrs_em0="193.35.157.168/24"
    
     
  6. SirDice

    SirDice Moderator Staff Member Moderator

    Messages:
    17,375
    Likes Received:
    3
    Why does your client want to change the MAC address?
     
  7. DutchDaemon

    DutchDaemon Administrator Staff Member Administrator Moderator

    Messages:
    10,644
    Likes Received:
    20
    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"
    
     
  8. bigearsbilly

    bigearsbilly New Member

    Messages:
    143
    Likes Received:
    0
    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.
     
  9. bigearsbilly

    bigearsbilly New Member

    Messages:
    143
    Likes Received:
    0
    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.
     
  10. phoenix

    phoenix Moderator Staff Member Moderator

    Messages:
    3,407
    Likes Received:
    1
    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.
     
  11. ecazamir

    ecazamir New Member

    Messages:
    215
    Likes Received:
    0
    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).
     
  12. bigearsbilly

    bigearsbilly New Member

    Messages:
    143
    Likes Received:
    0
    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.
     
  13. UNIXgod

    UNIXgod New Member

    Messages:
    1,089
    Likes Received:
    0
    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.
     
  14. bigearsbilly

    bigearsbilly New Member

    Messages:
    143
    Likes Received:
    0
    I think next time somebody asks me to mess about with a MAC address I will tell them to bog off!
     
  15. kpa

    kpa Member

    Messages:
    3,995
    Likes Received:
    6
    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.
     
  16. bigearsbilly

    bigearsbilly New Member

    Messages:
    143
    Likes Received:
    0
    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.
     
  17. kpa

    kpa Member

    Messages:
    3,995
    Likes Received:
    6
    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.
     
  18. bigearsbilly

    bigearsbilly New Member

    Messages:
    143
    Likes Received:
    0
    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.
     
  19. SirDice

    SirDice Moderator Staff Member Moderator

    Messages:
    17,375
    Likes Received:
    3
    Then the issue had nothing to do with the MAC address.
     
  20. Uniballer

    Uniballer Member

    Messages:
    242
    Likes Received:
    0
    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).