TransWikia.com

Virtual ethernet interface on Raspbian buster

Raspberry Pi Asked by Ste on January 9, 2021

I need a virtual ethernet interface on a Raspbian Buster.

I read that I have to use /etc/dhcpcd.conf to set the network configuration but I don’t understand where to configure the virtual ethernet.
I think /etc/dhcpcd.conf but many answers on the internet suggest to modify /etc/network/interface.

How I can configure my second virtual ethernet?

One Answer

It's very vague to tell something about virtual interfaces if we do not have any information about the context for what they are needed. Raspbian comes with iproute2 to manage interfaces with its command ip.

In general the iproute2 system does not need the idea of a virtual interface. Instead, you can simply add additional IP addresses to an existing interface, for example:

rpi ~$ sudo ip addr add 192.168.50.2/32 dev eth0
rpi ~$ sudo ip addr add 192.168.50.3/32 dev eth0

rpi ~$ ip -4 addr show dev eth0
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
    inet 192.168.50.137/24 brd 192.168.50.255 scope global noprefixroute eth0
       valid_lft forever preferred_lft forever
    inet 192.168.50.2/32 scope global eth0
       valid_lft forever preferred_lft forever
    inet 192.168.50.3/32 scope global eth0
       valid_lft forever preferred_lft forever

Note that the deprecated ifconfig -a command will not show these additional IP addresses. If you really want to use old style ifconfig then you have to give the virtual interfaces a label like:

rpi ~$ sudo ip addr add 192.168.50.2/32 dev eth0 label eth0:2
rpi ~$ sudo ip addr add 192.168.50.3/32 dev eth0 label eth0:3

I do not use dhcpcd so I will only qoute Re: Configuring virtual eth interfaces using dhcpcd.conf:

Aliases are nothing more than an additional IP address. Since if uptown was designed around “interface” blocks the concept of aliases was invented to support adding an extra address. Nowadays you can simply add an additional “ip address add ...” in the exit-hook dhcpcd script. /etc/network/interfaces is not around for much longer in Debian/Raspbian, start looking for other ways to achieve what you want to do.


Reference:
add an IP address to an interface

Answered by Ingo on January 9, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP