Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. 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

Thanks

share|improve this question
add comment

6 Answers

I don't know what you want to use the aliases exactly for, but you can get multiple interfaces working with DHCP on one physical interface by creating a bridge interface with serveral virtual interfaces (they each would have a unique mac address).

share|improve this answer
add comment

There is a not very well documented feature of iproute2 that allows to create additional virtual network interfaces, and assign different MAC addresses to them; you should then be able to run two separate instances of the DHCP client on each.

To create the virtual interface, do

ip link add link eth0 name eth1 address 00:11:22:33:44:55 type macvlan

Then try running the DHCP client.

It is legitimate to ask why you want to do this. If the machine has uses for many addresses with different roles, how will the machine figure which address to use for which role if they are dynamic ?

Also note that the ifconfig syntax with the :0 suffixes is deprecated; with iproute2 you can simply use

ip addr add 10.0.0.1/24 dev eth0
ip addr add 10.0.0.2/24 dev eth0

and so on to assign several addresses to a single interface.

share|improve this answer
add comment

As far as I know this is not possible. DHCP assigns addresses based on MAC addresses (and some rules), and all your aliases are based on the same MAC, so the DHCP server won't be able to distinguish any requests, as they all come from the same MAC. In addition to that, once the basic IP address is set, you will have a hard time convincing your DHCP client that it needs another address.

share|improve this answer
add comment

I have read where users configure MACVLANS,to pull DHCP addresses from their ISP. In doing so,the MACVLAN interface gains a new public IP address,from the ISP. Why anybody desires this,seems a little dodgy to me,unless it's for some type of load-balancing,or virtualization on the PC.(how about NAT) I can get up to eight dynamic IP addresses,from my DSL modem.(one for me,and one for my SAT box) I have tried it,and it works. You can shutdown one MACVLAN,and go to DSLreports,and find your "public" IP address. Go to the other MACVLAN,do the same,and a different "public" IP is displayed. Having one network interface,and wanting multiple DHCP addresses? Something that makes you go,"Hmmm".

share|improve this answer
add comment

There is one reason why I would see this might be desirable: Dynamic Network Address Translation. This isn't the normal Linux Masquerading type of port address translation that you usually think of, but rather the on-demand dynamic mapping of a range of real addresses to internal hosts that need to use them.

If you do dynamic NAT, you don't have to statically map ports for certain things to a single host. For example, if I have a World of Warcraft updater going on more than computer in my private network, with the ubiquitous port address translation (masquerading), only one would be able to participate in the bittorrent-like sharing that it does because you can only map exposed ports on the one outside IP address to a single inside address. If you had a list of addresses you could dynamically assign for full address translation, however, you wouldn't need to do any port mapping. Since many cable providers don't allow you to get a static allocation of a range of IP addresses, you're forced to ask for each of them using DHCP and then NAT those addresses dynamically to internal addresses. Using separate physical interfaces for dynamic NAT would be wasteful, since all you really need is more MAC addresses on the same interface.

One thing that this link points out is that you can't use dhcp on the parent physical interface for the macvlan virtual interfaces because it confuses dhcp. I haven't tried any of this, I'm actually pretty excited to try to get dhcp working on my cablemodem using macvlan interfaces, as @b0fh and @lars-bailey have suggested.

share|improve this answer
add comment

I use this and it works:

ip link add link eth0 name eth1 address 00:11:22:33:44:55 type macvlan

I have Fedora 15.

share|improve this answer
add comment

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.