在 Alpine Linux 中配置网络,您可以根据以下步骤进行:

  1. 配置本机 hostname:

bash echo 'slave1' > /etc/hostname hostname -F /etc/hostname # 立即生效

  1. 配置 hosts: 修改 /etc/hosts 文件:

text 192.168.1.150 shortname.domain.com

  1. 配置 Loopback: 添加文件 /etc/network/interfaces:

text auto lo iface lo inet loopback

  1. 配置 Ethernet: 以 eth0 为例:

  2. 在/etc/network/interfaces文件中添加:

    text auto eth0

  3. IPv4 静态地址配置:

    text iface eth0 inet static address 192.168.1.150 netmask 255.255.255.0 gateway 192.168.1.1

  4. 配置 DNS: 修改 /etc/resolv.conf 文件:

text nameserver 114.114.114.114 nameserver 114.114.115.115

  1. 关闭 ipv6(如果不需要): 修改 /etc/modprobe.d/aliases.conf 文件:

  2. 将 #alias net-pf-10 off 行解注释。

  3. 重启系统。

  4. 临时配置 IP 和网关:

text ifconfig eth0 192.168.1.150 netmask 255.255.255.0 up route add default gw 192.168.1.1

  1. 重启网络服务:

text rc-service networking restart

  1. 检查网络连接:

text ping google.com

  1. 安装和配置无线网络:

    • 安装wpa_supplicant:

    bash apk add wpa_supplicant

    • 配置无线网络:

    bash wpa_passphrase 'YourSSID' 'YourPassword' > /etc/wpa_supplicant/wpa_supplicant.conf

    • 启动无线网络:

    bash wpa_supplicant -B -i wlan0 -c /etc/wpa_supplicant/wpa_supplicant.conf

这些步骤可以帮助您在 Alpine Linux 上配置网络。如果您需要更详细的帮助或了解更多命令选项,可以通过 apk --help 或查看 apk 的手册页 man apk 获取。