Create a dummy interface when you only have 1 NIC available

network
vps

(Rob Bosch) #1

This is a compilation of 2 discussions on these forums:

Thanks to @asl and @jstammi for doing great work on this topic!

  1. add a file for your dummy interface in /etc/sysconfig/network-scripts/ let’s call it ifcfg-dummy0

  2. the kernel module dummy (which is need for dummy devices) is not loaded per default, so we need to add this during server start. Ceate a file dummy.conf inside /etc/modules-load.d. This file includes the word dummy only!
    If you reboot the server now, you will see the result with e.g. ifconfig and you are able to ping yourself:

  3. You will recognize, that your new interafce dummy0 is still missing in WEB-GUI. Thanks to @jstammi I found the solution here: https://community.nethserver.org/t/virtual-network-interface-for-virtual-machines/7728
    I had to patch my /usr/libexec/nethserver/nic-info file. After my next server reboot the NIC is present in the dashboard and I could set up the correct green and red roles under Network. The final result:

The DIFF file reads like:

57,59c57,64
<     if ! [ -e /sys/class/net/${card}/device ]; then
<         continue
<     fi
---
> # NO IDEA, WHY, but with passing the dummy interfaces only, they cannot be
> # configured but deleted only. Letting pass the 2nd virtual nic things
> # can be configured again ... strange, very strange.
> #    if ! [ -e /sys/class/net/${card}/device ]; then
> #        if [ -z "$(ip link show ${card} type dummy)" ] ; then
> #            continue
> #        fi
> #    fi
79,80c84,89
<     driver=`basename $(ls -l /sys/class/net/$card/device/driver | awk '{print$NF}' )`
<     type=`basename $(ls -l /sys/class/net/$card/device/subsystem | awk '{print$NF}' )`
---
>     if [ -r /sys/class/net/$card/device/driver ] ; then
>         driver=`basename $(ls -l /sys/class/net/$card/device/driver | awk '{print$NF}' )`
>     fi
>     if [ -r /sys/class/net/$card/device/subsystem ] ; then
>         type=`basename $(ls -l /sys/class/net/$card/device/subsystem | awk '{print$NF}' )`
>     fi

The full modified /usr/libexec/nethserver/nic-info script reads like:

#!/bin/bash

#
# Copyright (C) 2015 Nethesis S.r.l.
# http://www.nethesis.it - nethserver@nethesis.it
#
# This script is part of NethServer.
#
# NethServer is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License,
# or any later version.
#
# NethServer is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with NethServer.  If not, see COPYING.
#

if [ "x${1}" == "x" ]; then
    cards=($(ls -A -1 /sys/class/net))
else
    cards=($1)
fi

