Bikin macvlan di Arch Linux dan turunannya serta semua distro yang menggunakan netplan

Macvlan allows a single physical interface to have multiple mac and ip addresses using macvlan sub-interfaces. This is different from creating sub-interface on a physical interface using vlan. With vlan sub-interfaces, each sub-interface belongs to a different L2 domain using vlan and all sub-interfaces have same mac address. With macvlan, each sub-interface will get unique mac and ip address and will be exposed directly in underlay network.

Macvlan interface is typically used for virtualization applications and each macvlan interface is connected to a Container or VM. Each container or VM can directly get dhcp address from a common server as the host would do. This would help customers who want Containers to be part of their traditional network with the IP addressing scheme that they already have.

Macvlan has 4 types(Private, VEPA, Bridge, Passthru). Commonly used type is Macvlan bridge which allows for endpoints in a single host to be able to talk to each other without packets leaving the host. For external connectivity, underlay network is used.

Source

Daripada aku jelasin malah salah tangkap, jadi saya kutip saja. Jadi ceritanya aku ada PC terhubung ke router, PC itu punya satu ethernet card. Aku pengen PC itu punya satu lagi ethernet card yang sama-sama terhubung ke router. Dan dapat ip yang satu kelas dari router. Salah satu caranya adalah dengan bikin eth virtual dari eth fisik yang ada.

Cara ini berlaku untuk semua distro yang membawa netplan untuk manajemen network. Contoh distro yang bawa netplan Arch linux, Manjaro, dan Ubuntu teranyar.

Pertama, copy contoh konfigurasi bawaan paket. Di Manjaro sih ada, entah di distro lain

1
sudo cp /etc/netctl/examples/macvlan-dhcp /etc/netctl/macvlan0

Selanjutnya edit hasil copas tadi

1
sudo vim /etc/netctl/macvlan0

Contoh punyaku seperti ini, silakan sesuaikan

1
2
3
4
5
6
7
Description='Virtual LAN with a static MAC on interface eth0 using DHCP'
Interface=macvlan0 # nama interface yang mau kita buat
Connection=macvlan
BindsToInterfaces=enp2s0 # eth fisik yang sudah ada (dapat dari command `ip link`)
Mode="bridge"
MACAddress="12:34:56:78:9a:bc"
IP=dhcp

Terakhir, tinggal start dan enable macvlan0 yang barusan dibuat

1
2
sudo netctl enable macvlan0
sudo netctl start macvlan0

Untuk memastikan, bisa cek pakai command ip

1
ip a

Hasilnya

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: enp2s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
    link/ether f4:4d:30:a7:57:7c brd ff:ff:ff:ff:ff:ff
    inet 192.168.1.28/24 brd 192.168.1.255 scope global noprefixroute enp2s0
       valid_lft forever preferred_lft forever
    inet6 fe80::10bc:5396:d876:5572/64 scope link noprefixroute 
       valid_lft forever preferred_lft forever
24: macvlan0@enp2s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000
    link/ether 12:34:56:78:9a:bc brd ff:ff:ff:ff:ff:ff
    inet 192.168.1.88/24 brd 192.168.1.255 scope global noprefixroute macvlan0
       valid_lft forever preferred_lft forever
    inet6 fe80::1034:56ff:fe78:9abc/64 scope link 
       valid_lft forever preferred_lft forever

Nah sip, selesai. enp2s0 itu perangkat eth fisik di PC dan dapet 192.168.1.28 dari router. macvlan0@enp2s0 itu perangkat eth virtual yang tadi dibuat, dapet ip 192.168.1.88 dari router.

Cool!