一、虚拟机网卡映射
1 查看物理机网卡
2 配置virtualbox虚拟机网卡映射
->网络->网卡1->启用网络连接【勾选】->连接方式【桥接网卡】->名称【选择想要映射的物理机网络的名称】->确定
二、虚拟机centOS7.9网络配置
1 获取超级管理员
$ su root
密码:输入密码
#
2 查看网卡
其中lo是本地环回网卡,br0是网桥,enp0s3是上一步骤映射出去的网卡,所以我们配置enp0s3以便和外部进行网络通信。
# ip addr
lo
enp0s3
br0
# ifconfig
lo
enp0s3
br0
[root@MiWiFi-R4CM-srv ~]# ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default 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: enp0s3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether 08:00:27:02:d1:be brd ff:ff:ff:ff:ff:ff
inet 192.168.31.149/24 brd 192.168.31.255 scope global noprefixroute dynamic enp0s3
valid_lft 43075sec preferred_lft 43075sec
inet6 fe80::a9af:22dd:f375:6dac/64 scope link noprefixroute
valid_lft forever preferred_lft forever
3: virbr0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN group default qlen 1000
link/ether 52:54:00:f8:01:4c brd ff:ff:ff:ff:ff:ff
inet 192.168.122.1/24 brd 192.168.122.255 scope global virbr0
valid_lft forever preferred_lft forever
4: virbr0-nic: <BROADCAST,MULTICAST> mtu 1500 qdisc pfifo_fast master virbr0 state DOWN group default qlen 1000
link/ether 52:54:00:f8:01:4c brd ff:ff:ff:ff:ff:ff
[root@MiWiFi-R4CM-srv ~]#
[root@MiWiFi-R4CM-srv ~]#
[root@MiWiFi-R4CM-srv ~]# ifconfig
enp0s3: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.31.149 netmask 255.255.255.0 broadcast 192.168.31.255
inet6 fe80::a9af:22dd:f375:6dac prefixlen 64 scopeid 0x20<link>
ether 08:00:27:02:d1:be txqueuelen 1000 (Ethernet)
RX packets 1148 bytes 76330 (74.5 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 142 bytes 20580 (20.0 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 1000 (Local Loopback)
RX packets 562 bytes 48754 (47.6 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 562 bytes 48754 (47.6 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
virbr0: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500
inet 192.168.122.1 netmask 255.255.255.0 broadcast 192.168.122.255
ether 52:54:00:f8:01:4c txqueuelen 1000 (Ethernet)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
[root@MiWiFi-R4CM-srv ~]#
3 centOS7.9配置网卡
centOS7.9网卡文件存放在“/etc/sysconfig/network–scripts”路径下,网卡文件的名字和ip addr看到的网卡名字相同,比如下方就是ifcfg-enp0s3
[root@MiWiFi-R4CM-srv ~]# cd /etc/sysconfig/network-scripts/
[root@MiWiFi-R4CM-srv network-scripts]# pwd
/etc/sysconfig/network-scripts
[root@MiWiFi-R4CM-srv network-scripts]# ls
ifcfg-enp0s3 ifdown-bnep ifdown-ippp ifdown-post ifdown-sit ifdown-tunnel ifup-bnep ifup-ippp ifup-plip ifup-ppp ifup-Team ifup-wireless network-functions-ipv6
ifcfg-lo ifdown-eth ifdown-ipv6 ifdown-ppp ifdown-Team ifup ifup-eth ifup-ipv6 ifup-plusb ifup-routes ifup-TeamPort init.ipv6-global
ifdown ifdown-ib ifdown-isdn ifdown-routes ifdown-TeamPort ifup-aliases ifup-ib ifup-isdn ifup-post ifup-sit ifup-tunnel network-functions
[root@MiWiFi-R4CM-srv network-scripts]#
配置网卡文件
[root@MiWiFi-R4CM-srv network-scripts]# cat ifcfg-enp0s3
TYPE=Ethernet
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=dhcp //此网卡IPv4地址获取方式
DEFROUTE=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=3083c3f2-e316-40b5-aa4c-0381765312c3
DEVICE=enp0s3
ONBOOT=yes //是否引导启用此网卡,yes是启用,no是禁用
[root@MiWiFi-R4CM-srv network-scripts]#
重启网络服务->查看网络DHCP获取IP地址成功->虚拟机访问外网成功
[root@MiWiFi-R4CM-srv network-scripts]# systemctl restart network
[root@MiWiFi-R4CM-srv network-scripts]#
[root@MiWiFi-R4CM-srv network-scripts]# ifconfig enp0s3
enp0s3: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.31.149 netmask 255.255.255.0 broadcast 192.168.31.255
inet6 fe80::a9af:22dd:f375:6dac prefixlen 64 scopeid 0x20<link>
ether 08:00:27:02:d1:be txqueuelen 1000 (Ethernet)
RX packets 3279 bytes 221323 (216.1 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 415 bytes 78092 (76.2 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
[root@MiWiFi-R4CM-srv network-scripts]# ping www.qq.com
PING ins-r23tsuuf.ias.tencent-cloud.net (111.30.185.60) 56(84) bytes of data.
64 bytes from 111.30.185.60 (111.30.185.60): icmp_seq=1 ttl=50 time=16.7 ms
64 bytes from 111.30.185.60 (111.30.185.60): icmp_seq=2 ttl=50 time=16.6 ms
64 bytes from 111.30.185.60 (111.30.185.60): icmp_seq=3 ttl=50 time=16.7 ms
64 bytes from 111.30.185.60 (111.30.185.60): icmp_seq=4 ttl=50 time=17.4 ms
64 bytes from 111.30.185.60 (111.30.185.60): icmp_seq=5 ttl=50 time=18.5 ms
64 bytes from 111.30.185.60 (111.30.185.60): icmp_seq=6 ttl=50 time=17.3 ms
^C
--- ins-r23tsuuf.ias.tencent-cloud.net ping statistics ---
6 packets transmitted, 6 received, 0% packet loss, time 9134ms
rtt min/avg/max/mdev = 16.626/17.258/18.565/0.669 ms
[root@MiWiFi-R4CM-srv network-scripts]#
原文地址:https://blog.csdn.net/rfc2544/article/details/131340513
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。
如若转载,请注明出处:http://www.7code.cn/show_18865.html
如若内容造成侵权/违法违规/事实不符,请联系代码007邮箱:suwngjj01@126.com进行投诉反馈,一经查实,立即删除!
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。