初次嘗試可以使用Docker的小型Linux,看了大部分Linux網絡配置的文章都是修改/etc/sysconfig/network-scripts/ifcfg-eth0文件的,但Alpine Linux沒有這樣的配置方式,搜了下"Alpine Linux network configure",找到了alpine wiki的網絡配置部分,根據自己的需求配置了一遍,在此記錄下。
配置本機hostname
echo 'slave1' > /etc/hostname
hostname -F /etc/hostname #立即生效
配置hosts
修改/etc/hosts文件:
192.168.1.150 shortname.domain.com
配置Loopback
添加文件 /etc/network/interfaces:
auto lo
iface lo inet loopback
即可設置IPv4的loopback地址127.0.0.1
配置Ethernet
以eth0為例:
- /etc/network/interfaces文件中,在所有eth0的配置項之前添加:
auto eth0
- Ipv4靜態地址配置
在/etc/network/interfaces文件的auto eth0
之后添加:
iface eth0 inet static
address 192.168.1.150
netmask 255.255.255.0
gateway 192.168.1.1
配置DNS
修改/etc/resolv.conf文件:
nameserver 114.114.114.114
nameserver 114.114.115.115
關閉ipv6
有的域名解析會優先使用ipv6,由於未手動配置ipv6,可能會出問題。
修改/etc/modprobe.d/aliases.conf文件:
將#alias net-pf-10 off
行解注釋。
重啟系統。
ip和gateway也可以像其他Linux一樣通過命令的方式臨時配置:
ifconfig eht0 192.168.1.150 netmask 255.255.255.0 up
route add default gw 192.168.1.1