[solved] How to add new dummy persistent network device

Linux Kernel, Network, and Services configuration.
Post Reply
Message
Author
franke
Posts: 21
Joined: 2023-02-19 10:30

[solved] How to add new dummy persistent network device

#1 Post by franke »

Hello, I'm currently executing

Code: Select all

ip l add veth type dummy
ip l dev veth address d4:d4:d4:d4:d4:d4
every time I start the machine.

How can I configure Debian in a way that this dummy network device with fixed mac address is persisted between reboots?

I wanted to avoid to "pollute" my crontab, but I did not find out what is _the_ way one should do it.
The syntax of /etc/network/interfaces is a bit obscure to me, and I did not manage to add the device there (where IMHO it makes the most sense).
Last edited by franke on 2024-10-17 05:42, edited 1 time in total.

arzgi
Posts: 1407
Joined: 2008-02-21 17:03
Location: Finland
Been thanked: 56 times

Re: How to add new dummy persistent network device

#2 Post by arzgi »

You can use /etc/network/interfaces or leave it to systemd, You can google a lot of info of both, Debian wiki is a good starting point, Arch linux has also valid pages of the subjects.

My /etc/systemd/network/25-wireless.network for example:

Code: Select all

rto@dell:/etc/systemd/network$ cat 25-wireless.network 
#/etc/systemd/network/25-wireless.network

[Match]
MACAddress=xx.xx.xx.xx #/(of course, put a valid hex-code here)

[Link]
Name=wlan0

[Network]
DHCP=yes
IgnoreCarrierLoss=10s

[DHCPv4]
RouteMetric=10


Aki
Global Moderator
Global Moderator
Posts: 3949
Joined: 2014-07-20 18:12
Location: Europe
Has thanked: 109 times
Been thanked: 518 times

Re: How to add new dummy persistent network device

#3 Post by Aki »

Hello,
franke wrote: 2024-10-05 04:42 Hello, I'm currently executing

Code: Select all

ip l add veth type dummy
ip l dev veth address d4:d4:d4:d4:d4:d4
every time I start the machine.
How can I configure Debian in a way that this dummy network device with fixed mac address is persisted between reboots?
[..]
Can you please give some context about the overall configuration using this dummy interface ?
⢀⣴⠾⠻⢶⣦⠀
⣾⠁⢠⠒⠀⣿⡁ Debian - The universal operating system
⢿⡄⠘⠷⠚⠋⠀ https://www.debian.org
⠈⠳⣄⠀

franke
Posts: 21
Joined: 2023-02-19 10:30

Re: How to add new dummy persistent network device

#4 Post by franke »

@Aki, do you mean, what I am going to do with this dummy interface?

It just needs to exist, I have a program that verifies all mac addresses, and depending which specific one it finds, it loads internally a configuration file.

This device is not used for any type of communication, you can think of it like an unplugged ethernet port.

The two commands in my first post are sufficient to reach that state, but needs to be repeated at every reboot.

@arzgi

Yeah, I found different methods, but most where real interfaces, unfortunately I did not write down what I tried without success.
Most guides deal with real hardware, so similarly to your they match a mac address and configure something, while I mean more or less the opposite; configure nothing, but define a device with a given mac address.

arzgi
Posts: 1407
Joined: 2008-02-21 17:03
Location: Finland
Been thanked: 56 times

Re: How to add new dummy persistent network device

#5 Post by arzgi »

Would not

Code: Select all

ip link set [$IF] up/down
work?

Aki
Global Moderator
Global Moderator
Posts: 3949
Joined: 2014-07-20 18:12
Location: Europe
Has thanked: 109 times
Been thanked: 518 times

Re: How to add new dummy persistent network device

#6 Post by Aki »

Hello,

You may install the ifupdown-ng package [1].

It is a "one to one" replacement for the ifupdown package, which is usually installed by default.

ifupdown-ng allows you to use the lynk-type keyword [2]:
[..]
link-type link-type

Denotes the link-type of the interface. When set to dummy, the interface is created
as a virtual dummy interfaces. When set to veth the interface is created as virtual veth
interface (pair).
[..]
in its /etc/network/interfaces configuration file like this:

Code: Select all

