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
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 insmod
ed
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