DHCP Not Sharing Internet Access – Troubleshooting Guide

centosdhcpdhcp-serverUbuntuvmware-esxi

I have several Virtual Machines in Vmware ESXi 6.5 with 2 Network Groups.
Created a DHCP Server Machine on CentOs with 2 networks interface.

1 / vm network from which it takes a network and has IP assigned.
2 / to the internet network in which all the machines that have the Internet will be
– the machine gets internet on interface 1 and it works properly. I can ping 8.8.8.8 etc.
– a simple DHCP is configured in /etc/dhcp/dhcpd.conf file and it serves correctly addresses of machines in the "Internet" network
– machines in the Internet subnet that got DHCP addresses can ping each other and have no conflicts at all

On DHCP Machine (CentOS) I created a another profile network ens192 with IP
192.168.0.1, mask 255.255.255.0, no default gateway.

In file dhcpd.conf (ofcourse there is option domain-name)

subnet 192.168.0.0 netmask 255.255.255.0 {
option routers                  192.168.0.1; //same as ens192
option subnet-mask              255.255.255.0;
#option routers                 192.168.0.254 //tried with .254 gw
range   192.168.0.10   192.168.0.200;
}

From DHCP Machine I can ping to 8.8.8.8 and to another machines that got a DHCP addresses assigned by DHCP server.

Now lets check one machine with assigned DHCP. Its Ubuntu machine.
Assigned address: 192.168.0.46.
I can ping each machine, including 192.168.0.1 but cannot 8.8.8.8.

Im not sure whats wrong.


Edit:

In the meantime, I changed the DHCP server configuration to 192.168.1.1 and range on 192.168.1.10-.200

Ubuntu machine:
ip addr show
inet 192.168.1.10/24 brd 192.168.1.255 scope global dynamic ens160

ip route
default via 192.168.1.1 dev ens160 proto static metric 100
192.168.1.0/24 dev ens160 proto kernel scope link src 192.168.1.10 metric 100

CentOS 7.3 DHCP machine:
So all looks line in your post.

I enabled routing by
sysctl -w net.ipv4.ip_forward=1, added it to sysctl.d/ip_forward.conf by
echo "net.ipv4.ip_forward=1" >> /etc/sysctl.d/ip_forward.conf
Should I restart some service at the moment?
Enabled firewalld:
firewall-cmd --permanent --direct --passthrough ipv4 -t nat -I POSTROUTING -o ens192 -j MASQUERADE -s 192.168.1.0/24
success
firewall-cmd --reload

Reboot on Ubuntu machine, and ping 8.8.8.8: still nothing:
15 packets transmitted, 0 received, 100% packet loss

I thought configuring IP Forward and running NAT would solve the problem… Any more ideas? Thank you

Best Answer

To check if your DHCP configuration is good, you can check your ip settings with:

ip addr show

This will show the current configured ip address on the client machine interface, which from your example shows working - 192.168.0.46

next you can check on the client machine weather the default gateway is set properly:

ip route

This should show something like this:

default via 192.168.0.1 dev eth0
192.168.0.0/24 dev eth0 proto kernel scope link src 192.168.0.46

the first line indicating the default gateway, if this is set to 192.168.0.1 your golden in terms of DHCP config.

The last thing you need to check. Do you have routing enabled on the CentOS machine? In order to have internet access from your ubuntu machine, the CentOS needs to be configured as a router, or you need to have another router on the 192.168.0.x network.

quick n dirty - on the CentOS machine: Enable routing:

sysctl -w net.ipv4.ip_forward=1

to make persistent across reboots edit /etc/sysctl.conf and add:

net.ipv4.ip_forward = 1

to masquerade (NAT) 192.168.0.0/24 for the 'outside' network:

Enable firewalld:

systemctl start firewalld
firewall-cmd –permanent –direct –passthrough ipv4 -t nat -I POSTROUTING -o *** -j MASQUERADE -s 192.168.0.0/24
systemctl restart firewalld

*** above should be your 'outside' interface on the CentOS machine.