0

(Similar to this question, but with two different DHCP-assigned IPs)

Is there any way to let dhclient or dhcpcd request two different IPs for one physical interface, e.g. via virtual interfaces eth0 and eth0:1? Maybe by letting eth0:1 have a different MAC? Or by creating a virtual eth1 bridged to eth0? Or can I use ip addr add directly somehow?

Tobias Kienzler
  • 388
  • 1
  • 9
  • 28

2 Answers2

0

If eth0:1 has a different MAC, dhcpd should provide a second address automatically, unless it is on a different VLAN.

NickW
  • 10,183
  • 1
  • 18
  • 26
  • Do I actually have to use a virtual interface or can `ip` associate a second IP with a different MAC automatically? – Tobias Kienzler Nov 08 '13 at 10:01
  • 1
    You could have the same MAC address on a second interface, but you would probably have to add the ip manually or via the system configuration files. If you're asking if a single interface can have multiple MAC addresses, no, that's why there are interfaces like eth0:1, eth0:2, etc.. – NickW Nov 08 '13 at 10:29
  • That makes sense, thanks. Turns out my kernel doesn't currently support virtual interfaces (`ifconfig eth0:1 up` yields `SIOCSIFFLAGS: Cannot assign requested address`, and `ip link add link eth0 mac0 type macvlan` a `RTNETLINK answers: Operation not supported`) so I have to fix _that_ first... – Tobias Kienzler Nov 08 '13 at 10:39
  • You did create the corresponding files for eth0:1 `/etc/sysconfig/network-scripts/ifcfg-eth0:1` and made sure the Device name at the top is `eth0:1` ? This of course the RH model, Debian systems use a different one.. – NickW Nov 08 '13 at 10:43
  • No, but since currently I just want to temporarily test whether this works at, shouldn't `ifconfig eth0:1 up` suffice? – Tobias Kienzler Nov 08 '13 at 10:47
  • 1
    Not unless you specify the values it needs.. try `ifconfig eth0:1 netmask ` , up calls the ifcfg-eth0:1 script. – NickW Nov 08 '13 at 10:52
  • Hm, if I assign a static IP `eth0:1` is up, but static is what I'd like to avoid... And if I add `hw ether SOMEMAC` the MAC gets also assigned to `eth0` – Tobias Kienzler Nov 08 '13 at 10:53
  • It would be a lot easier to make a new file for the eth0:0 interface, copy the eth0 file, and name it eth0:0, change the device name at the top, then alter any other options, like the MAC, the IP (if it's static, etc).. – NickW Nov 08 '13 at 10:56
0

No. The virtual interface is still the same underlying physical interface, and the MAC address is part of the physical interface, not the virtual interface.

You need to make one of the addresses static.

fukawi2
  • 5,327
  • 3
  • 30
  • 51
  • I am very certain that this is either wrong or we misunderstand one another - a virtual machine can easily obtain its own IP via (a bridge and) DHCP – Tobias Kienzler Nov 08 '13 at 10:16
  • 1
    So, if I type `ifconfig eth0:2 down` `ifconfig eth0:2 ifconfig hw ether 11:22:33:44:55:66` then `ifconfig eth0:2 up` I wouldn't actually be changing the address? – NickW Nov 08 '13 at 10:27
  • @NickW Unless something has changed since the last time I tried this, then that is correct. Your commands don't work for me on CentOS 6 (`ifconfig eth0:1 hw ether 11:22:33:44:55:66` == `SIOCSIFHWADDR: Device or resource busy`). I am happy to be corrected if this has been changed in recent kernels. – fukawi2 Nov 08 '13 at 22:00
  • @TobiasKienzler My understanding is that we're talking about Virtual NIC's (ie, eth0:1), not Virtual Machines (eg, KVM, Xen etc) – fukawi2 Nov 08 '13 at 22:01
  • Hm, now when I re-read my question I realize I have indeed unnecessarily narrowed it, I broadened it a bit now - from what I read so far (but could not test due to a lack of supporting Kernel) at the very least iproute2's `macvlan` [should](http://serverfault.com/a/224295/45248) allow assigning multiple MACs to one physical interface – Tobias Kienzler Nov 11 '13 at 08:49
  • @fukawi2 In your ifcfg-ethX files, if you add MACADDR= you can assign it a different address. I can't see in the ifconfig man pages if it is possible to do it via the command line, you do need to make sure the interface is down. – NickW Nov 11 '13 at 09:31