auto veth
iface veth inet static
        link-type dummy
        hwaddress d4:d4:d4:d4:d4:d4
I tested it according to your first post, and it works.

I've never used ifupdown-ng before, so I don't know generally speaking how it behaves compared to ifupdown, so it's up to you.

Another different solution is to create a custom systemd service that runs a script containing your two ip commands after the networking service has finished.

Hope this helps.

---
[1] ifupdown-ng - Network Interface Management tool similar to ifupdown{,2}
[2] interfaces-ng(5) - File Formats Manual
⢀⣴⠾⠻⢶⣦⠀
⣾⠁⢠⠒⠀⣿⡁ Debian - The universal operating system
⢿⡄⠘⠷⠚⠋⠀ https://www.debian.org
⠈⠳⣄⠀

franke
Posts: 21
Joined: 2023-02-19 10:30

Re: How to add new dummy persistent network device

#7 Post by franke »

Thank you both for assisting me, unfortunately I did not see your replies.


@Aki

With your proposed changes, I see following message during startup

> [FAILED] failed to start networking.service - Raise network interfaces.
> See systemctl status networking.service for details

And after executing systemctl status networking.service, I see following errors:

> failed(Result: exit-code) since <today datae>

and

> Process: 747 ExecStart=/urs/sbin/ifup -a --read-environment (code=exited, status=1/FAILURE)

