Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I would like to create several aliases to eth0, but have the addresses assigned by DHCP instead of being set to static IP's. Is this even possible?

All the examples I've seen assign a static IP using the command:

ifconfig eth0:0 192.168.1.11 up
share|improve this question

5 Answers 5

up vote 10 down vote accepted

This is only possible if the two DHCP clients use different MAC addresses. Which means they cannot run both on the same physical network interface, which has a single MAC address.

The solution is Linux's virtual MAC-VLAN network interfaces. MAC-VLAN interfaces are virtual network interfaces backed by a physical interface, but using with a different MAC address, which is randomly generated when you create a MAC-VLAN device.

Once you create a MAC-VLAN interface using a physical interface, you use it the same way like you would the physical one. In your particular case, you can run one DHCP client on the physical interface, and another on the MAC-VLAN device. Each device (physical and MAC-VLAN) can then have its own IP address.

A new MAC-VLAN device macvlan0 can be created from eth0 by running

ip link add dev macvlan0 link eth0 type macvlan

It can be deleted by running

ip link delete dev macvlan0

Using NCD, my network configuration software ( http://code.google.com/p/badvpn/wiki/NCD ), the following NCD program will create two MAC-VLAN devices from eth0 (macvlan0 and macvlan1), run DHCP on each of them, and assign them the obtained IP addresses. You easily do other stuff like add routes and DNS servers; read the NCD page if you're interested.

process lan {
    # Set device.
    var("eth0") dev;

    # Wait for device to appear, set it up, and wait for cable to be plugged in.
    net.backend.waitdevice(dev);
    net.up(dev);
    net.backend.waitlink(dev);

    # Start DHCP's.
    provide("lan-link");
}

process lan_dhcp1 {
    # Wait for link.
    depend("lan-link") linkdep;

    # Choose virtual device name.
    var("macvlan0") vdev;

    # Create virtual MAC-VLAN device.
    list("/sbin/ip", "link", "add", "dev", vdev, "link", linkdep.dev, "type", "macvlan") do;
    list("/sbin/ip", "link", "delete", "dev", vdev) undo;
    run(do, undo);

    # Set virtual device up.
    net.up(vdev);

    # DHCP configuration on virtual device.
    net.ipv4.dhcp(vdev) dhcp;
    ip_in_network(dhcp.addr, "127.0.0.0", "8") test_local;
    ifnot(test_local);

    println(vdev, ": got address ", dhcp.addr);

    # Assign address to virtual device.
    net.ipv4.addr(vdev, dhcp.addr, dhcp.prefix);
}

# This differs from above only in interface name (macvlan1).
process lan_dhcp2 {
    # Wait for link.
    depend("lan-link") linkdep;

    # Choose virtual device name.
    var("macvlan1") vdev;

    # Create virtual MAC-VLAN device.
    list("/sbin/ip", "link", "add", "dev", vdev, "link", linkdep.dev, "type", "macvlan") do;
    list("/sbin/ip", "link", "delete", "dev", vdev) undo;
    run(do, undo);

    # Set virtual device up.
    net.up(vdev);

    # DHCP configuration on virtual device.
    net.ipv4.dhcp(vdev) dhcp;
    ip_in_network(dhcp.addr, "127.0.0.0", "8") test_local;
    ifnot(test_local);

    println(vdev, ": got address ", dhcp.addr);

    # Assign address to virtual device.
    net.ipv4.addr(vdev, dhcp.addr, dhcp.prefix);
}

You'll end up with macvlan0 and macvlan1 each with its own DHCP-obtained IP address, and eth0 which is up but does not have an IP address. Alternatively, you can create just one MAC-VLAN interface, and run one DHCP instance on eth0 itself.

share|improve this answer

Using static or DHCP assigned IP addresses is a choice you make for your computer.

There is a good tutorial here.

It contains plenty of detail, and helps you avoid problems that you can have if you use static instead of DHCP assigned address, e.g. how to connect to DNS servers and gateways.

share|improve this answer

I dont know for sure But i believe unless you have a open source router then you will have to use static IP to do what you want. IMO unless you have a REALLY good reason for why you want to do what you want I would just stick witrh DHCP. from your question i see thats what you want so unless someone knows how to do it I would wait and stay with DHCP until someone gives a better answer. Although if you dont have more than 1-2 pcs and nothing else on the network (printers media extenders etc) then I would not use Static IPs as IDK how or if it is possible to set these items with a static IP. Maybe you can do what you want if you get an Open source Router and you may be able to make it do what you want like just use a static IP for your machine using the mac address as a way to identify it and set its IP and the rest of the network could bne DHCP. IDK as i have never done thins i am just throwing out ideas so Sorry for not having an answer for you. Although the link posed by Bryan looks like a nice resource on DHCP ans Static IP issues. Also For the Open Source router I believe Netgear and D-Link make them I am sure more but IMO these two brands are the ones I would choose. I personally dont like Linksys since they were bought by novel (you would think they would be better but NOT IMO. Personally I prefer D-link as they are the most customizeable routers i have found.)

Also check out this link and you may be able to do more with your router if it is supported

This site has Router Firmware

share|improve this answer

I have never seen a DHCP configuration which would allow the DHCP server to send multiple addresses to an interface. I don't believe the protocol supports it. Once you get into multiple IP addresses on an interface, you really should configure them as static addresses.

Some DHCP clients allow static address to be assigned when an address is supplied. I don't believe Windows will allow you to add more than one.

Make sure all your static addresses are outside the DCHP address range.

share|improve this answer

No, you can't do that. DHCP assigns an IP based on your hardware address. Each physical interface only have one of those, thus DHCP will only assign one IP to a physical interface.

I would advise you to just set the interface IPs statically.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.