Create VLAN interface with ip command

In this article, we are going to show you how to create a VLAN interface on a Linux system using the “ip” command.

To begin with, it is important to mention that VLAN (Virtual Local Area Network) is a networking technique that allows you to split a physical LAN into several logical networks. This means that you can create several separate networks within a single physical connection, allowing you to have better control over security and bandwidth.

To create a VLAN interface in Linux, you will first need a physical network card. You can check which network cards you have in your system by using the “ip link show” command.

$ ip link show
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP mode DEFAULT group default qlen 1000
link/ether 00:0c:29:d4:5e:f5 brd ff:ff:ff:ff:ff:ff

In this example, our physical network card is “eth0”. Next, we will use the “ip link add link” command to create a VLAN interface. The format of the command is as follows:

$ ip link add link <nombre_de_interfaz_física> name <nombre_de_interfaz_VLAN> type vlan id <ID_de_VLAN>

For example, in the next step, to create a VLAN interface on a Linux system we use the command “ip link add” followed by the necessary parameters. Here is an example of how to use this command to create a VLAN interface with ID 100 and linked to interface eth0:

ip link add link eth0 name eth0.100 type vlan id 100

In this example, we are using the “link” parameter to specify the base interface (eth0) to which the new VLAN interface will be linked. We are also using the “name” parameter to specify the name of the new VLAN interface (eth0.100) and the “type vlan” parameter to indicate that we are creating a VLAN interface. Finally, we are using the “id” parameter to specify the VLAN ID (100).

Once you have executed this command, you can verify if the new VLAN interface has been created correctly by using the “ip link show” command again. You should see a new entry for interface eth0.100 in the output.

The next step would be to configure the IP address of the newly created VLAN interface, this can be done with the command “ip addr add” followed by the necessary parameters. An example of how to assign an IP address to the VLAN interface eth0.100:

ip addr add 192.168.100.1/24 dev eth0.100

In this example, we are using the “add” parameter to add an IP address to the VLAN interface and the “dev” parameter to specify the interface to which the IP address will be added. We are also specifying the IP address and subnet mask.

Continuing with the article, once you have the network interface identifiers, you can use the command “ip link add link [interface_name] name [vlan_name] type vlan id [vlan_id]” to create a new VLAN interface. For example, if we want to create a VLAN interface with the name “vlan100” on interface “eth0” with a VLAN ID of 100, the command would be:

ip link add link eth0 name vlan100 type vlan id 100

Once the VLAN interface is created, we can use the command “ip addr add [ip_address]/[subnet_mask] dev [vlan_name]” to assign an IP address to the VLAN interface. For example, if we want to assign the IP address 192.168.100.1/24 to the VLAN interface “vlan100”, the command would be:

ip addr add 192.168.100.1/24 dev vlan100

After assigning an IP address to the VLAN interface, we can use the command “ip link set [vlan_name] up” to activate the VLAN interface. For example, to enable the VLAN interface “vlan100”, the command would be:

ip link set vlan100 up

Finally, we can use the “ip link show” command to verify that the VLAN interface has been created correctly and has an assigned IP address. The output should show the VLAN interface “vlan100” with its assigned IP address and its active status.

It is important to mention that these commands are only applicable on Linux based systems, it is also important to clarify that these commands must be executed with administrator permissions (sudo or as root).

In summary, using the IP tool commands, we can create a VLAN interface on a Linux system, assign it an IP address and activate it. It is a simple process, but it is important to note the configuration details and verify the correct creation of the VLAN interface.

Leave a Reply