这里写自定义目录标题
- 虚拟机无网络测试
- 解决方案
- 1、设置VM(关闭虚拟机)
- 2、查看当前IP、网关、子网掩码
- 3、设置虚拟机IP、网卡、子网掩码
虚拟机无网络测试
CentOS使用yum下载gcc时报错:cannot find a valid baseurl for repo:base/7/x86_64,百度发现是是虚拟机没有连接网络,使用:
ping www.baidu.com
测试后,报错:未知的名称或服务
解决方案
1、设置VM(关闭虚拟机)
(1)点击编辑-虚拟网络编辑器
(2)在默认网卡下,单击更改设置
(3)在默认网卡下,单击还原默认设置
2、查看当前IP、网关、子网掩码
(1)点击编辑-虚拟网络编辑器
(2)选择类型为NAT模式的网卡,单击NAT设置
(3)将子网IP、子网掩码、网关进行记忆
3、设置虚拟机IP、网卡、子网掩码
(1)使用ifconfig查看使用网卡,且查看使用网卡是否有IP、子网掩码(没有网络的话可能没有)
(2)使用“cd /etc/sysconfig/network-scripts/”命令进入到网卡设置目录下
(3)使用“vi cfg-ens33”给网卡添加IP、网卡、子网掩码,修改BOOTPROTO与ONBOOT参数值。
(4)使用“service network restart”或者“systemctl restart network”命令重启网络
(5)使用ifconfig命令查看使用网卡是否有innerIP,若有,表示设置成功。
(6)使用ping www.baidu.com 测试是否连接外网成功。
如下所示:
BOOTPROTO=static
IPADDRESS=192.168.75.1
GATEWAY=192.168.75.2
NETMASK=255.255.255.0
ONBOOT=yes
[wlh@localhost /]$ ifconfig # 查看<UP,BROADCAST,RUNNING,MULTICAST>的网卡
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500inet6 fe80::ef96:6057:3f0e:4cbe prefixlen 64 scopeid 0x20<link>ether 00:0c:29:b7:2e:44 txqueuelen 1000 (Ethernet)RX packets 400 bytes 43934 (42.9 KiB)RX errors 0 dropped 0 overruns 0 frame 0TX packets 112 bytes 13433 (13.1 KiB)TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536inet 127.0.0.1 netmask 255.0.0.0inet6 ::1 prefixlen 128 scopeid 0x10<host>loop txqueuelen 1000 (Local Loopback)RX packets 96 bytes 10560 (10.3 KiB)RX errors 0 dropped 0 overruns 0 frame 0TX packets 96 bytes 10560 (10.3 KiB)TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0virbr0: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500inet 192.168.122.1 netmask 255.255.255.0 broadcast 192.168.122.255ether 52:54:00:0b:90:b5 txqueuelen 1000 (Ethernet)RX packets 0 bytes 0 (0.0 B)RX errors 0 dropped 0 overruns 0 frame 0TX packets 0 bytes 0 (0.0 B)TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0[wlh@localhost /]$ cd /etc/sysconfig/network-scripts/
[wlh@localhost network-scripts]$ ls
ifcfg-ens33 ifdown-ppp ifup-ib ifup-Team
ifcfg-lo ifdown-routes ifup-ippp ifup-TeamPort
ifdown ifdown-sit ifup-ipv6 ifup-tunnel
ifdown-bnep ifdown-Team ifup-isdn ifup-wireless
ifdown-eth ifdown-TeamPort ifup-plip init.ipv6-global
ifdown-ib ifdown-tunnel ifup-plusb network-functions
ifdown-ippp ifup ifup-post network-functions-ipv6
ifdown-ipv6 ifup-aliases ifup-ppp
ifdown-isdn ifup-bnep ifup-routes
ifdown-post ifup-eth ifup-sit
[wlh@localhost network-scripts]$ vi cfg-ens33