Thursday, May 2, 2024
 Popular · Latest · Hot · Upcoming
8
rated 0 times [  8] [ 0]  / answers: 1 / hits: 21771  / 2 Years ago, wed, january 5, 2022, 3:32:48

If I want to have 2 static IP addresses, I can do something like this:



auto eth0
iface eth0 inet static
address 192.168.1.10
netmask 255.255.255.0
broadcast 192.168.1.255

auto eth0:0
iface eth0:0 inet static
address 192.168.1.11
netmask 255.255.255.0
broadcast 192.168.1.255


However, I'd like to use DHCP to get addresses. I tried the following:



auto eth0
iface eth0 inet dhcp

auto eth0:0
iface eth0:0 inet dhcp


...but I only end up with eth0, and no second IP. Is there a simple way to go about this?


More From » networking

 Answers
7

After a little bit of research, apparently you can't do that.



The sub-interface cannot request another IP address because it is using the same MAC address as the physical interface, and since DHCP requests are by MAC address, you can't get two IPs for the same interface.



An answer from SuperUser suggests the following two methods:




Method 1



Create a script that will do something like this (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.

  5. 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.



Method 2



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




Source: SuperUser: Getting 2 IP addresses on one network card, using DHCP



Other sources:




[#23788] Wednesday, January 5, 2022, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
odyroc

Total Points: 324
Total Questions: 109
Total Answers: 103

Location: Belize
Member since Mon, Apr 17, 2023
1 Year ago
odyroc questions
;