Linux, Embedded Systems, Networking, and DevOps Engineering

Virtual Interfaces in Linux

Table of contents

  1. Revision history
  2. Meaning and how to create various types of virtual interfaces on Linux

Revision history

  Revision Date Remark
  0.1 Feb-02-2023 Add Document
  0.2 Feb-02-2023 Add description of Docker using VETH
  0.3 Feb-04-2023 Add tunnel interface
  0.34 Feb-06-2023 Add ipvlan interface

Meaning and how to create various types of virtual interfaces on Linux

Type How to create Meaning
Bridge
Create interface
brctl addbr br0
ip link add name br0 type bridge
Delete interface
brctl delbr br0
ip link delete br0
Add interface to bridge
brctl addif br0 eth1
ip link set eth1 master br0
Remove interface from bridge
brctl delif br0 eth1
ip link set eth1 nomaster
Software bridge, L2 interface
802.1Q VLAN
Check if kernel is enabled
modinfo 8021q
Create interface
vconfig add eth1 8
ip link add link eth1 name eth1.8 type vlan id 8
802.1Q VLAN interface, L2 interface
MACVLAN
Create interface
ip link add macvlan1@eth0 link eth0 type macvlan mode bridge
MACVLAN interface, Interface needs to support promiscuity mode, L2 interface
IPVLAN
Create interface
ip link add ipvlan1@eth0 link eth0 type ipvlan mode l2
Similar to macvlan, ipvlan supports L2 and L3. In L2 mode, interfaces have the same MAC but different IPs
TUN
Create interface
ip tuntap add name tun0 mode tun
- Only accepts L3 packets
- Cannot be added to bridge
- Cannot broadcast packets
- Commonly used for VPN connections
TAP
Create interface
ip tuntap add name tap0 mode tap
- Operates at L2
- Can be added to bridge
- Can broadcast packets
- Commonly used in virtual machine systems
VETH
Create interface
ip link add veth1 type veth peer name veth2
- Creates a pair of virtual interfaces with link connection to each other
- Docker bridge mode uses this config, veth0 is bound to container,
veth1 is added as member of bridge docker0
TUNNEL
Create interface
ip tunnel add tunnel0 mode sit ttl $TUNTTL remote $ISPBRIP local $WAN4IP
Delete interface
ip tunnel del tunnel0
- Create tunnel interface, modes: ipip | gre | sit | isatap | vti | ip6ip6 | ipip6 | ip6gre | vti6 | any