I have two virtual machines (host machine is on Windows):

  • One DHCP server(on Debian)
  • One Client(on Debian)

The problem is that the client receives an IP address and both machines can ping each other, but the client cannot access internet. (ping never returns)

  • My DHCP server is connected to Internet through "enp0s3" in NAT.
  • My DHCP server is connected in Host-Only through "enp0s9".
  • My Client is connected in Host-Only through "enp0s3".

Am I wrong in the network types that I chose?

ifconfig -a on the DHCP server :

<code>ifconfig -a</code> on the DHCP server

ifconfig -a && ip route show on the client : if config -a && ip route show on the client

/etc/dhcp/dhcpd.conf : dhcpd.conf

I deactivated Windows's firewall and iptables --flush on Debian. In the future I would like to replace the virtual machine client by a real machine plugged in on the Ethernet.

I give my client an IP address, a mask, a gateway. I think it is a gateway problem, but I don't know what to do to get Internet, on the client.

  • 1
    Besides NAT... Is ip forwarding enabled on the server? What is routing table for the server?
    – DevilaN
    Feb 5, 2019 at 22:22

1 Answer 1


You need to enable ip forwarding and use iptables to forward outgoing traffic from enp0s9 to enp0s3



# delete all existing rules.
iptables -F
iptables -t nat -F
iptables -t mangle -F
iptables -X

# Always accept loopback traffic
iptables -A INPUT -i lo -j ACCEPT

# Allow established connections, and those not coming from the outside
iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -A INPUT -m state --state NEW -i ! enp0s3 -j ACCEPT
iptables -A FORWARD -i enp0s3 -o enp0s9 -m state --state ESTABLISHED,RELATED -j ACCEPT

# Allow outgoing connections from the LAN side.
iptables -A FORWARD -i enp0s9 -o enp0s3 -j ACCEPT

# Masquerade.
iptables -t nat -A POSTROUTING -o enp0s3 -j MASQUERADE

# Don't forward from the outside to the inside.
iptables -A FORWARD -i enp0s3 -o enp0s3 -j REJECT

# Enable routing.
echo 1 > /proc/sys/net/ipv4/ip_forward

Source: https://debian-administration.org/article/23/Setting_up_a_simple_Debian_gateway

  • I changed the line iptables -A INPUT -m state --state NEW -i ! enp0s3 -j ACCEPT to iptables -A INPUT -m state --state NEW -i enp0s3 -j ACCEPT (I removed the exclamation mark) That works ! Thanks !
    – Nicolas K.
    Feb 6, 2019 at 7:36

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .