Why does "ip link add" not work in rc.local?

I used the following command to add a dummy interface:

sudo ip link add name mydummy type dummy

It works great. But when I put this in rc.local before the exit 0 command, it does not work. After login to the system, ifconfig does not show the mydummy interface.


Adding a dummy interface needs a dummy kernel module that is not loaded when rc.local is executed. There are many methods to run a program at boot time, but the best way is using a service file.

I suppose that your Ubuntu box supports upstart technology. I name this service dummyadder.

  1. Create the file /etc/init/dummyadder.conf and add the following lines:

    start on runlevel [2345]
    
    script
    ip link add name mydummy type dummy
    ip link set dev mydummy up
    end script
    
    pre-stop exec ip link del mydummy
    
  2. Reboot your Linux to see the result.