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
}
相关推荐
lixzest34 分钟前
Vim 快捷键速查表
linux·编辑器·vim
ICscholar7 小时前
ExaDigiT/RAPS
linux·服务器·ubuntu·系统架构·运维开发
sim20207 小时前
systemctl isolate graphical.target命令不能随便敲
linux·mysql
米高梅狮子8 小时前
4. Linux 进程调度管理
linux·运维·服务器
再创世纪8 小时前
让USB打印机变网络打印机,秀才USB打印服务器
linux·运维·网络
fengyehongWorld9 小时前
Linux ssh端口转发
linux·ssh
知识分享小能手11 小时前
Ubuntu入门学习教程,从入门到精通, Ubuntu 22.04中的Shell编程详细知识点(含案例代码)(17)
linux·学习·ubuntu
Xの哲學11 小时前
深入解析 Linux systemd: 现代初始化系统的设计与实现
linux·服务器·网络·算法·边缘计算
龙月12 小时前
journalctl命令以及参数详解
linux·运维
EndingCoder12 小时前
TypeScript 的基本类型:数字、字符串和布尔
linux·ubuntu·typescript