Make some virtual MAC address

47,214

Solution 1

All you need to do is

ip link add link eth0 address 00:11:11:11:11:11 eth0.1 type macvlan

then turn on the virtual network interface

ifconfig eth0.1 up

and then optionally acquire an ip via dhcp with

dhclient -v eth0.1

Solution 2

You do not need more that one MAC address to have multiple ip addresses on a single network interface. This technique is called ip aliasing.

Each operative system has a slightly different syntax but usually, to set different IP addresses on the same interface, you need only to do something like:

ifconfig eth0 192.168.100.200 netmask 255.255.255.0
ifconfig eth0:1 192.168.120.200 netmask 255.255.255.0
ifconfig eth0:2 192.168.130.200 netmask 255.255.255.0

The example above works on Linux. On BSD, you need something like:

ifconfig lnc0 192.168.100.200 netmask 255.255.255.0
ifconfig lnc0 192.168.120.200 netmask 255.255.255.0 alias
ifconfig lnc0 192.168.130.200 netmask 255.255.255.0 alias

Solution 3

Edit: Add hint for setting up virtual device:

First set up an additional device e.g.:

ifconfig eth0:1 up

The you might additionally add an IP to it. e.g.:

ifconfig eth0:1 10.0.0.20 broadcast 10.255.255.255 netmask 255.255.255.255

If you really want to, you can also alter the MAC-address:

ip link set eth0:1 address 02:73:53:00:ca:fe

Note that the second bit of the first byte has to be set to signal a locally administered address (LAA) - which says that this MAC-address is only locally valid (e.g. within your enterprise network) and might not be unique world wide (so you can assign your own MAC-addresses without the need to register them officially).

Solution 4

This is working for me on Linux (Kali). You may need to change addresses, gateways, or netmasks based on your personal situation. Sorry if you don't need this, for the next person to stumble here though, as I did moments ago.

Where <your-nicN> is what you see from an ifconfig such as eth0 or wlan0

sudo ip link add link <your-nicN> mac0 type macvlan && sudo ifconfig mac0 up

That creates a new "virtual" interface called mac0 and brings it up. I added the the up command because a first I thought this didn't work, but sudo ip link show [tab][tab] plus a double tab completed with a list that included mac0 I then proceeded to bring it up with ifconfig and assign it an address.

Just Remember to assign it an ip address or tell it to use dhcp

ifconfig mac0 inet 192.168.1.107 netmask 255.255.255.0 #static/manual config

or

dhclient mac0 # For a dhcp-client, to get ip from router.

if you need to assign a default gateway:

sudo ip route add default via 192.168.1.1 

The place I got some of this from is here: http://www.pocketnix.org/posts/Linux%20Networking:%20MAC%20VLANs%20and%20Virtual%20Ethernets

Edit3: I tried messing with "bond" and ifenslave but I need to do a bit more studying on that, I couldn't really figure it out. What I did do though what set up an "EtherSwitch Router" in GNS3 and then assigned a "cloud" ten of the macN devices on one "end" and then another "cloud" to a vmware host only adapter, virtualbox would probably work the same, on the other "end", I am going to mess around with that a bit and see if I can limit the speed on the macN devices to simulate an "aggregation" or if I can distribute the load across the ten connections for "increased" bandwidth. Maybe if I set them all to txqueuelen:10 on Linux. I have DragonflyBSD on the other "end" of this, I will attempt to connect it to my real router via GNS3.

Edit2: Here is a quick script to get as many up as you need with dhclient. It needs to be ran as root. So create the file, then chmod 750 <script> and run it with sudo if you can/have to. I use it like this : ./crazy-mac.sh 20 it takes the first argument and creates that many new interfaces each with its own mac and ip address. There are no sanity checks so use it wisely, or add some yourself ;)

Note : Make sure to connect with your normal wlan0 first or else this wont work. how-to-connect-manually-to-a-wireless-ap Also if their is mac access control list on the router you might need to do some some sniffing to gain a list of mac address accepted by the router. You will then need to edit the script to parse a file with that list and use a line for each $i in the sequence instead of allowing this to create random mac addresses.

Note2: You might want to put some a sleep <N> in the loop somewhere, this will bring up many "devices" sequentially and will probably raise some red flags if anyone is paying attention to the network. I don't think 20 some devices will pop up in this fashion under normal circumstances.

