Dracut, netboot and default gateway in RHEL/CentOS 7

RHEL

WAT?

Ok, so I've rolled up a new host and made it boot OS from the iSCSI drive. Great. I have 4 NICs in this box.

After booting machine default gateway was set up on the iSCSI network. Weird, but ok - I tried to change that with:

  • Setting up a gateway in /etc/sysconfig/network by entering GATEWAY param; didn't work, still defroute on iSCSI NIC
  • Setting up DEFROUTE="no" in /etc/sysconfig/network-scripts/ifcfg-eno2 (the iSCSI NIC). Didn't work, still defroute on iSCSI NIC
  • Use "nmcli" to setup ipv4.never-default for the iSCSI NIC. Didn't work - this only rewrites ifcfg* script adding DEFROUTE param

So What?

Yup, things were going weirdo and honestly I left this for a while as I simply didn't find the answer - even after debugging the /etc/sysconfig/network-scripts/* scripts. Something - not NetworkManager - was overwriting the default route during boot after NetworkManager did it's job.

I came back to this problem after while and poked around this one ifcfg config for the iSCSI NIC:

# Generated by dracut initrd
DEVICE="eno2"
ONBOOT=yes
NETBOOT=yes
UUID="whatevercdff28f030fd"
BOOTPROTO=none
IPADDR="192.168.1.2"
GATEWAY="192.168.1.1"
NETMASK="255.255.255.0"
HWADDR="00:22:10:d5:a2:6d"
TYPE=Ethernet
NAME="eno2"

And finally I payed attention to this comment: Generated by dracut initrd. While installing this host I had to reconfigure dracut a little bit to make grub boot this OS from network via iSCSI (I wrote about it here as this is a bug in CentOS/RHEL7). In /etc/default/grub I entered:

GRUB_TIMEOUT=5
GRUB_DISTRIBUTOR="$(sed 's, release .*$,,g' /etc/system-release)"
GRUB_DEFAULT=saved
GRUB_DISABLE_SUBMENU=true
GRUB_TERMINAL_OUTPUT="console"
GRUB_CMDLINE_LINUX="ip=192.168.1.2::192.168.1.1:255.255.255.0:[...]
GRUB_DISABLE_RECOVERY="true"

That's it! This iSCSI network is a simple P2P connection, so it does not need the gateway there! Basing on this article the proper format for dracut is:

ip=<client-IP>:[ <server-id> ]:<gateway-IP>:
    <netmask>:<client_hostname>:<interface>:{none|off}

So I simply removed the gateway 192.168.1.1 from the grub default config, regenerated grub with:

grub2-mkconfig -o /boot/grub2/grub.cfg

And after reboot my default gateway was set up exactly like I configured it in /etc/sysconfig/network

Yes - that was truly pain in the ass!

Comments