Getting 2 IP addresses on one network card, using DHCP
As a DHCP reply is based on the MAC address of the requesting interface, with a single physical interface, the answer is "you can't". The only way to do this would be with a script.
Perhaps something like (with a subinterface defined on the primary):
- Primary interface issues DHCP and gets IP address
- macchanger changes MAC address of interface
- Sub interface issues DHCP and gets IP address
- Revert mac address with macchanger
Kill the dhcp client, so that it doesn't automatically run later. Work out the lease time of the IP address you are given, and schedule this script to run again before the lease expires.
Update
For this you will need iproute2 installed. The following command adds a virtual interface bound to an existing eth0 interface:
ip link add link eth0 address 00:11:22:33:44:55 virtual0 type macvlan
Replace the mac and "virtual0" name of the interface to whatever you like. Turn it on:
ip link set virtual0 up
Then configure using dhcpd or dhclient or ifconfig as needed. I have tested this on Debian squeeze - your distro may not have everything needed enabled in the kernel (macvlan particularly).
As @JesseChisholm suggested, it is way easier to ask the right thing to the DHCP server instead of making complex network setups.
For OpenWRT I could simply run:
# udhcpc -i eth0:1 -x 0x3d:0100BEEFC0FFEE
Which resulted in having two ip addresses from the same dhcp server.
The 0x36 is option 61 which is the client id option. After the : there is an hex byte option. This came from the help option of udhcpc:
# udhcp --help
BusyBox v1.22.1 (2014-10-08 16:34:50 HKT) multi-call binary.
Usage: udhcpc [-fbqRB] [-t N] [-T SEC] [-A SEC/-n]
[-i IFACE] [-s PROG] [-p PIDFILE]
[-oC] [-r IP] [-V VENDOR] [-F NAME] [-x OPT:VAL]... [-O OPT]...
...
-x OPT:VAL Include option OPT in sent packets (cumulative)
Examples of string, numeric, and hex byte opts:
-x hostname:bbox - option 12
-x lease:3600 - option 51 (lease time)
-x 0x3d:0100BEEFC0FFEE - option 61 (client id)