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?

1

2 Answers 2

0

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

8
  • Do I actually have to use a virtual interface or can ip associate a second IP with a different MAC automatically? Commented Nov 8, 2013 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.. Commented Nov 8, 2013 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... Commented Nov 8, 2013 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.. Commented Nov 8, 2013 at 10:43
  • 1
    Not unless you specify the values it needs.. try ifconfig eth0:1 <ip> netmask <mask> , up calls the ifcfg-eth0:1 script. Commented Nov 8, 2013 at 10:52
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.

6
  • 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 Commented Nov 8, 2013 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? Commented Nov 8, 2013 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. Commented Nov 8, 2013 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) Commented Nov 8, 2013 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 allow assigning multiple MACs to one physical interface Commented Nov 11, 2013 at 8:49

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.