开启DHCP
进入内核编译文件夹
$cd ~/NUC970_Buildroot-master/
开启DHCP
$make menuconfig
选择System configuration下的这一项
根据所需填入对应内容
保存退出,make.
interfaces文件
打开output/target/etc/network/interfaces文件,发现内容已变化为:
# interface file auto-generated by buildroot
auto lo
iface lo inet loopback
auto eth0
iface eth0 inet dhcp
pre-up /etc/network/nfs_check
wait-delay 15
该文件若未进行网络设置,其内容为
# interface file auto-generated by buildroot
auto lo
iface lo inet loopback
所以我们一般都是通过修改该文件设置DHCP或者静态IP
设置DHCP如上面代码所示:
auto eth0
iface eth0 inet dhcp
静态IP则为:
auto eth0
iface eth0 inet static
address 192.168.0.100
gateway 192.168.0.1
netmask 255.255.255.0
但是会发现每次make编译内核后,我们修改的interfaces文件会被覆盖掉,其问题就出现在这句话中:
# interface file auto-generated by buildroot
修改源
interfaces文件的内容其实被 package/skeleton/skeleton.mk文件控制,相关内容如下:
define SKELETON_SET_NETWORK_LOCALHOST
( \
echo "# interface file auto-generated by buildroot"; \
echo ; \
echo "auto lo"; \
echo "iface lo inet loopback"; \
) > $(TARGET_DIR)/etc/network/interfaces
endef
SKELETON_NETWORK_DHCP_IFACE = $(call qstrip,$(BR2_SYSTEM_DHCP))
ifneq ($(SKELETON_NETWORK_DHCP_IFACE),)
define SKELETON_SET_NETWORK_DHCP
( \
echo ; \
echo "auto $(SKELETON_NETWORK_DHCP_IFACE)"; \
echo "iface $(SKELETON_NETWORK_DHCP_IFACE) inet dhcp"; \
echo " pre-up /etc/network/nfs_check"; \
echo " wait-delay 15"; \
) >> $(TARGET_DIR)/etc/network/interfaces
$(INSTALL) -m 0755 -D $(SKELETON_PKGDIR)/nfs_check \
$(TARGET_DIR)/etc/network/nfs_check
endef
endif
可以看到该文件首先将如下内容写入interfaces:
# interface file auto-generated by buildroot
auto lo
iface lo inet loopback
然后读取menuconfig中DHCP设置项内容:
SKELETON_NETWORK_DHCP_IFACE =$(callqstrip,$(BR2_SYSTEM_DHCP))
并进行判断:
ifneq ($(SKELETON_NETWORK_DHCP_IFACE),)
若不为空,则开启了DHCP功能,并使用写入的eth0进行设置,同时将其定义为一个可以复用的define:
define SKELETON_SET_NETWORK_DHCP
echo "auto $(SKELETON_NETWORK_DHCP_IFACE)";
echo "iface $(SKELETON_NETWORK_DHCP_IFACE) inet dhcp";
自定义修改
由于我的板子只有一个网口,所以我想设置一个静态IP,在未启用DHCP的情况下使用,修改如下:
ifneq ($(SKELETON_NETWORK_DHCP_IFACE),)
define SKELETON_SET_NETWORK_DHCP
( \
echo ; \
echo "auto $(SKELETON_NETWORK_DHCP_IFACE)"; \
echo "iface $(SKELETON_NETWORK_DHCP_IFACE) inet dhcp"; \
echo " pre-up /etc/network/nfs_check"; \
echo " wait-delay 15"; \
) >> $(TARGET_DIR)/etc/network/interfaces
$(INSTALL) -m 0755 -D $(SKELETON_PKGDIR)/nfs_check \
$(TARGET_DIR)/etc/network/nfs_check
endef
else
define SKELETON_SET_NETWORK_STATIC
( \
echo ; \
echo "auto eth0"; \
echo "iface eth0 inet static"; \
echo "address 192.168.0.100"; \
echo "gateway 192.168.0.1"; \
echo "netmask 255.255.255.0"; \
) >> $(TARGET_DIR)/etc/network/interfaces
endef
endif
同时定义一个define:
define SKELETON_SET_NETWORK_STATIC
还需增添一点内容,将增加的define增加在后面:
define SKELETON_SET_NETWORK
mkdir -p $(TARGET_DIR)/etc/network/
$(SKELETON_SET_NETWORK_LOCALHOST)
$(SKELETON_SET_NETWORK_DHCP)
$(SKELETON_SET_NETWORK_STATIC)
endef
这样,每次make后都是设置好的interfaces。
|