No DHCP after installing NS on top of Centos

NethServer Version: 7.9.2009
Module: nethserver-release

Pretty sure the default behavior prior to 7.9.2009 was if the single active network interface was configured with DHCP under NetworkManger’s control; system-init kept a DHCP configuration for this interface.

Installing nethserver on top of an updateted CentOS 7.9.2009 minimal installation (proxmox VM) results in a FIXED IP setup.

Did see this behavior on the ARM images too, where it is mitigated by stopping / disabling NetworkManager at the end of system-init.
Can confirm this hack works on x86_64 too (edited nethserver-install for this), this results in a DHCP configuration.

Before filing a issue I wonder if my assumption a DHCP configuration should survive system-init is correct?



(may be related to:)

1 Like

Another non critical (slightly related) observation seen on ARM before:

.... systemd[1]: Network Manager is not active.
.... systemd[1]: Dependency failed for Network Manager Wait Online.
.... systemd[1]: Job NetworkManager-wait-online.service/start failed with result 'dependency'.

NetworkManager-wait-online.service is not disabled by nethserver-install

The code that parses the network configuration is this one: https://github.com/NethServer/nethserver-base/blob/master/root/etc/e-smith/events/actions/nethserver-base-initialize-db

It received no changes since 2016.

By the way, if at the end the installation has the correct static IP on the green interface, it’s much better than the dynamic one.

I know, tried hard to find the origin. My only clue here is NetworkManager / network.service changed behavior.
EDIT:
Unfortunately my Perl knowledge is to limited to fully grasp the line I suspect not handling the alleged changed behavior of stopping Networkmanager. (my lack of knowledge: where does $ifname get it’s value?)

To be frank I do not have a problem with it because here it does end up with a correct fixed IP configuration.
Have read one report it did not work well on a RPI install, it ended up with a fixed fall-back configuration. And the referenced install on a (Hetzner) vps.

And again, pretty sure it alway’s ended up with DHCP config in the past. :thinking:

EDIT2: Very old closed issue addressing this in the past:

the value of $ifname come from as an argument of the function fetch_ifcfg_props

