查看当前alpine虚拟机环境的网卡和IP配置
进入虚拟机环境, 输入命令:
ip address show
lo 为回环地址,eth0 为外部访问的网卡地址。显示如下:
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 08:00:27:a9:f3:dd brd ff:ff:ff:ff:ff:ff
inet 192.168.0.102/24 scope global eth0
valid_lft forever preferred_lft forever
inet6 fe80::a00:27ff:fea9:f3dd/64 scope link
valid_lft forever preferred_lft forever
编辑网卡配置
如系统为 virtual box
内的虚拟机,可设置为双网卡。
虚拟机设置==>网络:
创建一个和宿主机并列的, 处于相同局域网的独立网络环境, 宿主机可通过局域网IP访问.
网卡1(对应eth0):连接方式:桥接网卡
;接入网线;
创建一个宿主机下的网络环境, 宿主机使用端口映射与其交互.
网卡2(对应eth1):连接方式:网络地址转换NAT
;接入网线; 端口转发;
vi /etc/network/interfaces
iface eth0 inet dhcp
改为 iface eth0 inet static
,
参照宿主机IP网段,配置对应的 address
, netmask
, gateway
项。
新增 eth1
网卡,连接方式为 dhcp
auto lo
iface lo inet loopback
auto eth0
iface eth0 inet static
address 192.168.0.102
netmask 255.255.255.0
gateway 192.168.0.1
auto eth1
iface eth1 inet dhcp
重启服务
service networking restart
备忘: /etc/network/interfaces
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).
source /etc/network/interfaces.d/*
# The loopback network interface
auto lo
iface lo inet loopback
# The primary network interface
# allow-hotplug enp4s0
# iface enp4s0 inet dhcp
auto enp4s0
iface enp4s0 inet static
address 192.168.2.12
netmask 255.255.255.0
gateway 192.168.2.1
Alpine Linux配置网络 https://www.cnblogs.com/peanutk/p/13094935.html
Alpine Linux设置固定IP https://my.oschina.net/u/2306127/blog/1589995
Xshell无法连接到虚拟机Linux系统(桥接方式) https://blog.csdn.net/yefeng0810/article/details/81150605