[Linux使用] Centos 7.0 网络配置双网卡

Host-only与网络地址转换(NAT)

在VirtualBox中对虚拟机需要设置

  • 网卡1:网络地址转换(NAT)
    • 记录MAC地址:080027C68C02
  • 网卡2:仅主机(Host-Only)网络
    • 记录MAC地址:0800276D4274

在VirtualBox中全局进行设置

全局工具 -> 主机网络管理器-> 网卡 -> 手动配置网卡

  • ipv4地址:192.168.56.1
  • ipv4网络掩码:255.255.255.0

进入虚拟机

[root@localhost ~]# ip addr
1: lo:  mtu 65536 qdisc noqueue state UNKNOWN qlen 1
    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: enp0s3:  mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 08:00:27:c6:8c:02 brd ff:ff:ff:ff:ff:ff
    inet6 fe80::a00:27ff:fec6:8c02/64 scope link
       valid_lft forever preferred_lft forever
3: enp0s8:  mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 08:00:27:6d:42:74 brd ff:ff:ff:ff:ff:ff
    inet6 fe80::a00:27ff:fe6d:4274/64 scope link
       valid_lft forever preferred_lft forever
[root@localhost ~]# cd /etc/sysconfig/network-scripts/
[root@localhost network-scripts]# ls
ifcfg-enp0s3  ifdown       ifdown-ippp  ifdown-post    ifdown-sit       ifdown-tunnel  ifup-bnep  ifup-ipv6  ifup-plusb  ifup-routes  ifup-TeamPort  init.ipv6-global
ifcfg-enp0s8  ifdown-bnep  ifdown-ipv6  ifdown-ppp     ifdown-Team      ifup           ifup-eth   ifup-isdn  ifup-post   ifup-sit     ifup-tunnel    network-functions
ifcfg-lo      ifdown-eth   ifdown-isdn  ifdown-routes  ifdown-TeamPort  ifup-aliases   ifup-ippp  ifup-plip  ifup-ppp    ifup-Team    ifup-wireless  network-functions-ipv6
[root@localhost network-scripts]# vi ifcfg-enp0s3
[root@localhost network-scripts]# vi ifcfg-enp0s8
[root@localhost network-scripts]# service network restart

ifcfg-enp0s3 配置(对应-网络地址转换(NAT))

TYPE=Ethernet
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=dhcp
DEFROUTE=yes
#IPADDR=10.0.0.20
#NETMASK=255.255.255.0
#GATEWAY=10.0.0.2
#DNS1=10.0.0.2
#DNS2=223.5.5.5
#DEFROUTE=yes
#PEERDNS=yes
#PEERROUTES=yes

IPV4_FAILURE_FATAL=no
#IPV6INIT=yes
#IPV6_AUTOCONF=yes
#IPV6_DEFROUTE=yes
#IPV6_FAILURE_FATAL=no
#IPV6_ADDR_GEN_MODE=stable-privacy

NAME=enp0s3
UUID=d4c7f904-100b-40cc-9890-1051bf5e2ddf
DEVICE=enp0s3
ONBOOT=yes
#此处为刚才记录的MAC地址
HWADDR=08:00:27:c6:8c:02 

ifcfg-enp0s8 配置(对应-仅主机(Host-Only)网络)

TYPE=Ethernet
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=static
DEFROUTE=yes
IPADDR=192.168.56.101
NETMASK=255.255.255.0
GATEWAY=192.168.56.1
#DNS1=10.0.0.2
#DNS2=223.5.5.5
#DEFROUTE=yes
#PEERDNS=yes
#PEERROUTES=yes

IPV4_FAILURE_FATAL=no
#IPV6INIT=yes
#IPV6_AUTOCONF=yes
#IPV6_DEFROUTE=yes
#IPV6_FAILURE_FATAL=no
#IPV6_ADDR_GEN_MODE=stable-privacy

NAME=enp0s8
UUID=d4c7f904-100b-40cc-9910-1151bf5e2ddf
DEVICE=enp0s8
ONBOOT=yes
HWADDR=08:00:27:6d:42:74

你可能感兴趣的:(Linux)