WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

Author Topic: How to use nameif?  (Read 1621 times)

Offline glareboa

  • Newbie
  • *
  • Posts: 14
How to use nameif?
« on: April 16, 2016, 11:09:25 AM »
I have installed three network cards.
I want to bind the MAC address and network interface name.
Doing so.
In the file bootlocal.sh add lines
nameif eth0 08:00:27:44:C8:F0
nameif eth1 08:00:27:D3:5C:C0
nameif eth2 08:00:27:65:04:EE
ifconfig eth0 192.168.1.200 netmask 255.255.255.0 up
ifconfig eth1 192.168.3.200 netmask 255.255.255.0 up
ifconfig eth2 192.168.4.200 netmask 255.255.255.0 up

But it's not working.
What you're doing wrong?

Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11220
Re: How to use nameif?
« Reply #1 on: April 16, 2016, 02:18:55 PM »
Hi glareboa
From:
http://man7.org/linux/man-pages/man8/nameif.8.html
Quote
nameif should be run before the interface is up, otherwise it'll fail.
Try adding the  nodhcp  bootcode to your bootloader.

Offline glareboa

  • Newbie
  • *
  • Posts: 14
Re: How to use nameif?
« Reply #2 on: April 16, 2016, 07:38:39 PM »
Hi Rich.

I tried to do that.
Here's a line of extlinux.conf
APPEND initrd=/tce/boot/core.gz nodhcp quiet waitusb=5:UUID="b8aa898e and so on
Nothing changes.
If I do a reboot, the MAC address of the eth0 becomes the other.
Forgot to say earlier that I use CorePlus.iso v.7.0

Offline glareboa

  • Newbie
  • *
  • Posts: 14
Re: How to use nameif?
« Reply #3 on: April 18, 2016, 05:45:21 AM »
Tried to do

nameif eth0 1C:6F:65:59:D1:65
nameif eth1 00:11:95:F5:8C:CC
nameif eth2 00:10:5A:E3:82:55
ifconfig eth0 hw ether 1C:6F:65:59:D1:65
ifconfig eth1 hw ether 00:11:95:F5:8C:CC
ifconfig eth2 hw ether 00:10:5A:E3:82:55

10.11.8.18 ifconfig eth0 netmask 255.255.255.0 up
168.192.5.237 ifconfig eth1 netmask 255.255.255.0 up
168.192.1.237 ifconfig eth2 netmask 255.255.255.0 up

Works stably.

Offline glareboa

  • Newbie
  • *
  • Posts: 14
Re: How to use nameif?
« Reply #4 on: April 21, 2016, 12:55:13 AM »
Hi.
I'm sorry, but this option does not always work.
The documentation found the following information:

Using the nameif program

Alternative to the get-mac-address.sh script, you can also use the slightly more convenient nameif program, which is distributed as part of the net-tools package on Debian.

The advantage of nameif is that you can specify the interface names in the / etc / mactab file:

ethmgnt 00: 37: E9: 17: 64: AF
ethwireless 00: 21: E9: 17: 64: B5

It is not possible to rename an interface to a name of an existing interface. So you can not rename eth1 to eth0 as long as eth0 still exists. It is possible to still swap the names eth0 and eth1 by using a temporary name (e.g. first rename eth1 to ethfoo, then eth0 to eth1 and finally ethfoo to eth0). Note that this method may lead to problems if you use common names such as eth0 and eth1. If you upgrade a kernel, the names may be different than you expected, and you may rename a NIC to eth0 while eth0 still exists, leading to name collisions. Therefor, it is recommended to use other names like "ethmgmnt", "ethwired", "ethwireless" and "eth10ge", as shown in the example above.



It turns out that nameif does not work because the names eth0, eth1, eth2 already exist.

The tc-config file:

if [-n "$ AOE"]; then
IFACE = $ (echo $ AOE | awk -F: '{print $ 1}')
DEV = $ (echo $ AOE | awk -F: '{print $ 2}')
ifconfig $ IFACE up
modprobe aoe
echo "$ {BLUE} Waiting for $ DEV $ {NORMAL}"
CNT = 120
until [-e / dev / etherd / interfaces]
do
[$ ((- CNT)) -le 0] && break
echo -ne "$ {RED} $ CNT \ r"
sleep 1
done
printf "% s \ 0" $ IFACE> / dev / etherd / interfaces
echo> / dev / etherd / discover
until [-e / dev / etherd / $ DEV]
do
[$ ((- CNT)) -le 0] && break
echo -ne "$ {RED} $ CNT \ r"
sleep 1
done
if [$ CNT -gt 0]; then
ln -s / dev / etherd / $ DEV / dev / $ DEV
mkdir -p / mnt / $ DEV
mount / dev / $ DEV / mnt / $ DEV> / dev / null 2> & 1
else
echo -ne "\ n $ DEV NOT mounted Press <ENTER>!"; read junk
fi
echo "$ {NORMAL}"
fi

Therefore, in nameif bootlocal.sh not going to work.

Let's try to do so:

First, we give new names to network interfaces.
And then rename as it is necessary to us.

Now bootlocal.sh is:

#! / Bin / sh
# Put other system startup commands here
# give new names to network interfaces.
nameif zeth0 1C: 6F: 65: 59: D1: 65
nameif zeth1 00: 11: 95: F5: 8C: CC
nameif zeth2 00: 10: 5A: E3: 82: 55
#rename as it is necessary to us.
nameif eth0 1C: 6F: 65: 59: D1: 65
nameif eth1 00: 11: 95: F5: 8C: CC
nameif eth2 00: 10: 5A: E3: 82: 55
ifconfig eth0 10.11.8.18 netmask 255.255.255.0 up
ifconfig eth1 192.168.5.237 netmask 255.255.255.0 up
ifconfig eth2 192.168.1.237 netmask 255.255.255.0 up
route add default gw 10.11.8.254
route add -net 192.168.2.0 netmask 255.255.255.0 gw 192.168.5.250

Nameif now work correctly