Getting Connected: Fixing No Internet Access for CentOS VMs

As a seasoned IT pro, nothing is quite as frustrating as spinning up a shiny new CentOS virtual machine (VM), only to find you have no internet connectivity and limited troubleshooting info.

In this detailed guide, I‘ll walk you through everything I‘ve learned over the years for diagnosing and restoring that vital network access that we so desperately rely on.

An Overview of the Problem and Solutions

At a high level, loss of internet connectivity simply means packets are unable to traverse the various network layers between your CentOS VM and destinations on the wider network.

Our job is to validate connectivity and configuration at each layer, identify the choke point, and take steps to remediate.

Common culprits include:

  • Misconfigured network adapters in VMware
  • Failed or missing IP assignments
  • Incorrect network parameters/firewall rules
  • Intercompatibility issues between VMware tools and CentOS

Getting connectivity established again can typically be achieved through:

  • Reconfiguring the VMXNET3 adapter
  • Running dhclient to request a new IP address
  • Assigning a static IP configuration
  • Adjusting firewall rules and routes

Be sure to also check for issues on the VMware host, virtual switch, and external networks that could be blocking traffic.

Now let‘s dive into the details…

A Structured Troubleshooting Approach

As networking professionals, we have standard models like OSI and TCP/IP to guide our troubleshooting methodology. We‘ll follow this layered approach to validate connectivity and configuration at each step:

Layer 1/2 – Physical and Data Link

Verify the NIC works and can communicate on the local network segment.

Layer 3 – Network

Validate IP connectivity and routing across the subnet.

Layer 3/4 – Transport

Confirm DNS resolution and end-to-end connections.

Application Access

Finally test actual application usage.

Let‘s map out some quick commands to check each layer…

Layer 1/2:

ifconfig 
ethtool eth0
vmkping 
tcpdump

Layer 3:

ip addr  
ping default gateway
traceroute
arp tables

Layer 3/4:

dig website.com
telnet website.com 80
nmap troublehost

Application Access:

curl -I website.com
wget testfile
ssh user@server

If failure occurs at a layer, investigate that interface and configs. Now let‘s explore common issues and remediation steps…

VM Network Adapter Not Initialized

The virtual network adapter acts as our layer 1 interface to VMware vSphere networking. If it fails to initialize during boot or gets disconnected, we lose all connectivity.

Confirm Adapter Enabled and Connected

  1. Shut down the VM
  2. Edit settings, ensure VMXNET3 adapter enabled
  3. Verify attached and connected to correct Port Group
  4. Restart VM, check ifconfig for adapter

Manually Bring Up/Renew DHCP

$ ifdown eth0; ifup eth0
$ dhclient -v eth0

Modify Adapter Driver and Firmware

Try the VMXNET2 driver, update Tools, enable spoofing.

Failed DHCP and Lost IP Connectivity

Next, let‘s validate IP connectivity and assignment. Without proper layer 3 parameters, we cannot communicate past the local network.

Attempt DHCP Renewal

$ nmcli con down eth0; nmcli con up eth0
$ dhclient -r; dhclient

Assign Static IP

Bypass DHCP and configure static IP addressing. Don‘t forget gateway, dns, netmask.

Check Host Networking

Investigate VMware host NICs, vSwitches, port groups for issues that could prevent DHCP and connectivity to subnets.

Modify Firewall Rules

Confirm VM, host, network, and security group firewalls allow DHCP traffic on UDP 67/68.

Name Resolution and End-to-End Failures

Alright, we have layer 3 connectivity but still can‘t reach public sites and services. Time to verify DNS, routing/transport protocols.

Diagnose DNS and Routing

Use dig, nslookup, traceroute to validate DNS queries and traffic routing as expected.

TCPDUMP and Logs

Inspect traffic dumps and VMkernel logs more closely to analyze traffic flow.

Isolate Transport Issues

Utilize nmap, telnet, netcat to test basic TCP/IP connectivity and port access.

Adjust Firewalls and Network Security

Tighten down firewalls and security groups while ensuring needed access remains.

Inspect Application Logs

App, web server, database logs may reveal additional details on access issues.

Maximizing Uptime and Availability

Once connectivity is restored, implement some best practices to prevent issues proactively:

  • Script dhclient IP renewals on startup
  • Leverage NetworkManager connection monitoring
  • Configure static IPs outside DHCP pools
  • Implement secondary DNS
  • Allow ICMP ping in firewalls for better monitoring
  • Validate VM mobility across hosts/vSwitches

Proper logging and metrics are key as well for performance management.

We Have Contact!

Hopefully by now you‘ve managed to get your CentOS VM talking to the network again! ☺️ Reach out if you have any other troubleshooting questions.

Thanks for letting me put my 15+ years of network engineering experience to work helping diagnose your connectivity issue step-by-step. That‘s what I love about IT – every problem makes us better troubleshooters!

Let me know if you need any assistance getting your VMs and infrastructure locked down tight with security best practices next. Stay safe out there!