Sunil Kumar
Sunil Kumar

Reputation: 42

Static IP address set in /etc/network/interface not getting updated after rmmod and insmod

I have configured static IP address in /etc/network/interfaces file as below

# The loopback interface
 auto lo
 iface lo inet loopback

# Wired or wireless interfaces
 auto eth0
 iface eth0 inet static
    address 192.168.1.2
    netmask 255.255.255.0
    broadcast 192.168.1.255
    hwaddress ether 01:06:92:85:00:12

But, when i try to do rmmod of the driver e1000 and then insmod again. the eth0 network interface would be loaded but, the ip address is not assigned until i explicitly do ifconfig eth0 or ifup eth0.

I have tried adding a script in /etc/network/if-up.d/loadeth.sh which has

#!/bin/sh

 if [ "$IFACE" = eth0 ]; then
        echo "eth0 up" >> /var/log/oak_pci.log
 fi

but, no luck the IP address is getting assigned.

My aim is that whenever i insmod the ethernet device driver i want to get the network interface(eth0) assigned with static IP address i have assigned in the interfaces file

Could anybody let me know what am i missing here

Upvotes: 0

Views: 3122

Answers (2)

Sunil Kumar
Sunil Kumar

Reputation: 42

After going through man page of udev i understood how to create udev rules and with a dummy test specified in this link https://www.tecmint.com/udev-for-device-detection-management-in-linux/ i was able to invoke the udev rules when insmod-ing and rmmod-ing a driver.

So, Here's what i did to automatically set the ip address for the ethernet network interface once driver is loaded or insmoded

I create a udev rules file named 80-net_auto_up.rules in the ethernet pcie driver recipe (it is an out of tree kernel module. Hence, custom recipe)

i added SUBSYSTEM=="net", ACTION=="add", RUN+="/sbin/ifup eth0"

and edited ethernet pcie driver recipe .bb file and added below lines

...

SRC_URI = "all source files of ethernet pcie driver
           file://80-net_auto_up.rules \
          "

FILES_${PN} += "${sysconfdir}/udev/rules.d/*"

do_install_append() {

    ...
    
    install -d ${D}${sysconfdir}/udev/rules.d
    install -m 0644 ${WORKDIR}/80-net_auto_up.rules ${D}${sysconfdir}/udev/rules.d/
}

and now it works. when i reset the ethernet device manually. The device is getting detected and Static IP address configured in the /etc/network/interfaces is set

Upvotes: 0

KamilCuk
KamilCuk

Reputation: 141698

what am i missing here

The files in /etc/network/ are parsed when when ifup or ifdown commands are executed. (I think also when ifplugd picks them up).

insmod loads a module into the running kernel.

You are missing the knowledge, that there is just no connection between insmod-ing a kernel driver and reading any files from /etc/network directory.

My aim is that whenever i insmod the ethernet device driver i want to get the network interface(eth0) assigned with static IP address i have assigned in the interfaces file

You may setup udev rule to run a custom script upon insmod-ing a kernel driver or when interface comes up.

Upvotes: 1

Related Questions