Netmask not detected properly on Debian 9

kristian

Verified User
Joined
Nov 4, 2005
Messages
436
Location
Norway
Hi,

The code that tries to find the netmask fails on (at least) Debian 9. The line for non-FreeBSD for this is on line 744 of setup.sh:

Code:
NM=`/sbin/ifconfig $ETH_DEV | grep 'Mask:' | cut -d: -f4`;

The output from ifconfig for an interface "eth0" looks like this on Debian 9:

Code:
# ifconfig eth0
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 1.2.3.4  netmask 255.255.255.0  broadcast 1.2.3.255
        inet6 fe80::216:3eff:fe49:6573  prefixlen 64  scopeid 0x20<link>
        ether 00:16:3e:49:65:73  txqueuelen 1000  (Ethernet)
        RX packets 13403845  bytes 1908847857 (1.7 GiB)
        RX errors 0  dropped 438  overruns 0  frame 0
        TX packets 747033  bytes 93890407 (89.5 MiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

Suggested replacement for line 744 which should capture the correct netmask on at least Debian 8 and 9, as well as CentOS 6 and 7, which is all I have available for testing at the moment:

Code:
NM=$(/sbin/ifconfig ${ETH_DEV} | grep -oP "(netmask |Mask:)\K[^\s]+(?=.*)")

It seems that running
Code:
cd /usr/local/directadmin
./directadmin i
does not use this same script, so there might be more locations where this change should be made.
 
Last edited:
Thanks for the report, nice solution.

The netmask from the setup.sh, is dumped into the setup.txt, where the "./directadmin i" will find it.
As any invalid netmasks are ignored and reverted to 255.255.255.0 anyway, that's why it's not likely reported until now.
Also, DA's netmasks shown are essentially just cosmetic, since the server IP is loaded up by the system, assumingly with the correct netmask already.
And the IP aliases, although DA sets whatever you specify, often times just defaults to the main server IPs netmask anyway.. so for both cases, what you set in DA isn't going to make or break anything. That being said, I would still want it to show correctly to avoid confusion, so thanks for the solution :)

setup.sh now has the fix.

John
 
Back
Top