Arch 支持每一种接口的网络连接方式dhcp ,static,两个接口如eth0,eth1不能配置相同的连接方式和几乎一样的网络配置,如:
eth0,eth1都配置为ethernet:static ,且都设置了IP,ROUTE,GATEWAY,DNS 会出现冲突,只有最后启用的接口生效,前一个配置接口则不能正常UP;
Arch 的ethernet 以Bridge 接入主机host 网络或接口,配置为指定static的IP,GATEWAY有效,但是DNS无效,不能使用域名访问网络。
Arch 需要以指定static IP接入主机网络,能够使用DNS,则要选择NAT (或NAT network)
在Virtualbox 启用NAT network adapter,选择已经创建的虚拟natnetwork,然后定义主机到Arch 的端口转发条目,如:
Arch IP:10.0.2.2 Arch eth0 设置完整的static 配置,启用service: Jenkins port:8082
Host IP: 192.168.2.3 希望使用相同端口访问 Jenkins in Arch
端口转发条目为:tcp 192.168.2.3:8082 10.0.2.2:8082
配置实例:
[root@Arch arch]# cd /etc/netctl
[root@Arch netctl]# ls
bridgeenp0s3enp0s3_bridge enp0s8 examples hooksinterfaces
[root@Arch netctl]# cat enp0s3
Description=’A basic static ethernet connection’
Interface=enp0s3
Connection=ethernet
IP=static
#IP=dhcp
Address=(‘10.0.2.68/24’)
#Routes=(‘192.168.0.0/24 via 192.168.1.2’)
Gateway=’10.0.2.1’
DNS=(‘10.0.2.1’)
## For IPv6 autoconfiguration #IP6=stateless ## For IPv6 static address configuration #IP6=static #Address6=('1234:5678:9abc:def::1/64' '1234:3456::123/96') #Routes6=('abcd::1234') #Gateway6='1234:0:123::abcd' SkipNoCarrier=yes ForceConnect=yes [root@Arch netctl]# pwd /etc/netctl [root@Arch netctl]# Arch connect host:host only【bridge interface】
Virtualbox host only network:
It can be thought of as a hybrid between the bridged and internal networking modes: as withbridged networking, the virtual machines can talk to each other and the host as if they wereconnected through a physical Ethernet switch. Similarly, as with internal networking however, aphysical networking interface need not be present, and the virtual machines cannot talk to theworld outside the host since they are not connected to a physical networking interface.
Instead, when host-only networking is used, VirtualBox creates a new software interface onthe host which then appears next to your existing network interfaces. In other words, whereaswith bridged networking an existing physical interface is used to attach virtual machines to,with host-only networking a new “loopback” interface is created on the host. And whereas withinternal networking, the traffic between the virtual machines cannot be seen, the traffic on the“loopback” interface on the host can be intercepted.
VirtualBox host only 是一个虚拟的bridge adapter;在主机只有一个访问Internet的网口时,Arch 使用NAT 静态IP接入主机网络,Arch 的服务通过端口转发可以正常在外部访问,
但主机host 不能直接使用SSH,telent 管理NAT内部的Guest, 这时Arch新启用一个接口接入Host Only, 仅配置ethernet static IP,避免配置Gateway,Route,Dns 妨碍其他接口的正常通信。
配置实例:
[root@Arch netctl]# cat enp0s8 Description='A basic static ethernet connection' Interface=enp0s8 #Connection=ethernet Connection=ethernet IP=static Address=('192.168.56.202/24') #Routes=('192.168.0.0/24 via 192.168.1.2') #Gateway='192.168.56.1' #DNS=('192.168.56.1') ## For IPv6 autoconfiguration #IP6=stateless ## For IPv6 static address configuration #IP6=static #Address6=('1234:5678:9abc:def::1/64' '1234:3456::123/96') #Routes6=('abcd::1234') #Gateway6='1234:0:123::abcd' SkipNoCarrier=yes ForceConnect=yes [root@Arch netctl]#
综合配置实例:
VirtualBox NAT Adapter 配置端口转发
Arch 网络接口连接状态
[root@Arch netctl]# ifconfig
docker0: flags=4163
将/etc/netctl/example/ethernet-static 模板配置copy一份到/etc/netctl目录下,按照需要编辑该配置文件,注意如果是LAN内,优先设置192.168.xx.xx。
如:cd /etc/netctl
cp example/ethernet-static eth1
nano eth1
另外再追加以下配置:
ForceConnect=yes
SkipNoCarrier=yes
保存之后执行netcctl start eth1 #不需要执行netcctl start ,否则开机启动会失败,eth1会up失败
netctl enable eth1
然后reboot后,会自动设置为配置的静态IP。完整的配置文件如下:
# /etc/netctl/lan1 Description='A basic static ethernet connection' Interface=(eth1)enp1s0 Connection=ethernet IP=static #Routes=('192.168.99.0/24' via '192.168.99.11') #按照默认配置注释,否则启用后会在开机过程中Fail Address=('192.168.99.4/24') Gateway='192.168.99.1' #该行可以注释,如果eth0为dhcp的话可能引起网关冲突,使得eth1 在启动时无法UP DNS=('8.8.8.8')#该行必须的配置为eth0 可以访问的DNS Server,否则eth0 无法connect internet ForceConnect=yes ##没有一些具体原因,在reboot后启动fail, 如 vendor preset disabled 等,增加该配置即可。 SkipNoCarrier=yes
添加用户登陆CLI:useradd -m -G wheel -s /bin/bash arch
设置密码: passwd arch(tcuser)
安装并启用SSH
pacman -Sy openssh systemctl enable sshd systemctl start sshd #不需要执行start,否则开机启动会失败,eth1会up失败