15:18 - Sunday, 20 April 2014

Getting 2 IP Addresses On One Network Card, Using DHCP

#Topics: 2013 dhcp bound to virtual network card,two ip addresses on one network card,request two dhcp addresses from dhcp,one nic 2 ip addresses automatically,ntwork card with two ip address

Given: A computer running Linux (CentOS 5.x), one network card connected to LAN switch, a second one to cable modem via crossover cable. This computer acts as a router/firewall/traffic shaper for the local network.

Computer gets its public IP address from an ISP via DHCP. I know my ISP can supply 2 IP addresses to clients (when cable modem is connected directly to a hub, etc.). I would like to get 2 IP addresses on one computer that is connected to the ISP. It will simplify traffic segregation, NAT and shaping.

I know I can probably “fake” DHCP requests and bang together some scripts that will do this, but I wonder if somebody knows an easier and proper way.

Question: How can I make a Linux computer request two IP addresses via DHCP and assign both of them to one network card?

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):

  1. Primary interface issues DHCP and gets IP address
  2. macchanger changes MAC address of interface
  3. Sub interface issues DHCP and gets IP address
  4. 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 virtua0 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).

Share

Advertisement

Comment