sub fetch_ifcfg_props
{
    my $ifname = shift;
    my %props = ();

    # Note: command returns empty output if interface is DOWN:
    open(ADDR, '-|', "ip -o -4 address show dev $ifname");

so check the line nethserver-base/root/etc/e-smith/events/actions/nethserver-base-initialize-db at bceaf5457b92faeea214e6b1c90db718086b6bda · NethServer/nethserver-base · GitHub

shift in perl takes the first arg: shift in Perl

if we would like to assign different arguments we would like to use Processing command line arguments - @ARGV in Perl

something like :

sub functionToDoSomething('toto','25') {
 my ($name, $age) = @ARGV;

or

sub functionToDoSomething('toto','25') {
my $name = shift;
my $age = shift;
2 Likes

Just thinking out loud here :upside_down_face:

See output of (this is the real output it did not truncate, linefeed at \)

# systemctl status NetworkManager
● NetworkManager.service - Network Manager
   Loaded: loaded (/usr/lib/systemd/system/NetworkManager.service; enabled; vendor preset: enabled)
   Active: active (running) since Mon 2021-02-08 09:43:44 EST; 30s ago
     Docs: man:NetworkManager(8)
 Main PID: 11224 (NetworkManager)
   CGroup: /system.slice/NetworkManager.service
           ├─11224 /usr/sbin/NetworkManager --no-daemon
           └─11241 /sbin/dhclient -d -q -sf /usr/libexec/nm-dhcp-helper -pf /var/run/dhclient-eth0.pid -lf /var/lib/NetworkManager/dhclient-7fd770b9-4431-43f8-b1f1-01d13608a404-eth0.lease...

<OUTPUT TRUNCATED>

# ip -o -4 address show dev eth0
2: eth0    inet 10.0.0.158/24 brd 10.0.0.255 scope global noprefixroute dynamic eth0\       valid_lft 86362sec preferred_lft 86362sec
# ps -A -o cmd | grep -E '(/| )dhclient .' | grep -q eth0
# echo $?
0


# systemctl stop NetworkManager

# ip -o -4 address show dev eth0
2: eth0    inet 10.0.0.158/24 brd 10.0.0.255 scope global noprefixroute dynamic eth0\       valid_lft 86334sec preferred_lft 86334sec
# ps -A -o cmd | grep -E '(/| )dhclient .' | grep -q eth0
# echo $?
1

With NM running
ps -A -o cmd | grep -E '(/| )dhclient .' | grep -q eth0
exit’s 0, which can explain why the hack stop NM at the end of system-init works

Also note the place of dynamic in the first command,
If I count the output arguments it in in the 10th position. here :

my($id, $dev, $family, $cidr, $brd_family, $brd_address, $scope_lbl, $scope, $dynamic, $end) = split(/\s+/, $_, 10);

(again not knowledgeable with PERL.)
It seems to me dynamic is expected on the 9th position. If this is true this test results in False if NM is not running : $dhclient_running || $dynamic =~ 'dynamic'

EDIT: Why do I see noprefixroute?

Can not read the full content: https://access.redhat.com/solutions/4275681

It is being added by NM version 1.10 or later (it came with RHEL 7.5).
I think it’s safe to update nethserver-base-initialize-db to get dynamic from 10th position, but I’d ask @giacomo. We could also find a better way to discover if an IP came from dhcp (playing with NM).

Thank you for finding this,
looks like that specific line is broken for a while. :thinking:

If the result of ip -o -4 address show dev $ifname is inconsistent maybe not making assumptions of the output is better after all.

I can try to fix it, but the code is working since 5 years.

Are you willing to retest the install on all the following? :unamused:

  • virtual machine with DHCP
  • virtual machine without DHCP
  • Digital Ocean VPS
  • NethServer image for Digital Ocean Market
  • Nethesis box
2 Likes

Come on Giacomo, we know you have nothing to do! :stuck_out_tongue:

Can do this :grinning:

what about an defensive (a bit dirty) improvement: (add || $end =~ 'dynamic' )

    if ($dhclient_running || $dynamic =~ 'dynamic' || $end =~ 'dynamic' ) {
        $props{'bootproto'} = 'dhcp';
        $props{'gateway'} = '';
    } else {
        $props{'bootproto'} = 'none';
    }
1 Like

can confirm this solves it on my Centos VM, before system-init edited

# cat /etc/e-smith/events/actions/nethserver-base-initialize-db | grep -5 'dynamic'

    # Note: command returns empty output if interface is DOWN:
    open(ADDR, '-|', "ip -o -4 address show dev $ifname");
    while(<ADDR>) {
        chomp;
        my($id, $dev, $family, $cidr, $brd_family, $brd_address, $scope_lbl, $scope, $dynamic, $end) = split(/\s+/, $_, 10);
        my $dhclient_running = (system("ps -A -o cmd | grep -E '(/| )dhclient .' | grep -q $ifname") == 0);

        if ($dhclient_running || $dynamic =~ 'dynamic' || $end =~ 'dynamic') {
            $props{'bootproto'} = 'dhcp';
            $props{'gateway'} = '';
        } else {
            $props{'bootproto'} = 'none';
        }

Have a dhcp setup after system-init :yum:

# db networks show
eth0=ethernet
    bootproto=dhcp
    gateway=
    ipaddr=10.0.0.158
    netmask=255.255.255.0
    role=green
ppp0=xdsl-disabled
    AuthType=auto
    FwInBandwidth=
    FwOutBandwidth=
    Password=
    name=PPPoE
    provider=xDSL provider
    role=red
    user=

EDIT:
It does not break if network is brought up without NM and noprefixroute is not added to the interface:

# ip -o -4 address show dev eth0
2: eth0    inet 10.0.0.158/24 brd 10.0.0.255 scope global dynamic eth0\       valid_lft 86067sec preferred_lft 86067sec

# db networks show
eth0=ethernet
    bootproto=dhcp
    gateway=
    ipaddr=10.0.0.158
    netmask=255.255.255.0
    role=green
ppp0=xdsl-disabled
    AuthType=auto
    FwInBandwidth=
    FwOutBandwidth=
    Password=
    name=PPPoE
    provider=xDSL provider
    role=red
    user=
1 Like

ROTFL

another test in the Centos VM;
without NM fixed IP:

ip -o -4 address show dev eth0
2: eth0    inet 10.0.0.158/24 brd 10.0.0.255 scope global eth0\       valid_lft forever preferred_lft forever

# db networks show
eth0=ethernet
    bootproto=none
    gateway=10.0.0.100
    ipaddr=10.0.0.158
    netmask=255.255.255.0
    role=green
ppp0=xdsl-disabled
    AuthType=auto
    FwInBandwidth=
    FwOutBandwidth=
    Password=
    name=PPPoE
    provider=xDSL provider
    role=red
    user=

Results in a correct FIXED IP configuration.

IMO it is pretty safe to say adding || $end =~ 'dynamic' mitigates NM/DHCP behavior and does not break other network configurations.

2 Likes

3 posts were split to a new topic: Chat about Perl fun

Thank you for the effort, the patch has been merged!

Now it comes the hardest part: testing :slight_smile:
We also need to build a new iso to check for regressions.

1 Like

Tip for those who want to help with testing,

before running nethserver-install on your CentOS test-setup edit
/etc/yum.repos.d/NethServer.repo
enable nethserver-testing (enabled=1) only for nethserver-base (includepkgs=nethserver-base*):

...
[nethserver-testing]
name=NethServer-$releasever - Testing
mirrorlist=http://mirrorlist.nethserver.org/?release=$releasever&repo=testing&arch=$basearch&nsrelease=$nsrelease
#baseurl=http://mirror.nethserver.org/nethserver/$releasever/testing/$basearch/
gpgcheck=1
repo_gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-NethServer-$releasever
enabled=1
enablegroups=0
includepkgs=nethserver-base*  

2 Likes

This is the ISO for testing: http://packages.nethserver.org/6422/nethserver-7.9.2009_issue6422-x86_64.iso

3 Likes

@giacomo

Hi Giacomo

Will try early evening on a VM…

My 2 cents
Andy

1 Like

Thank you! I did a quick test with unattended install and everything seems good :wink:

1 Like