PREFIX versus NETMASK

28,385

The issue is probably that the IP address you are using confuses ipcalc when it tries to divine the NETMASK. Looking at the network scripts:

/etc/sysconfig/network-scripts/network-functions:
    133 expand_config ()
    134 {
    135     if [ -z "${NETMASK}" ]; then
    136         eval `/bin/ipcalc --netmask ${IPADDR}`
    137     fi
    138 
    139     if [ -z "${PREFIX}" ]; then
    140         eval `/bin/ipcalc --prefix ${IPADDR} ${NETMASK}`
    141     fi
    142 
    143     if [ -z "${BROADCAST}" ]; then
    144         eval `/bin/ipcalc --broadcast ${IPADDR} ${NETMASK}`
    145     fi
    146 
    147     if [ -z "${NETWORK}" ]; then
    148         eval `/bin/ipcalc --network ${IPADDR} ${NETMASK}`
    149     fi
    150 }

So say you are using 10.0.0.0 space which is technically in a /8, if you give this to ipcalc:

# /bin/ipcalc --netmask 10.34.102.1 
NETMASK=255.0.0.0

You can test if this was the issue by putting your address in there and seeing if it returns the value you expected to see as NETMASK. Personally, I think this is really a bug in CentOS, it seems like if NETMASK is null but PREFIX is specified it should use that to set NETMASK.

Share:
28,385

Related videos on Youtube

Clodoaldo
Author by

Clodoaldo

Updated on September 18, 2022

Comments

  • Clodoaldo
    Clodoaldo almost 2 years

    I did setup a virtual network interface in Centos 6 copying the ifcfg-eth0 to ifcfg-eth0:1 and changing the appropriate variables. But the connection was unstable. Although one of the pre-existent variables was PREFIX=24 I had to add NETMASK=255.255.255.0 to the virtual interface script to make the connection stable. Shoudn't these variables have the same effect?

    EDIT:

    This is ifcfg-eth0:1 unstable:

    DEVICE="eth0:1"
    NM_CONTROLLED="yes"
    ONBOOT=yes
    HWADDR=00:26:18:24:4D:xx
    TYPE=Ethernet
    BOOTPROTO=none
    IPADDR=69.64.93.x
    PREFIX=24
    GATEWAY=64.150.183.1
    DNS1=69.64.66.11
    DNS2=69.64.66.10
    DEFROUTE=yes
    IPV4_FAILURE_FATAL=yes
    IPV6INIT=no
    NAME="System eth0:1"
    

    In the stable one I just added this line:

    NETMASK=255.255.255.0
    

    ifconfig output with unstable first and stable after:

    eth0:1    Link encap:Ethernet  HWaddr 00:26:18:24:4D:xx  
              inet addr:69.64.93.x  Bcast:69.255.255.255  Mask:255.0.0.0
              UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
              Interrupt:28 Base address:0x6000 
    
    eth0:1    Link encap:Ethernet  HWaddr 00:26:18:24:4D:xx  
              inet addr:69.64.93.x  Bcast:69.64.93.255  Mask:255.255.255.0
              UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
              Interrupt:28 Base address:0x6000 
    
    • Zoredache
      Zoredache almost 13 years
      What is the output of ip addr show and ip route show with two different configurations? Is there any difference?
    • Clodoaldo
      Clodoaldo almost 13 years
      I don't want to touch the configuration again as that is a production server and I don't know how that affects the real interface. ifconfig before and after adding NETMASK showed 255.0.0.0 and 255.255.255.0 respectively as Mask of the virtual interface.
  • Clodoaldo
    Clodoaldo almost 13 years
    Yes I get the wrong netmask: # /bin/ipcalc --netmask 69.64.93.x NETMASK=255.0.0.0 But the real interface's IP, from where the script was copied, also gets a wrong netmask from ipcalc but the output from ifconfig is correct.