88

I have a Dell XPS 13 ultrabook which has a wifi nic, but no physical ethernet nic (wlan0, but no eth0). I need to create a virtual adapter for using Vagrant with NFS, but am finding that the typical ifup eth0:1... fails with ignoring unknown interface eth0:1=eth0:1. I also tried creating a virtual interface against wlan0, but received the same result.

How can I create a virtual interface on this machine with no physical interface?

2
  • First off, make sure that your driver that's being used by wlan0 supports aliasing. That's the other name that virtual interfaces goes by. See how via my A to this Q: unix.stackexchange.com/questions/108396/…. BTW you cannot make an alias against eth0 if you do not have that physical device. – slm Aug 27 '14 at 3:03
  • You can also add additional IPs using the ip command too: xmodulo.com/2013/02/… – slm Aug 27 '14 at 3:20
126

Setting up a dummy interface

If you want to create network interfaces, but lack a physical NIC to back it, you can use the dummy link type. You can read more about them here: iproute2 Wikipedia page.

Creating eth10

To make this interface you'd first need to make sure that you have the dummy kernel module loaded. You can do this like so:

$ sudo lsmod | grep dummy
$ sudo modprobe dummy
$ sudo lsmod | grep dummy
dummy                  12960  0 

With the driver now loaded you can create what ever dummy network interfaces you like:

$ sudo ip link add eth10 type dummy

NOTE: In older versions of ip you'd do the above like this, appears to have changed along the way. Keeping this here for reference purposes, but based on feedback via comments, the above works now.

$ sudo ip link set name eth10 dev dummy0

And confirm it:

$ ip link show eth10
6: eth10: <BROADCAST,NOARP> mtu 1500 qdisc noop state DOWN mode DEFAULT group default 
    link/ether c6:ad:af:42:80:45 brd ff:ff:ff:ff:ff:ff

Changing the MAC

You can then change the MAC address if you like:

$ sudo ifconfig eth10 hw ether 00:22:22:ff:ff:ff
$ ip link show eth10
6: eth10: <BROADCAST,NOARP> mtu 1500 qdisc noop state DOWN mode DEFAULT group default 
    link/ether 00:22:22:ff:ff:ff brd ff:ff:ff:ff:ff:ff

Creating an alias

You can then create aliases on top of eth10.

$ sudo ip addr add 192.168.100.199/24 brd + dev eth10 label eth10:0

And confirm them like so:

$ ifconfig -a eth10
eth10: flags=130<BROADCAST,NOARP>  mtu 1500
        ether 00:22:22:ff:ff:ff  txqueuelen 0  (Ethernet)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

$ ifconfig -a eth10:0
eth10:0: flags=130<BROADCAST,NOARP>  mtu 1500
        inet 192.168.100.199  netmask 255.255.255.0  broadcast 192.168.100.255
        ether 00:22:22:ff:ff:ff  txqueuelen 0  (Ethernet)

Or using ip:

$ ip a | grep -w inet
    inet 127.0.0.1/8 scope host lo
    inet 192.168.1.20/24 brd 192.168.1.255 scope global wlp3s0
    inet 192.168.122.1/24 brd 192.168.122.255 scope global virbr0
    inet 192.168.100.199/24 brd 192.168.100.255 scope global eth10:0

Removing all this?

If you want to unwind all this you can run these commands to do so:

$ sudo ip addr del 192.168.100.199/24 brd + dev eth10 label eth10:0
$ sudo ip link delete eth10 type dummy
$ sudo rmmod dummy

References

4
33

You can create virtual interfaces using the iproute2 toolkit.

ip link add veth0 type veth peer name veth1

This will create 2 interfaces, veth0 and veth1. Think of them as 2 ends of a pipe. Any traffic sent into veth0 will come out veth1 and vice versa.

If you want the traffic to be routed, you can do:

sysctl -w net.ipv4.conf.veth0.forwarding=1

This will tell the kernel to forward traffic coming from veth0 (so use veth1 for the used endpoint).

Another option is to set up a bridge with veth0 and another interface. Then any traffic coming through the virtual interface will get routed out to the network as if your machine were simply acting as a switch.

There are many other things you can do with this traffic (masquerade it, redirect it, DNAT it, etc), but that depends on what you're trying to accomplish.

To tear it down:

ip link del veth0
4
  • Cool stuff, but not quite what I needed in this case (I really just needed a virtual interface so that a VM could mount an NFS share rather than using VBox file shares) – STW Aug 28 '14 at 3:17
  • How to set IP address veth0 in the example ? – MURATSPLAT Jun 7 '18 at 16:23
  • How can you make these persistent? – Daniel May 1 '20 at 16:16
  • @Daniel Short of creating a systemd service to run the commands, I don't know. After some brief googling, I does not seem apparent that NetworkManager will manage veth interface. – phemmer May 1 '20 at 20:18
1

Tested on Ubuntu 18.04:

1. The basics:

# 1. Install the "dummy" Linux kernel module.
sudo modprobe dummy
# 2. Ensure the "dummy" Linux kernel module is installed.
sudo lsmod | grep dummy
# 3. Create a virtual (dummy) interface named `eth10`.
sudo ip link add eth10 type dummy
# 4. Change this new interface's IP address to whatever you like
# (10.0.0.1 in this case).
sudo ip address change dev eth10 10.0.0.1
# 5. See the newly-created device and the IP address you just
# assigned to it.
ip address

