14

To Create a Fake Ethernet dummy Interface On Linux we First initialize the dummy interface driver using the below command: /sbin/modprobe dummy.
Then we Assign Ethernet Interface alias To Dummy Driver we just initialized above.

But it gives the following Fatal error saying: FATAL: Module dummy not found.

Also, at the path cd /sys/devices/virtual/net# , we can see that there are virtual interfaces present by the following names:
dummy0/ lo/ sit0/ tunl0/

ifconfig -a

dummy0:   Link encap:Ethernet  HWaddr aa:3a:a6:cd:91:2b    
          BROADCAST NOARP  MTU:1500  Metric:1  
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0  
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0   
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)

lo:     Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0  
          inet6 addr: ::1/128 Scope:Host  
          UP LOOPBACK RUNNING  MTU:16436  Metric:1  
          RX packets:111 errors:0 dropped:0 overruns:0 frame:0  
          TX packets:111 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0   
          RX bytes:8303 (8.1 KiB)  TX bytes:8303 (8.1 KiB)

sit0:      Link encap:UNSPEC  HWaddr 00-00-00-00-FF-00-00-00-00-00-00-00-00-00-00-00    
          NOARP  MTU:1480  Metric:1  
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0  
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0   
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)

tunl0:  Link encap:IPIP Tunnel  HWaddr   
          NOARP  MTU:1480  Metric:1  
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0  
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0   
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)  

So, the modprobe command is not able to load the kernel module.
How can we load a kernel module using modprobe or insmod to initialize a dummy interface driver?
Can we create multiple dummy interfaces on a single loaded module?

GAD3R
  • 63,407
  • 31
  • 131
  • 192
Kushal
  • 327
  • 1
  • 4
  • 9
  • When you talked about Ethernet virtual interface.You didnt need to load any dummy module. You can create it using ifconfig command like eth0:1, eth0:2, etc. – supriady Jan 06 '17 at 06:32
  • You can set different IP address, subnet and gateway on Ethernet virtual interface using ifconfig command. Just add it on rc.local and loaded on the boot.You didnt need to create any ethernet virtual interface config files. – supriady Jan 06 '17 at 06:36
  • 1
    @supriady I am not asking about Virtual interfaces. I know we can assign virtual ip's to an interface using ifconfig like eth0:1 & so on but here the Mac h/w address will be same for each virtual interface created. My question is how to create multiple dummy interfaces like dummy0 shown above having a different H/w Mac address than the real interfaces. – Kushal Jan 06 '17 at 06:52
  • Just to be sure, you do realize that these interfaces will not be visible from outside the machine, right? – Julie Pelletier Jan 06 '17 at 07:18
  • Please add to the question the FULL output of the `modprobe` error and the output of `uname -r` – Rui F Ribeiro Jan 06 '17 at 10:34
  • Have you had at least a kernel update without a reboot? `modprobe` might be trying to use a module directory that is no longer installed – Rui F Ribeiro Jan 06 '17 at 10:40
  • @JuliePelletier I have 4 servers with 4 dummy interfaces, and the dummy IP addresses are exposed via routing (at least). Over time I witnessed some other peculiarities, but without further testing, I wont digress in their properties. – Rui F Ribeiro Jan 06 '17 at 11:02
  • @RuiFRibeiro: Of course they can be routed but my point was related to the fact that OP wanted different MAC addresses for their interfaces but these will only matter locally and probably only useful in VMs (although I don't even see the benefit there). – Julie Pelletier Jan 06 '17 at 15:01
  • @JuliePelletier About the benefits, being able to setup Anycast DNS/VIPs is one of them. – Rui F Ribeiro Jan 06 '17 at 15:02

2 Answers2

14

The usual way to add several dummy interfaces is to use iproute2:

# ip link add dummy0 type dummy
# ip link add dummy1 type dummy
# ip link list
...
5: dummy0: <BROADCAST,NOARP> mtu 1500 qdisc noop state DOWN mode DEFAULT group default qlen 1000
    link/ether 22:4e:84:26:c5:98 brd ff:ff:ff:ff:ff:ff
6: dummy1: <BROADCAST,NOARP> mtu 1500 qdisc noop state DOWN mode DEFAULT group default qlen 1000
    link/ether 9e:3e:48:b5:d5:1d brd ff:ff:ff:ff:ff:ff

But the error message FATAL: Module dummy not found indicates that you may have a kernel where the dummy interface module is not enabled, so make sure to check your kernel configuration, and recompile the kernel if necessary.

dirkt
  • 31,679
  • 3
  • 40
  • 73
  • "the error message FATAL: Module dummy not found indicates that you may have a kernel where the dummy interface module is not enabled" => No, it may mean the dummy driver was not built as a module, but directly added to the kernel instead. Apparently a `dummy0` interface exists on the OP's machine. Other than that, your answer is OK. – xhienne Jan 06 '17 at 09:41
  • 1
    @xhienne depends on your version of modprobe, but recent versions from `kmod`, at least, will know about builtins. Try it. E.g. `modprobe unix` and `modprobe -r unix`. – sourcejedi Mar 22 '19 at 21:05
10

To create dummy interfaces upon boot, I advise adding to /etc/modules

dummy

Beware the module dummyonly allows two dummy interfaces by default before kernel 4.4.x( correct version to be verified).

If you need more, you have also to create either a /etc/modprobe.d/local or /etc/modprobe.d/dummy.conf defining the parameter numdummies with the number of dummy interfaces you desire:

options dummy numdummies=4 

As per @Feuermurmel comments, in newer kernels, you add more dummy interfaces, besides the two one created by default, using the command:

sudo ip link add dummyX type dummy
Rui F Ribeiro
  • 55,929
  • 26
  • 146
  • 227
  • At least with the kernel 4.4.0, additional dummy interfaces can be added with `ip link add dumdum type dummy`. – Feuermurmel Mar 20 '17 at 16:00
  • @Feuermurmel Do you have an ideia if it works to add more than 2? – Rui F Ribeiro Mar 20 '17 at 16:14
  • It definitely does. Test for yourself: `for i in {0..100}; do ip link add blubb-$i type dummy; done` – Feuermurmel Mar 20 '17 at 16:17
  • @Feuermurmel Good news, thanks for the tip. You might want to add it as an additional answer. IMO both are pertinent as there are still lot of iOT devices that are stuck in lower kernel versions. – Rui F Ribeiro Mar 20 '17 at 16:20
  • Out of curiosity: Are these devices, once created, persistent across reboots, or do you have to recreate them after each system start? – Robidu Sep 15 '19 at 00:10
  • @Robidu In dummy.conf they are created automagically upon boot, the ones using the `ip command`, the ip command has to be run or scripted. – Rui F Ribeiro Sep 15 '19 at 01:25