Configuring a virtual network interface on Linux isn’t something most people need to do very often, but it can come in handy sometimes. The system will recognize a virtual interface as a real, physical interface.
In this respect, it works sort of like a virtual machine – that is, it emulates the necessary hardware components to seem like it’s physically connected to the machine.
In this tutorial, you’ll learn how to create a virtual network interface on Linux. Follow along with the step by step instructions below to create one or more of these interfaces on your own system.
In this tutorial you will learn:
- How to configure virtual network interfaces on Linux
|Category||Requirements, Conventions or Software Version Used|
|System||Any Linux distro|
|Other||Privileged access to your Linux system as root or via the
|Conventions||# – requires given linux commands to be executed with root privileges either directly as a root user or by use of
$ – requires given linux commands to be executed as a regular non-privileged user
Configure virtual network interfaces on Linux
The methods for creating a virtual network interface have changed a bit through the years. There is more than one way to do this, but we will be using the “dummy” kernel module to set up our virtual interface in these steps.
- Start off by enabling the
dummykernel module with the following command.
$ sudo modprobe dummy
- Now that the module has been loaded, we can create a new virtual interface. Feel free to name yours however you want, but we will name ours
eth0in this example.
$ sudo ip link add eth0 type dummy
You will be able to verify that the link was added by executing the following command afterwards:
$ ip link show eth0
- We have our virtual interface, but it’t not much use to us without an IP address or MAC address. Let’s give the interface a MAC address with the following command. Feel free to substitute any address you want to use, as ours is just a randomly generated one.
$ sudo ifconfig eth0 hw ether C8:D7:4A:4E:47:50
Note that if the ifconfig command is not available, you’ll need to install package
- We can now add an alias to the interface and configure an it with an IP address.
$ sudo ip addr add 192.168.1.100/24 brd + dev eth0 label eth0:0
- Don’t forget to put the interface up, or it probably won’t be very useful.
$ sudo ip link set dev eth0 up
- You should now be able to use your virtual network interface for whatever you want. You can see the full configuration by viewing the output of the
$ ip a [...] 3: eth0: <BROADCAST,NOARP,UP,LOWER_UP> mtu 1500 qdisc noqueue state UNKNOWN group default qlen 1000 link/ether c8:d7:4a:4e:47:50 brd ff:ff:ff:ff:ff:ff inet 192.168.1.100/24 brd 192.168.1.255 scope global eth0:0 valid_lft forever preferred_lft forever
- If the virtual network interface has finished serving its purpose, you can revert all your changes with the following commands.
$ sudo ip addr del 192.168.1.100/24 brd + dev eth0 label eth0:0 $ sudo ip link delete eth0 type dummy $ sudo rmmod dummy
In this tutorial, we learned how to add a virtual network interface to a Linux system, by using the dummy kernel module. This is a useful practice in multiple scenarios. For example, if you have an application that must be tied to a network interface and don’t wish to use your physical adapter.