Alpine Linux配置网络

初次尝试可以使用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为例:

  1. /etc/network/interfaces文件中,在所有eth0的配置项之前添加:
auto eth0
  1. 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
posted @ 2020-06-11 18:03  汉尼拔草  阅读(10165)  评论(0编辑  收藏  举报