for card in ${cards[@]}; do

    hwaddr=
    type=
    model=
    driver=
    speed=
    link=

    # Error on non-existing devices
    if ! [ -e "/sys/class/net/${card}" ]; then
	echo "[ERROR] nic-info: interface ${card} does not exist" 1>&2
	exit 1
    fi

    # Skip non-link elements:
    if ! [ -L "/sys/class/net/${card}" ]; then
	continue;
    fi	
    
    # Skip non-Ethernet physical devices (type=1)
    if [ "$(cat /sys/class/net/${card}/type)" != "1" ]; then
	continue
    fi

    #
    # FIXME: Skip virtual devices
    #        "device" links may not work in future kernel versions
    #
    if ! [ -e /sys/class/net/${card}/device ]; then
	continue
    fi

    # Skip bridge and tun/tap
    if [ -e /sys/class/net/${card}/brforward ] || [ -e /sys/class/net/${card}/tun_flags ]; then
        continue
    fi

    if [ -d /sys/class/net/${card}/master ] && [ ! -d /sys/class/net/${card}/brport ]; then
        link=`/bin/readlink  /sys/class/net/${card}/master`
        bond=`basename $link`
        hwaddr=`/usr/libexec/nethserver/bond-slave-mac ${bond} ${card}`
    else
        hwaddr=`cat /sys/class/net/${card}/address`
    fi
    
    # Skip if mac is not valid (00:00... or FF:FF...)
    if [ "${hwaddr}" == "00:00:00:00:00:00" ] || [ "${hwaddr}" == "ff:ff:ff:ff:ff:ff" ]; then
	continue
    fi
    
    driver=`basename $(ls -l /sys/class/net/$card/device/driver | awk '{print$NF}' )`
    type=`basename $(ls -l /sys/class/net/$card/device/subsystem | awk '{print$NF}' )`

    # Default if not avaiable in /sys/class/net
    if [ "a$type" == "a" ]; then
	type="???"
    fi
    
    if [ "a$driver" == "a" ]; then
	driver="Unknown Network Interface ($card)"
    fi

    model=$type

    # Get more details for pci and usb devices
    if [ "$type" == "pci" ]; then
	model=`/sbin/lspci -s $(basename $(ls -l /sys/class/net/$card/device | awk '{print$NF}' )) | cut -d':' -f3 | cut -c 2-`
    fi
    
    if [ "$type" == "usb" ]; then
	bus=`grep DEVICE= /sys/class/net/$card/device/uevent | cut -d"/" -f5`
	dev=`grep DEVICE= /sys/class/net/$card/device/uevent | cut -d"/" -f6`
	# work around the base8 convert
	let bus=`echo 1$bus`-1000
	let dev=`echo 1$dev`-1000
	model=`/bin/lsusb -s $bus:$dev | cut -d':' -f3 | cut -c 6-`
    fi

    link=$(cat /sys/class/net/$card/carrier 2>/dev/null)
    if [ $? != 0 ]; then
	/sbin/ip link set $card up 2>/dev/null
	link=$(cat /sys/class/net/$card/carrier 2>/dev/null)
	speed=$(cat /sys/class/net/$card/speed 2>/dev/null)
	/sbin/ip link set $card down 2>/dev/null
    else
	speed=$(cat /sys/class/net/$card/speed 2>/dev/null)
    fi

    echo $card,${hwaddr//,/ },${type//,/ },${model//,/ },${driver//,/ },$speed,$link

done

Keep in mind that the MACADDRESS of the new dummy interface is changing every time you reboot. I didn’t notice any problems with that on my VPS with Samba4 AD account provider installed.


HowTo install FOG-Project CloneServer on NethServer
(Davide Principi) #2

As alternative, adding a VLAN can be quicker and doesn’t require patching.

This is an example, just for reference:


(Rob Bosch) #3

I take it the script you use is still valid, but the VPS service at dply.co doesn’t exist anymore. The domain is parked.
Can you create this VLAN interface from Configuration / Network too?
newinterface
png1
png2
Make sure the IP for the new interface is in a different subnet than your main interface.
After creating of the dummy/VLAN interface, set the original interface (eth0) to RED role.

/edit: either it is not possible to create different roles on the interface and VLAN interface, or there is a bug.
I set eth0 as RED and eth0.10 as GREEN. Both in different subnets.
Then I tried to install Samba4 AD Accouintprovider. All installs well, but at 62% the install hangs on “adjust services”
@davidep any ideas?


(Davide Principi) #4

It happened also in the past. I hope they didn’t run out of business!

I don’t know: it used to work in the past from Nethgui too. I’ll try again next week…


(Rob Bosch) #5

After a LONG time (20-30minutes) The install process ends with an error message:

Task completed with errors
S96nethserver-dc-createldapservice #15 (exit status 512)
S01nethserver-dc-create-bridge #18 (exit status 65280)
S95nethserver-dc-waitstart #23 (exit status 256)
S96nethserver-dc-createldapservice #24 (exit status 512)
S96nethserver-dc-join #25 (exit status 256)
S97nethserver-dc-password-policy #26 (exit status 768)
S98nethserver-dc-createadmins #28 (exit status 768)
Adjust service nsdc #56 (exit status 1)
failed
Adjust service sssd #62 (exit status 1)
failed
Template /var/lib/machines/nsdc/etc/systemd/network/green.network #42 (exit status 1)
expansion of /var/lib/machines/nsdc/etc/systemd/network/green.network failed
Adjust service nsdc #47 (exit status 1)
restart service nsdc failed!


(Dan) #6

…and to have something copy/paste-able:

DEVICE=dummy0
BOOTPROTO=none
IPADDR=192.168.5.1
NETMASK=255.255.255.0
NM_CONTROLLED=no
ONBOOT=yes
TYPE=Ethernet
USRCTL=no

This should be modules-load.d. modules-loaded.d doesn’t exist, and putting the file there doesn’t allow the interface to come up.

For those who (like me) are n00bs with patch, it would be nice to see the actual command that needs to be run. For now, I just copied/pasted the full text you posted. But the interface still isn’t showing in the dashboard–if I’m reading the patch correctly (which is by no means guaranteed), the “full modified file” you posted isn’t in fact the modified file.

Edit: Curious. The “modified file” (which I copied and pasted from your post) is identical to the original nic-info file. It’s also identical to the nic-info file on my other server, which I’d previously modified following these or similar instructions, and which does show dummy0 in the GUI.


(Rob Bosch) #7

You are correct… I just C/P-ed this from the other thread. When I check my own config on my VPS, The location is modules.load.d
I will correct this in the howto. [/edit: done]

The resulting file is a C/P from my VPS, which is working and showing the interface in NetGui. So it looks like the last ‘patch’ is not necessary? Can someone else confirm this?


(Dan) #8

So what should I check to troubleshoot this further? The dummy0 interface is created and up:

[root@phabricator ~]# ifconfig
dummy0: flags=195<UP,BROADCAST,RUNNING,NOARP>  mtu 1500
        inet 192.168.5.1  netmask 255.255.255.0  broadcast 192.168.5.255
        inet6 fe80::c4fa:9cff:fe49:2614  prefixlen 64  scopeid 0x20<link>
        ether c6:fa:9c:49:26:14  txqueuelen 1000  (Ethernet)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 3  bytes 210 (210.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
(others deleted)

The system’s been rebooted (more than once). The nic-info script, as already established, doesn’t need to be patched. But the interface doesn’t show in the web GUI:
image

Or is there a different “best practice” to accomplish this?

Edit: kind of frustrating is that I have another Neth server, with the same VPS host, where I’m pretty sure I followed identical instructions, and the dummy interface appears in the GUI. The nic-info scripts are identical (same md5sum) between the two, and as far as I can tell, the ifcfg-dummy0 files differ only in the assigned IP addresses.

Edit 2: Well, when the GUI fails, try the CLI. db networks set dummy0 ethernet ipaddr=whatever netmask=whatever role green && db networks setprop eth0 role red && signal-event interface-update. It works, and now dummy0 shows up in the GUI (both on the dashboard and on the Network page). Kind of scratching my head as to why, but… Attempted comparison between the working and the non-working system isn’t finding any differences. It might (but shouldn’t) be relevant to note that the working system started with Neth 7.4 and was upgraded to 7.5, while the non-working system started with 7.5.