busybox:启动阶段的静态 IP 配置过程

文章目录

  • [1. 前言](#1. 前言)
  • [2. 启动阶段 busybox 配置静态 IP 过程](#2. 启动阶段 busybox 配置静态 IP 过程)

1. 前言

限于作者能力水平,本文可能存在谬误,因此而给读者带来的损失,作者不做任何承诺。

2. 启动阶段 busybox 配置静态 IP 过程

编辑 /etc/network/interfaces 文件内容如下:

bash 复制代码
auto lo
iface lo inet loopback

auto eth0
iface eth0 inet static
address 192.168.1.188
netmask 255.255.255.0
gateway 192.168.1.1

启动时用命令 /sbin/ifup eth0 配置网络,该命令调用 busybox/networking/ifupdown.c 中的函数 ifupdown_main() 解析 /etc/network/interfaces 对网络进行配置:

c 复制代码
/* busybox/networking/ifupdown.c */

ifupdown_main()
	...
	static_up()

static int FAST_FUNC static_up(struct interface_defn_t *ifd, execfn *exec)
{
	int result;
# if ENABLE_FEATURE_IFUPDOWN_IP
	result = execute("ip addr add %address%/%bnmask%[[ broadcast %broadcast%]] "
			"dev %iface%[[ peer %pointopoint%]][[ label %label%]]", ifd, exec);
	result += execute("ip link set[[ mtu %mtu%]][[ addr %hwaddress%]] %iface% up", ifd, exec);
	result += execute("[[ip route add default via %gateway% dev %iface%[[ metric %metric%]]]]", ifd, exec);
	return ((result == 3) ? 3 : 0);
# else
	/* ifconfig said to set iface up before it processes hw %hwaddress%,
	 * which then of course fails. Thus we run two separate ifconfig */
	result = execute("ifconfig %iface%[[ hw %hwaddress%]][[ media %media%]][[ mtu %mtu%]] up",
				ifd, exec);
	result += execute("ifconfig %iface% %address% netmask %netmask%"
				"[[ broadcast %broadcast%]][[ pointopoint %pointopoint%]]",
				ifd, exec);
	result += execute("[[route add default gw %gateway%[[ metric %metric%]] %iface%]]", ifd, exec);
	return ((result == 3) ? 3 : 0);
# endif
}
相关推荐
s6516654964 小时前
IDT和GDT是什么
linux
Android系统攻城狮4 小时前
Linux Gstreamer深度解析之gst_audio_decoder_set_estimate_rate调用流程与实战(四十五)
linux·gstreamer音视频·音视频进阶
FED_AF5 小时前
Linux运维“邪修”功法之通配符
linux·运维
箓维5 小时前
线程的概念和理解
linux
云杂项5 小时前
tmux指南:安装、配置与高效使用(Ubuntu上)
linux·服务器·ubuntu
j7~5 小时前
【Linux网络编程】四十七.《Linux IO 模型详解:阻塞 IO、非阻塞 IO 与 IO 多路转接(select)》
linux·运维·网络·select·非阻塞io·阻塞io·i/o多路连接
GeW6 小时前
智能工厂背后:Linux在跑,数据库在扛,高端制造在加速
linux
qq_394562006 小时前
【在Linux上升级nginx】
linux·服务器·nginx
Tairitsu_H7 小时前
[Linux系统] 基础IO核心 | 系统接口 | 文件描述符 | 重定向
linux·服务器·文件操作
嵌入式-老费7 小时前
esp32开发与应用(用Python+PySide6解决上位机开发)
linux·单片机·嵌入式硬件