and with "ip a", I do not see the dummy network interface :(

@arzgi

I'm not sure what your command does, in particular, how does it help to define a dummy network interface with a fixed mac address? Or do I need to execute it after some other changes?

arzgi
Posts: 1407
Joined: 2008-02-21 17:03
Location: Finland
Been thanked: 56 times

Re: How to add new dummy persistent network device

#8 Post by arzgi »

MAC address is usually given to any network device in the factory that made it, There are methods to spoof the ip address, but that's I think it is not what you need.

You can make any ip link up or down with the command example I gave.

Code: Select all

arto@dell:~$ ip a
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
2: eno1: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc fq_codel state DOWN group default qlen 1000
    link/ether 20:47:47:0b:98:a2 brd ff:ff:ff:ff:ff:ff
    altname enp0s25
10: wlan0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
    link/ether 14:eb:b6:85:6a:26 brd ff:ff:ff:ff:ff:ff
    inet 192.168.1.113/24 brd 192.168.1.255 scope global dynamic wlan0
       valid_lft 43178sec preferred_lft 43178sec
arto@dell:~$ sudo ip link set wlan0 down
arto@dell:~$ ping google.com
ping: google.com: Tilapäinen virhe nimenselvityksessä
arto@dell:~$ sudo ip link set wlan0 up
arto@dell:~$ sudo dhclient -r
Killed old client process
arto@dell:~$ sudo dhclient 
arto@dell:~$ ping google.com
PING google.com (216.58.209.206) 56(84) bytes of data.
64 bytes from bud02s22-in-f14.1e100.net (216.58.209.206): icmp_seq=1 ttl=60 time=2.56 ms
64 bytes from bud02s22-in-f14.1e100.net (216.58.209.206): icmp_seq=2 ttl=60 time=2.19 ms
^X^C
--- google.com ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1001ms
rtt min/avg/max/mdev = 2.193/2.374/2.555/0.181 ms
arto@dell:~$ 

Aki
Global Moderator
Global Moderator
Posts: 3949
Joined: 2014-07-20 18:12
Location: Europe
Has thanked: 109 times
Been thanked: 518 times

Re: How to add new dummy persistent network device

#9 Post by Aki »

Hello,
franke wrote: 2024-10-11 07:18 With your proposed changes, I see following message during startup

Code: Select all

[FAILED] failed to start networking.service - Raise network interfaces.
See systemctl status networking.service for details
And after executing systemctl status networking.service, I see following errors:

Code: Select all

failed(Result: exit-code) since <today datae>
and

Code: Select all

Process: 747 ExecStart=/urs/sbin/ifup -a --read-environment (code=exited, status=1/FAILURE)
and with "ip a", I do not see the dummy network interface :(
Did you check the installed ifupdown version ? You can check with:

Code: Select all

apt --installed list ifupdown*
Are you sure there are no errors in your /etc/network/interfaces ?

Can you share your /etc/network/interfaces ?

Hope this helps.
⢀⣴⠾⠻⢶⣦⠀
⣾⠁⢠⠒⠀⣿⡁ Debian - The universal operating system
⢿⡄⠘⠷⠚⠋⠀ https://www.debian.org
⠈⠳⣄⠀

franke
Posts: 21
Joined: 2023-02-19 10:30

Re: How to add new dummy persistent network device

#10 Post by franke »

@arzgi
But then what you are proposing does not help me.
* I do not need to be able to make ip link up or down (AFAIK), it would even be bettere if there is no traffic on such interface; I just need it to be there
* I need to be able to specify a mac address

@Aki

Code: Select all

> cat /etc/network/interfaces
auto lo
iface lo inet loopback

auto veth
iface veth inet static
     link-type dummy
     hwaddress d4:d4:d4:d4:d4:d4
     
> apt --installed list 'ifupdown*'
ifupdown-ng/testing,now 0.12.1-6 amd64 [installed]
ifupdown/testing,now 0.8.44 amd64 [installed]
I did not try it last time, I'v eexecuted the command reported from systemctl

Code: Select all

> sudo ifup -a
ifup: missing required variable: address
ifup: missing required configuration variable for interface veth/inet
ifup: failed to bring up veth
Thus address seems to be missing, but from the documentation, as far as I understood, it's an ip address, not a mac address (which is hwaddress), and changing from hwaddress to address seems to confirm it (error message tells more or less that the format is wrong)

Aki
Global Moderator
Global Moderator
Posts: 3949
Joined: 2014-07-20 18:12
Location: Europe
Has thanked: 109 times
Been thanked: 518 times

Re: How to add new dummy persistent network device

#11 Post by Aki »

Hello,
franke wrote: 2024-10-14 06:52

Code: Select all

> apt --installed list 'ifupdown*'
ifupdown-ng/testing,now 0.12.1-6 amd64 [installed]
ifupdown/testing,now 0.8.44 amd64 [installed]
From your log quoted above:
  • it turns out that you are using Debian testing (it seems to me that you did not report it before)
  • I suspect you have done something strange as there are two packages installed which should *not* be installed together (ifupdown and ifupdown-ng); this is the list of installed packages matching the pattern ifupdown* in my Debian testing (after installing ifupdown-ng):

    Code: Select all

    # apt --installed list "ifupdown*"
    ifupdown-ng-compat/testing,now 0.12.1-6 all [installato, automatico]
    ifupdown-ng/testing,now 0.12.1-6 amd64 [installato]
    
    # ip address show dev veth
    4: veth: <BROADCAST,NOARP,UP,LOWER_UP> mtu 1500 qdisc noqueue state UNKNOWN group default qlen 1000
        link/ether d4:d4:d4:d4:d4:d4 brd ff:ff:ff:ff:ff:ff
        inet6 fe80::d6d4:d4ff:fed4:d4d4/64 scope link proto kernel_ll 
           valid_lft forever preferred_lft forever
    
Furthermore, the package named ifupdown-ng-compat is missing in your installation.

Therefore, you should install the package named ifupdown-ng-compat and uninstall the package named ifupdown; you can simulate it with the following commands:

Code: Select all

# apt -s install ifupdown-ng-compat
⢀⣴⠾⠻⢶⣦⠀
⣾⠁⢠⠒⠀⣿⡁ Debian - The universal operating system
⢿⡄⠘⠷⠚⠋⠀ https://www.debian.org
⠈⠳⣄⠀

franke
Posts: 21
Joined: 2023-02-19 10:30

Re: How to add new dummy persistent network device

#12 Post by franke »

@Aki

That was it.

I'm not sure how I ended with the wrong package, after installing ifupdown-ng-compat, it worked as described!

Aki
Global Moderator
Global Moderator
Posts: 3949
Joined: 2014-07-20 18:12
Location: Europe
Has thanked: 109 times
Been thanked: 518 times

Re: How to add new dummy persistent network device

#13 Post by Aki »

Hello,
franke wrote: 2024-10-15 18:02 @Aki
That was it.
I'm glad you sorted it out. Please, mark the discussion as "solved" manually adding the text tag "[Solved]" at the beginning of the subject of the first message.
franke wrote: 2024-10-15 18:02 I'm not sure how I ended with the wrong package, after installing ifupdown-ng-compat, it worked as described!
The dependencies of the ifupdown-ng package changed from Debian Stable (alias Bookworm) and Debian Testing:
  • in Debian Stable (alias Bookworm) the ifupdown-ng package "conflicts" with the ifupdown package (so, apt uninstall the ifupdown package before installing ifupdown-ng):

    Code: Select all

    $ apt-cache depends ifupdown-ng/stable
    ifupdown-ng
      Depends: adduser
      Depends: iproute2
      Depends: lsb-base
        sysvinit-utils
      Depends: libbsd0
      Depends: libc6
      Conflicts: ifupdown
        ifupdown2
        netscript-2.4
      Conflicts: ifupdown2
     |Recommends: isc-dhcp-client
      Recommends: <dhcp-client>
        dhcpcd-base
        isc-dhcp-client
      Suggests: ppp
      Suggests: rdnssd
    
  • in Debian Testing the ifupdown-ng package does not conflicts with the ifupdown package (the ifupdown is not uninstalled before installing ifupdown-ng) but it recommends the ifupdown-ng-compat package:

    Code: Select all

    $ apt-cache depends ifupdown-ng/testing
    ifupdown-ng
      Depends: adduser
      Depends: iproute2
      Depends: libbsd0
      Depends: libc6
      Recommends: ifupdown-ng-compat
     |Recommends: isc-dhcp-client
      Recommends: <dhcp-client>
        dhcpcanon
        isc-dhcp-client
        dhcpcd-base
      Recommends: rdnssd
      Suggests: ppp
    
    • the "APT::Install-Recommends" should be enabled in Debian Testing, therefore, the ifupdown-ng-compat should be installed as a dependency of ifupdown-ng:

      Code: Select all

      $ apt-config dump | grep Recommends
      APT::Install-Recommends "1";
      
    • the ifupdown-ng-compat package "conflicts" with the ifupdown package (so, apt uninstall the ifupdown package before installing ifupdown-ng-compat):

      Code: Select all

      $ apt-cache depends ifupdown-ng-compat/testing
      ifupdown-ng-compat
        Conflicts: ifupdown
          netscript-2.4
        Conflicts: ifupdown-ng
        Conflicts: <ifupdown2>
        Replaces: ifupdown-ng
      
What is the program you use to install Debian packages ?

--
[1] Debian Policy - Conflicting binary packages - Conflicts
⢀⣴⠾⠻⢶⣦⠀
⣾⠁⢠⠒⠀⣿⡁ Debian - The universal operating system
⢿⡄⠘⠷⠚⠋⠀ https://www.debian.org
⠈⠳⣄⠀

franke
Posts: 21
Joined: 2023-02-19 10:30

Re: [solved] How to add new dummy persistent network device

#14 Post by franke »

I used following command

Code: Select all

sudo aptitude install ifupdown-ng
I've executed

Code: Select all

apt-cache depends ifupdown-ng/testing
apt-config dump | grep Recommends
apt-cache depends ifupdown-ng-compat/testing
and got exactly the same output you've shown

User avatar
fabien
Forum Helper
Forum Helper
Posts: 1155
Joined: 2019-12-03 12:51
Location: Anarres (Toulouse, France actually)
Has thanked: 101 times
Been thanked: 264 times

Re: [solved] How to add new dummy persistent network device

#15 Post by fabien »

Hello @franke,
here is what I get on testing if I simulate the installation of ifupdown-ng:

Code: Select all

#> apt -sV install ifupdown-ng

Installing:                     
   ifupdown-ng (0.12.1-6)

Installing dependencies:
   ifupdown-ng-compat (0.12.1-6)
   resolvconf (1.92)

Recommended packages:
   rdnssd (1.0.7-1)

REMOVING:
   ifupdown (0.8.44)

Summary:
  Upgrading: 0, Installing: 3, Removing: 1, Not Upgrading: 0
Remv ifupdown [0.8.44]
Inst ifupdown-ng (0.12.1-6 Debian:testing [amd64])
Inst ifupdown-ng-compat (0.12.1-6 Debian:testing [all])
Inst resolvconf (1.92 Debian:testing [all])
Conf ifupdown-ng (0.12.1-6 Debian:testing [amd64])
Conf ifupdown-ng-compat (0.12.1-6 Debian:testing [all])
Conf resolvconf (1.92 Debian:testing [all])
Can you please find the sequence in your apt logs and copy it here?

Code: Select all

$> less /var/log/apt/history.log
$> zless /var/log/apt/history.log.1.gz
ImageShare your Debian SCRIPTS
There will be neither barrier nor walls, neither official nor guard, there will be no more desert and the entire world will become a garden. — Anacharsis Cloots

franke
Posts: 21
Joined: 2023-02-19 10:30

Re: [solved] How to add new dummy persistent network device

#16 Post by franke »

/var/log/apt/history.log.1.gz does not exist


From "less /var/log/apt/history.log"

Code: Select all

Start-Date: 2024-10-11  09:01:43
Requested-By: debian (1000)
Install: ifupdown-ng:amd64 (0.12.1-6)
End-Date: 2024-10-11  09:01:48

Start-Date: 2024-10-15  08:19:53
Commandline: apt install ifupdown-ng-compat
Requested-By: debian (1000)
Install: ifupdown-ng-compat:amd64 (0.12.1-6)
Remove: ifupdown:amd64 (0.8.44)
End-Date: 2024-10-15  08:19:59

and there is an older entry

Code: Select all

Start-Date: 2024-10-04  11:46:30
Commandline: apt dist-upgrade
Requested-By: debian (1000)
<lot of packages>.... ifupdown:amd64 (0.8.41, 0.8.44) .... <lot of packages>
Maybe I got an inconsistent state when I changed the repo from bookworm to testing, and did the dist-upgrade.
I did install the Debian OS shortly before, it was a minimal install (no gui, etc etc)

User avatar
fabien
Forum Helper
Forum Helper
Posts: 1155
Joined: 2019-12-03 12:51
Location: Anarres (Toulouse, France actually)
Has thanked: 101 times
Been thanked: 264 times

Re: [solved] How to add new dummy persistent network device

#17 Post by fabien »

franke wrote: 2024-10-17 12:32 Maybe I got an inconsistent state
No, it's simpler than that. I didn't notice you were using aptitude until I looked into why your log didn't have the "Commandline:" field.
aptitude does not behave like apt, you have to pay attention to the recommendations:

Code: Select all

$> aptitude -sv install ifupdown-ng
The following NEW packages will be installed:
  ifupdown-ng 
The following packages are RECOMMENDED but will NOT be installed:
  ifupdown-ng-compat rdnssd 
0 packages upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
Need to get 65.7 kB of archives. After unpacking 183 kB will be used.
Inst ifupdown-ng (0.12.1-6 Debian:testing [amd64])
Conf ifupdown-ng (0.12.1-6 Debian:testing [amd64])

Code: Select all

$> aptitude -sv install ifupdown-ng ifupdown-ng-compat
The following NEW packages will be installed:
  ifupdown-ng ifupdown-ng-compat 
The following packages will be REMOVED:
  ifupdown{a} 
The following packages are RECOMMENDED but will NOT be installed:
  rdnssd 
0 packages upgraded, 2 newly installed, 1 to remove and 0 not upgraded.
Need to get 70.9 kB of archives. After unpacking 13.3 kB will be used.

Note: Using 'Simulate' mode.
Do you want to continue? [Y/n/?] 
Remv ifupdown [0.8.44]
Inst ifupdown-ng (0.12.1-6 Debian:testing [amd64])
Inst ifupdown-ng-compat (0.12.1-6 Debian:testing [all])
Conf ifupdown-ng (0.12.1-6 Debian:testing [amd64])
Conf ifupdown-ng-compat (0.12.1-6 Debian:testing [all])
(in my case, rdnssd is not installed because it conflicts with another installed package for those who are wondering)
ImageShare your Debian SCRIPTS
There will be neither barrier nor walls, neither official nor guard, there will be no more desert and the entire world will become a garden. — Anacharsis Cloots

Post Reply