0

My /etc/resolv.conf will not be written so DNS resolution is not working.

I'm running Ubuntu Server 16.04.1 LTS in a virtual machine on our office server.

This is my /etc/network/interfaces:

# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).

source /etc/network/interfaces.d/*

# The loopback network interface
auto lo
iface lo inet loopback

# The primary network interface
auto ens3
iface ens3 inet static
        address 192.168.222.104
        netmask 255.255.255.0
        gateway 192.168.222.1
        gateway 192.168.222.1
        dns-nameservers 192.168.222.1 8.8.8.8
        dns-search internal.domain
        post-up iptables-restore < /etc/iptables.up.rules

(/etc/network/interfaces.d is empty)

I've already tried running sudo dpkg-reconfigure resolvconf and sudo ln -sf /run/resolvconf/resolv.conf /etc/resolv.conf as mentioned in this answer. But my /etc/resolv.conf still remains empty:

# Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8)
#     DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN

What else can I try to get DNS resolution back on this server?

NOTE: The same setup works on the other 5 servers which run Ubuntu in other VMs on the same hardware.

They all show a /etc/resolv.conf like

# Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8)
#     DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN
nameserver 192.168.222.1
nameserver 8.8.8.8
search internal.domain

and for those DNS resolution works perfect.

Is there any configuration I'm missing?

Just in case I also added my /etc/iptables.up.rules (which is also more or less the same on all 6 Servers and) which I've set up taking some hints from this guide:

*filter
# Allow all outgoing, but drop incoming and forwarding packets by default
:INPUT DROP [0:0]
:FORWARD DROP [0:0]
:OUTPUT ACCEPT [0:0]

# Custom per-protocol chains
:UDP - [0:0]
:TCP - [0:0]
:ICMP - [0:0]

# Acceptable UDP traffic

# Acceptable TCP traffic
-A TCP -p tcp --dport 22 -j ACCEPT
-A TCP -p tcp --dport 80 -j ACCEPT
-A TCP -p tcp --dport 443 -j ACCEPT
-A TCP -p tcp --dport 10000 -j ACCEPT

# Acceptable ICMP traffic
-A ICMP -p icmp -j ACCEPT

# Boilerplate acceptance policy
-A INPUT -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT
-A INPUT -i lo -j ACCEPT

# Drop invalid packets
-A INPUT -m conntrack --ctstate INVALID -j DROP

# Pass traffic to protocol-specific chains
## Only allow new connections (established and related should already be handled)
## For TCP, additionally only allow new SYN packets since that is the only valid
## method for establishing a new TCP connection
-A INPUT -p udp -m conntrack --ctstate NEW -j UDP
-A INPUT -p tcp --syn -m conntrack --ctstate NEW -j TCP
-A INPUT -p icmp -m conntrack --ctstate NEW -j ICMP

# Reject anything that's fallen through to this point
## Try to be protocol-specific w/ rejection message
-A INPUT -p udp -j REJECT --reject-with icmp-port-unreachable
-A INPUT -p tcp -j REJECT --reject-with tcp-reset
-A INPUT -j REJECT --reject-with icmp-proto-unreachable

# Commit the changes
COMMIT

*raw
:PREROUTING ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
COMMIT

*nat
:PREROUTING ACCEPT [0:0]
:INPUT ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
:POSTROUTING ACCEPT [0:0]
COMMIT

*security
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
COMMIT

*mangle
:PREROUTING ACCEPT [0:0]
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
:POSTROUTING ACCEPT [0:0]
COMMIT
muru
  • 197,895
  • 55
  • 485
  • 740
derHugo
  • 3,356
  • 5
  • 31
  • 51

2 Answers2

4

You can try to update the DNS servers in

/etc/resolvconf/resolv.conf.d/base

then run

sudo resolvconf -u

to regenerate the resolv.conf file.

  • the file /etc/resolvconf/resolv.conf.d/base is empty .. how should it look like? And will this permanently fix the problem? Since it is an office server I can't reconfigure it all the time e.g. after reboots, updates etc. – derHugo Sep 21 '17 at 08:07
  • 2
    @derHugo the file is empty by default. You add lines that should appear in /etc/resolv.conf to it (for example, nameserver 192.168.222.1, or search internal.domain). The file is read by resolvconf whenever it updates, so it should persist across reboots. – muru Sep 21 '17 at 08:08
0

To my knowledge, it is better not to edit resolv.conf, and that is because network manager would update everything you have written by hand, with each restart of the network or reboot. So I would use the nmcli command:

nmcli con mod ens3 +ipv4.dns 192.168.222.1 8.8.8.8
nmcli con up ens3

Network manager is installed by default in most ubuntu based distros, so I assume that would also be the case. Hope this helps!

muru
  • 197,895
  • 55
  • 485
  • 740
S.Ith
  • 518
  • Nice intempt but nmcli and network-manager are not installed since it is Ubuntu-Server without GUI. – derHugo Sep 21 '17 at 08:33