#!/bin/sh
## crazy-mac.sh
for i in $(seq ${1}); do
    ip link add link wlan0 mac${i} type macvlan && \
    ifconfig mac${i} up && \
    dhclient mac${i};
done

And to bring them down: Again just a quick script...

#!/bin/sh
## crazy-down.sh
for i in $(seq ${1}); do
    ifconfig mac${i} down && \
    ip link delete mac${i};
done

And if you need a list of mac addresses this is working with bash when a file is a list of one mac address per line in the file.

#!/bin/bash
## crazy-mac2.sh
## Usage : crazy-mac2.sh <N> </path/to/mac-list.txt>
MACLIST=($(cat ${2}))

# This is for testing, comment this and uncomment out the other for loop
# if this one works the other should also.
for i in $(seq ${1}); do
    echo "mac${i} :  ${MACLIST[${i}-1]}"; done

#for i in $(seq ${1}); do
#    ip link add link wlan0 mac${i} address ${MACLIST[${i}-1]} type macvlan && \
#    ifconfig mac${i} up && \
#    dhclient mac${i};
#done

unset MACLIST

Edit: I was just reading about "lagg" devices (at least for unix) that can be used to aggregate multiple interfaces into a single "lagg" interface to increase performance or to provide fall backs should one go down for whatever reason.

I was just thinking about how this would be useful in a situation where the bandwidth was limited per mac address, it might be able to be used in such a situation so that you can take all the many virtual macN interfaces and aggregate the bandwidth into a single interface and then perhaps tun/tap that to a virtual host or something. This is interesting to me, I'll try to set up bandwidth limit on my personal wifi per mac address to recreate the scenario and attempt this I'll be back.

Share:
47,214

Related videos on Youtube

Vikash B
Author by

Vikash B

I'm Moein who is into GNU/Linux, programming, open source and reading. Currently, I'm at AmirKabir University of Technology (Tehran Polytechnic) for M.S of Information Technology. My search interests are Natural Language Processing, Big Data and Machine Learning. Also, my thesis is about Forecasting the news impact on different aspects of social media users political opinions. Right now I work at BisPhone as Software Engineer. I took up my B.A in Computer Engineering from K.N.Toosi University of Technology and also graduated from Nodets for middle and high school.

Updated on September 18, 2022

Comments

  • Vikash B
    Vikash B almost 2 years

    I want to make some virtual MAC addresses for my network adapter or wireless adapter, so I can connect to network with more than one IP address from one computer or laptop.

    How can I do it? (I know it's possible ,because one of my friends done it in university and have more than one - sometimes up to 255 - IP addresses on a network).

    • serb
      serb over 12 years
      you have to specify which operative system are you using and, eventually, which distribution.
    • S edwards
      S edwards over 10 years
      @Moein7tl be aware that if sysadmin reduce the bandwidth for each user it's probably to avoid people downloading illegaly and to put more priority to more important traffic like search data, or cloud computation... Try not to exploit the limit of the system just to get a decent bandwiidth.
  • Vikash B
    Vikash B over 12 years
    In our university wireless network,the system gives one ip address to each mac address from 8 A.M till 9 P.M ,and the system limits each ip to max of 32KB of speed,if I can make virtual mac address,so it can't detect my laptop as one and it will gives more than one ip address to me.
  • Vikash B
    Vikash B over 12 years
    but when I connect to my home wireless network with it,it can only change mac address,and my modem doesn't give me 2 or more ip address.I only see one mac address in my modem pages.
  • Nils
    Nils over 12 years
    You need to set up an additional virtual device first, of course. That is why I said "also". Look at the answer to your question that outlines ip-aliasing. I prefer using a netmask of 255.255.255.255 for these. But you did not ask for virtual IPs, and sometimes it is enough to have a device up and running with a MAC.
  • serb
    serb over 12 years
    Please @Moein7tl, edit your question and specify that you are searching a method to get assigned more than one ip address by your university dhcp server.
  • JojOatXGME
    JojOatXGME over 7 years
    As far as I know, you cannot have different MAC addresses for eth0 and ´eth0:1´. Assuming you create eth0:1 as described. To be sure, I tested it on my system. The last command (ip link ...) has changed the MAC address of both "interfaces". This means eth0 itself has got the new MAC address as well. The reason is, that ifconfig eth0:1 up will not create a new link. It will only add an IP address to an existing one. Creating a macvlan link seems to be the way to go.