vmware+CentOS 7 无法上网

Posted on 2018-02-23 20:04  柳泉松声  阅读(199)  评论(0编辑  收藏  举报

vmware显示网络连接没问题。但是centos系统里面不能上网,连ip地址都没有。google了一个解决方法,非常有效!

直接黏贴过来了:

https://geekflare.com/no-internet-connection-from-vmware-with-centos-7/

No Internet Connection from VMware with CentOS 7

New Look. New CentOS!

Yes, that’s what CentOS 7 says.

Anyway, lately, I installed CentOS 7 over VMware and installation were quite smooth. Immediate after installation, I tried to browse some web, and it was failing.

While doing basic troubleshooting, I noticed there were no IP when I did ifconfig

[chandan@localhost ~]$ ifconfig
ens32: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500 
ether 00:0c:29:68:22:e2  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
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 0  (Local Loopback) 
RX packets 642  bytes 55820 (54.5 KiB) 
RX errors 0  dropped 0  overruns 0  frame 0 
TX packets 642  bytes 55820 (54.5 KiB) 
TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
[chandan@localhost ~]$

Are you in the same situation like I was?

In this article, I will talk about how to fix if you don’t get the Internet on VMware with CentOS 7.

That leads me to think either network adaptor is not enabled or failed to obtain DHCP IP address.

Quick Solution 

  1. Access terminal/console
  2. Become a root if you are not already
  3. Execute “dhclient –v” command
  4. You will notice it will bound IP address as shown below
[root@localhost network-scripts]# dhclient -v
Internet Systems Consortium DHCP Client 4.2.5 Copyright 2004-2013
Internet Systems Consortium. All rights reserved. For info, please visit https://www.isc.org/software/dhcp/ Listening on LPF/ens32/00:0c:29:68:22:e2
Sending on   LPF/ens32/00:0c:29:68:22:e2
Sending on   Socket/fallback DHCPDISCOVER on ens32 to 255.255.255.255 port 67 interval 4 (xid=0x433a9e33) DHCPREQUEST on ens32 to 255.255.255.255 port 67 (xid=0x433a9e33)
DHCPOFFER from 172.16.179.254 DHCPACK from 172.16.179.254 (xid=0x433a9e33) bound to 172.16.179.136 -- renewal in 822 seconds.
[root@localhost network-scripts]#

5.     Boom, that’s all, you should have the Internet now. You will also notice IP when you do ifconfig

[root@localhost network-scripts]# ifconfig
ens32: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500 
inet 172.16.179.136  netmask 255.255.255.0  broadcast 172.16.179.255 
ether 00:0c:29:68:22:e2  txqueuelen 1000  (Ethernet) 
RX packets 11  bytes 1255 (1.2 KiB) 
RX errors 0  dropped 0  overruns 0  frame 0 
TX packets 23  bytes 3536 (3.4 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 0  (Local Loopback) 
RX packets 770  bytes 66956 (65.3 KiB) 
RX errors 0  dropped 0  overruns 0  frame 0 
TX packets 770  bytes 66956 (65.3 KiB) 
TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

Add this in auto-startup

You might be interested in putting this in auto-startup, so you don’t have to do this every time you start the CentOS VM.

This is how you can put the script in auto-startup, so it starts automatically after VM is rebooted.

  • Go to /etc/init.d
  • Create a file with following, I have kept the name as “net-autostart
#!/bin/bash
# Solution for "No Internet Connection from VMware"
#
### BEGIN INIT INFO
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
### END INIT INFO
dhclient -v
  • Save the file
  • Change the file permission as executable
chmod 755 net-autostart
  • Add this script for auto-start using chkconfig command
chkconfig --add net-autostart
  • Restart VM to test

I hope this helps. Let me know how it goes with you.

If you want to enhance CentOS 7 administration skills, then you may take this course by Cody Ray Miller.

Copyright © 2024 柳泉松声
Powered by .NET 8.0 on Kubernetes