I'm using Ubuntu 18.04 Server and trying to make a router. When I execute the following iptables script (which worked just perfectly on Ubuntu 16.04), the DNS lookup from command line stops working. I have ping to IP addresses, but no DNS names. Something is obviously changed from 16.04, but don't know what.

EDIT: I started executing lines one by one and defined the culprit is this:

iptables -t nat -A POSTROUTING -j MASQUERADE

But still don't know why (it worked on previous Ubuntu versions - 16.04, 14.04, 12.04)

The ping output is:

# ping google.com
ping: google.com: Temporary failure in name resolution

If I reboot WITHOUT this script, it works:

# ping google.com
PING google.com ( 56(84) bytes of data.
64 bytes from sof02s32-in-f14.1e100.net ( icmp_seq=1 ttl=57 time=2.92 ms

OK, I'll answer my own question. The cure was to add an external interface in the iptables line, so it now looks like this:

ExtIF=eno1 ##Change this to the name of your external (Internet) interface    
iptables -t nat -A POSTROUTING -o $ExtIF -j MASQUERADE

Maybe some iptables guru would be able to answer in the comments why the DNS lookup is failing only from localhost, only in Ubuntu 18.04.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.