How to add virtual network interface in Debian based distro

Debian Logo

As a Linux user, and a Debian lover, I tends to use the OS using commands a lot.
Why not use Ubuntu? I use Ubuntu on my desktops, and on servers, I prefer Debian or CentOS.
Anyway, in Linux, not everything you can do it quickly and in a simple way using the GUI.
CLI is always the best way to do most of the things you want.
This post, I will teach you how to create a virtual network interface in your Debian based Linux, which means, Ubuntu users can use this as well.

Debian based Linux store the network interface config in the file /etc/network/interfaces.
No, it is not in /etc/sysconfig/network-scripts/. Only Red Hat family distro use this.

By default, you might see the entries such as below in your /etc/network/interfaces.

auto lo
iface lo inet loopback

auto eth0
iface eth0 inet static
address 192.168.1.5
netmask 255.255.255.0
gateway 192.168.1.254

Just edit it using nano or vi, or if you have a desktop GUI, you can use your preferred text editor instead.
Things that you need to add, is as below for an additional virtual network interface.

auto eth0:1
iface eth0:1 inet static
address 192.168.1.6
netmask 255.255.255.0
broadcast 255.255.255.0
gateway 192.168.1.254

So the file, will become as below:

auto lo
iface lo inet loopback

auto eth0
iface eth0 inet static
address 192.168.1.5
netmask 255.255.255.0
gateway 192.168.1.254

auto eth0:1
iface eth0:1 inet static
address 192.168.1.6
netmask 255.255.255.0
broadcast 255.255.255.0
gateway 192.168.1.254

After you have done this, just restart the network using the command:

/etc/init.d/networking restart

Or if your OS is using NetworkManager, use the command below:

/etc/init.d/NetworkManager restart

If you prefer to use the “service” command, just go ahead with:

service networking restart

or for NetworkManager:

service NetworkManager restart

No reboot is required.

CC BY-NC-ND 4.0 How to add virtual network interface in Debian based distro by Garfield is licensed under a Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International License.