That's it!

And if you ever need to delete this device:

# 6. Delete this `eth10` dummy device you created.
sudo ip link delete eth10 type dummy
# 7. Ensure 'eth10' is deleted and doesn't show up here now.
ip address

Done!

2. More details

lsmod shows "the status of modules in the Linux Kernel" (see man lsmod). Try it out! Just type in

lsmod

One of the modules is called dummy. Let's look to see it's there:

$ lsmod | grep dummy
dummy                  16384  0

Yep, it's there. Good. That Linux kernel module must be present for you to be able to run the sudo ip link add eth10 type dummy command above to create the virtual interface using the dummy kernel module. If you don't have it, see @slm's answer.

Before you create a new virtual interface, run this to see what IP addresses and interfaces you already have:

ip address

You can also take a look at this:

ifconfig

After you have created your new virtual interface, you will see it in the output of the ip address command above. Note: ifconfig may not show a virtual, dummy device you create, but ip address will.


Wait, but my coworker ran sudo ip addr change dev eth10 10.0.0.1, in place of sudo ip address change dev eth10 10.0.0.1 (notice addr in place of address). Or, maybe they ran sudo ip a change dev eth10 10.0.0.1 (notice a in place of address). What's up with that!?

Well, this particular command only needs enough of its characters to ensure it knows what you mean. In other words, once you have enough characters in the command for it to know you couldn't possibly mean any other command, it accepts it. Since no other subcommand after ip starts with the letter a, ip a is enough. Therefore, all of the below commands are equivalent:

ip address
ip addres
ip addre
ip addr
ip add
ip ad
ip a

Just be aware of this weird sort of thing when sharing information and looking at the help menus and man pages (shown in my references below). Otherwise, you'll be all sorts of confused, like I was, when no matter how hard you search you can't find the a (as in ip a) or addr (as in ip addr) commands listed anywhere in these page. Just realize both of those are short for address. Ah...now there it is in the help pages!

$ ip help
Usage: ip [ OPTIONS ] OBJECT { COMMAND | help }
       ip [ -force ] -batch filename
where  OBJECT := { link | address | addrlabel | route | rule | neigh | ntable |
                   tunnel | tuntap | maddress | mroute | mrule | monitor | xfrm |
                   netns | l2tp | fou | macsec | tcp_metrics | token | netconf | ila |
                   vrf | sr }
       OPTIONS := { -V[ersion] | -s[tatistics] | -d[etails] | -r[esolve] |
                    -h[uman-readable] | -iec |
                    -f[amily] { inet | inet6 | ipx | dnet | mpls | bridge | link } |
                    -4 | -6 | -I | -D | -B | -0 |
                    -l[oops] { maximum-addr-flush-attempts } | -br[ief] |
                    -o[neline] | -t[imestamp] | -ts[hort] | -b[atch] [filename] |
                    -rc[vbuf] [size] | -n[etns] name | -a[ll] | -c[olor]}

And ip address help (or man ip address), to see the existence of the ip address change command!:

$ ip address help
Usage: ip address {add|change|replace} IFADDR dev IFNAME [ LIFETIME ]
                                                      [ CONFFLAG-LIST ]
       ip address del IFADDR dev IFNAME [mngtmpaddr]
       ip address {save|flush} [ dev IFNAME ] [ scope SCOPE-ID ]
                            [ to PREFIX ] [ FLAG-LIST ] [ label LABEL ] [up]
       ip address [ show [ dev IFNAME ] [ scope SCOPE-ID ] [ master DEVICE ]
                         [ type TYPE ] [ to PREFIX ] [ FLAG-LIST ]
                         [ label LABEL ] [up] [ vrf NAME ] ]
       ip address {showdump|restore}
IFADDR := PREFIX | ADDR peer PREFIX
          [ broadcast ADDR ] [ anycast ADDR ]
          [ label IFNAME ] [ scope SCOPE-ID ]
SCOPE-ID := [ host | link | global | NUMBER ]
FLAG-LIST := [ FLAG-LIST ] FLAG
FLAG  := [ permanent | dynamic | secondary | primary |
           [-]tentative | [-]deprecated | [-]dadfailed | temporary |
           CONFFLAG-LIST ]
CONFFLAG-LIST := [ CONFFLAG-LIST ] CONFFLAG
CONFFLAG  := [ home | nodad | mngtmpaddr | noprefixroute | autojoin ]
LIFETIME := [ valid_lft LFT ] [ preferred_lft LFT ]
LFT := forever | SECONDS
TYPE := { vlan | veth | vcan | vxcan | dummy | ifb | macvlan | macvtap |
          bridge | bond | ipoib | ip6tnl | ipip | sit | vxlan | lowpan |
          gre | gretap | erspan | ip6gre | ip6gretap | ip6erspan | vti |
          nlmon | can | bond_slave | ipvlan | geneve | bridge_slave |
          hsr | macsec

References:

  1. @slm's answer here
  2. ip help
  3. man ip
  4. ip link help
  5. man ip link
  6. ip address help
  7. man ip address

Related:

  1. [my answer] AskUbuntu: How to enable/disable networking (ethernet or wifi) devices, arbitrarily
2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.