Ubuntu-Server 24.04.3 LTS iptables DNS not working

Ubuntu-Server 24.04.3 LTS

Problem Description:

I'm replacing my 10 year old CentOS system with Ubuntu-Server 24.04.3 LTS. The CentOS is running IP tables and I have always been able to add and delete rules as needed. I have never used Ubuntu but now I am trying it since CentOS is no longer available.

I bought a Beelink EQ14 with 2 Ethernet ports to use as my new firewall server. I have successfully installed Ubuntu and have the two Ehernet cards working. However, I have spent 2 days trying to solve what I believe to be a DNS issue. The systemd-resolved service seems to be working properly and it retrieves my ISP DNS server IP addresses. However, no client on the LAN has internet access.

The DHCP server is running properly and gives out IP addresses to the LAN clients. If I configure the network card on my PC to use DHCP for the IP address and manually add DNS servers 8.8.8.8 and 8.8.4.4, I am able to access the internet.

Relevant System Information:

The Ubuntu system i configured with 2 Ethernet cards. The ISP facing card is configured to obtain its IP address via DHCP, and does so. The LAN card is configured with a static IP address of 172.16.1.1. I can access the Ubuntu server from my desktop using Putty.

I tried to use my firewall rules from the CentOS box with no luck. So I have created a very simple iptables ruleset that should work. I have turned UFW and nftables off and disabled them. I have set net.ipv4.ip_forward = 1 and it is persistent across reboots.

The IP tables and Netplan 01-netcfg.yaml settings are shown below.

flush and initialize tables

iptables -F
iptables -t nat -F
iptables --delete-chain
iptables -t nat --delete-chain

Allow all to start with

iptables --policy INPUT ACCEPT
iptables --policy OUTPUT ACCEPT
iptables --policy FORWARD ACCEPT

iptables -t nat -A POSTROUTING -o enp1s0 -j MASQUERADE
iptables -A FORWARD -i enp2s0 -o enp1s0 -j ACCEPT
iptables -A FORWARD -i enp1s0 -o enp2s0 -m state --state RELATED,ESTABLISHED -j ACCEPT```

Netplan 01-netcfg.yaml

  version: 2
  renderer: networkd
  ethernets:
    enp1s0:
      dhcp4: true
    enp2s0:
      dhcp4: no
      optional: true
      link-local: []
      addresses:
        - 172.16.1.1/24```

At least to me, it is not obvious what is wrong. Could you give us the outputs from sudo iptables -xvnL and sudo iptables -t nat -xvnL.

Yes, UFW should be off and disabled, but the iptables syntax should be interpreted and executed by nftables so it is not clear that it should be disabled.

The links for iptables should look something like this:

doug@s19:~/iptables/misc$ which iptables
/usr/sbin/iptables
doug@s19:~/iptables/misc$ ls -l /usr/sbin/iptables
lrwxrwxrwx 1 root root 26 Apr 23  2024 /usr/sbin/iptables -> /etc/alternatives/iptables
doug@s19:~/iptables/misc$ ls -l /etc/alternatives/iptables
lrwxrwxrwx 1 root root 22 Apr 23  2024 /etc/alternatives/iptables -> /usr/sbin/iptables-nft
doug@s19:~/iptables/misc$ ls -l /usr/sbin/iptables-nft
lrwxrwxrwx 1 root root 17 Apr 23  2024 /usr/sbin/iptables-nft -> xtables-nft-multi
doug@s19:~/iptables/misc$ ls -l /usr/sbin/xtables-nft-multi
-rwxr-xr-x 1 root root 224424 Apr 23  2024 /usr/sbin/xtables-nft-multi
1 Like

I ran the commands. Results are shown here.

Chain INPUT (policy ACCEPT 17 packets, 1203 bytes)
    pkts      bytes target     prot opt in     out     source               destination

Chain FORWARD (policy ACCEPT 0 packets, 0 bytes)
    pkts      bytes target     prot opt in     out     source               destination
       1      451 ACCEPT     0    --  enp2s0 enp1s0  0.0.0.0/0            0.0.0.0/0
       1      476 ACCEPT     0    --  enp1s0 enp2s0  0.0.0.0/0            0.0.0.0/0            state RELATED,ESTABLISHED

Chain OUTPUT (policy ACCEPT 10 packets, 1217 bytes)
    pkts      bytes target     prot opt in     out     source               destination
root@atc-firewall:~#


root@atc-firewall:~# iptables -t nat -xvnL
Chain PREROUTING (policy ACCEPT 0 packets, 0 bytes)
    pkts      bytes target     prot opt in     out     source               destination

Chain INPUT (policy ACCEPT 0 packets, 0 bytes)
    pkts      bytes target     prot opt in     out     source               destination

Chain OUTPUT (policy ACCEPT 0 packets, 0 bytes)
    pkts      bytes target     prot opt in     out     source               destination

Chain POSTROUTING (policy ACCEPT 0 packets, 0 bytes)
    pkts      bytes target     prot opt in     out     source               destination
       6      392 MASQUERADE  0    --  *      enp1s0  0.0.0.0/0            0.0.0.0/0
root@atc-firewall:~#

Based on the packet counters, it seems to be working.
I don’t understand why the protocol (prot) column is listing “0”, as I think “all” is expected.

To better understand what is going on I would add logging to the iptables rule set and/or monitor the packets with tcpdump (or wireshark, if you prefer).

For tcpdump: In one terminal:

sudo tcpdump -n -tttt -i enp1s0

and in another terminal:

sudo tcpdump -n -tttt -i enp2s0

You mention using PuTTY to access the Ubuntu server, so to avoid an infinite spew of SSH packets the second tcpdump command might need to be:

sudo tcpdump -n -tttt -i enp2s0 not port 22

I activated logging for iptables. I see this when I try to access a website. It doesn’t matter if I have 8.8.8.8 manually entered so I can access the site or if I have no DNS and am unable to access anything, I get the same results in the log.

2025-08-14T01:11:08.534665+00:00 atc-firewall kernel: FIERWALL_DNS: IN=enp2s0 OUT= MAC=ff:ff:ff:ff:ff:ff:30:5a:3a:03:8b:a7:08:00 SRC=172.16.1.114 DST=255.255.255.255 LEN=68 TOS=0x00 PREC=0x00 TTL=128 ID=33034 PROTO=UDP SPT=49669 DPT=1947 LEN=48

2025-08-14T01:11:09.078789+00:00 atc-firewall kernel: FIERWALL_DNS: IN=enp1s0 OUT= MAC=ff:ff:ff:ff:ff:ff:98:a2:c0:71:28:19:08:00 SRC=10.54.0.1 DST=255.255.255.255 LEN=365 TOS=0x00 PREC=0x00 TTL=255 ID=36360 PROTO=UDP SPT=67 DPT=68 LEN=345```

The firewall is passing traffic. I had my brother use SSH to access my server and he was able to connect and log in. So apparently the issue is totally related to DNS. It makes no sense as to why it is not working.

These are the current firewall rules I have in place.

Chain INPUT (policy ACCEPT 788 packets, 91234 bytes)
    pkts      bytes target     prot opt in     out     source               destination
       0        0 ACCEPT     17   --  *      *       0.0.0.0/0            0.0.0.0/0            udp dpt:123
       4      622 ACCEPT     17   --  enp1s0 *       0.0.0.0/0            0.0.0.0/0            udp spt:53 dpts:1024:65535
      18     1251 LOG        17   --  *      *       0.0.0.0/0            0.0.0.0/0            udp dpt:53 LOG flags 0 level 4
      18     1251 LOG        17   --  *      *       0.0.0.0/0            0.0.0.0/0            udp dpt:53 LOG flags 0 level 6
     196    53972 LOG        17   --  *      *       0.0.0.0/0            0.0.0.0/0            LOG flags 0 level 4 prefix "FIERWALL_DNS: "

Chain FORWARD (policy ACCEPT 0 packets, 0 bytes)
    pkts      bytes target     prot opt in     out     source               destination
    3422  1045846 ACCEPT     0    --  enp2s0 enp1s0  0.0.0.0/0            0.0.0.0/0
    4074  3178894 ACCEPT     0    --  enp1s0 enp2s0  0.0.0.0/0            0.0.0.0/0            state RELATED,ESTABLISHED

Chain OUTPUT (policy ACCEPT 746 packets, 650158 bytes)
    pkts      bytes target     prot opt in     out     source               destination
       0        0 ACCEPT     17   --  *      *       0.0.0.0/0            0.0.0.0/0            udp dpt:123
       4      298 ACCEPT     17   --  *      enp1s0  0.0.0.0/0            0.0.0.0/0            udp spts:1024:65535 dpt:53

I have noticed one difference between the CentOS box and the Ubuntu box. From the command line on my Windows PC, when I issue an ipconfig /all command, I see this.
Default Gateway . . . . . . . . . : 172.16.1.1
DHCP Server . . . . . . . . . . . : 172.16.1.1
DNS Servers . . . . . . . . . . . : 172.16.1.1

The same command on the Ubuntu box only shows the Default Gateway and the DHCP Server. No DNS server is referenced.

I have those 3 lines filled out properly on my windows computers also:

   Default Gateway . . . . . . . . . : 192.168.111.1
   DHCP Server . . . . . . . . . . . : 192.168.111.1
   DNS Servers . . . . . . . . . . . : 192.168.111.1

And the DNS server address is as specified in my DHCP server configuration file, /etc/dhcp/dhcpd.conf:

option domain-name-servers 192.168.111.1;

And I do have a DNS server running at 192.168.111.1, but if I didn’t the line might be whatever I decide to use or whatever my ISP said to use, for example:

option domain-name-servers 75.154.133.68, 75.154.133.100;

I’ve no experience with this at all, but do you maybe need a “nameservers:” entry in your yaml file, possibly for enp2s0 only?

https://netplan.readthedocs.io/en/stable/examples/#how-to-configure-dns-servers-and-search-domains

OK, I am making some progress but not there yet.
I added
option domain-name-servers 172.16.1.1;
to my dhcpd.conf file in /etc/dhcp directory and then an ipconfig /all command shows the DNS Servers as 172.16.1.1. However, I still had no access to the internet.

I then changed option domain-name-servers to 172.16.1.1, 8.8.8.8, 8.8.4.4. That then gives the LAN side clients access to the internet. But it shouldn’t need to be setup that way.

The rules I have setup in IPTABLES should know to pass DNS requests to the ISP interface enp2s0. I need to figure that one out.

The dns server appears to be running on my Ubuntu box according to this:

Global
         Protocols: -LLMNR -mDNS -DNSOverTLS DNSSEC=no/unsupported
  resolv.conf mode: stub
Current DNS Server: 172.16.1.1
       DNS Servers: 172.16.1.1

Link 2 (enp1s0)
    Current Scopes: DNS
         Protocols: +DefaultRoute -LLMNR -mDNS -DNSOverTLS DNSSEC=no/unsupported
Current DNS Server: 68.105.28.11
       DNS Servers: 68.105.28.11 68.105.29.11 68.105.28.12 2001:578:3f::30 2001:578:3f:1::30

Link 3 (enp2s0)
    Current Scopes: none
         Protocols: -DefaultRoute -LLMNR -mDNS -DNSOverTLS DNSSEC=no/unsupported
root@atc-firewall:/usr/share/ufw/iptables#

The 68.105 addresses are the ISP providers DNS servers.

It sounds as though you do not actually have a DNS server running on 172.16.1.1.

And while your IPTABLES rules would forward DNS requests, they have to have a valid destination. If your are not running a local DNS server, then the DNS addresses would need to be supplied as part of your DHCP issued IP address lease.

The DNS server is running.

â—Ź isc-dhcp-server.service - ISC DHCP IPv4 server
     Loaded: loaded (/usr/lib/systemd/system/isc-dhcp-server.service; enabled; preset: enabled)
     Active: active (running) since Fri 2025-08-15 01:06:21 UTC; 39min ago
       Docs: man:dhcpd(8)
   Main PID: 2146 (dhcpd)
      Tasks: 1 (limit: 18819)
     Memory: 3.8M (peak: 4.3M)
        CPU: 29ms
     CGroup: /system.slice/isc-dhcp-server.service
             └─2146 dhcpd -user dhcpd -group dhcpd -f -4 -pf /run/dhcp-server/dhcpd.pid -cf /etc/dhcp/dhcpd.conf enp2s0

Aug 15 01:37:40 atc-firewall dhcpd[2146]: DHCPREQUEST for 172.16.1.119 from 50:67:ae:f0:3e:c0 (SPA112) via enp2s0
Aug 15 01:37:40 atc-firewall dhcpd[2146]: DHCPACK on 172.16.1.119 to 50:67:ae:f0:3e:c0 (SPA112) via enp2s0
Aug 15 01:37:41 atc-firewall dhcpd[2146]: DHCPREQUEST for 172.16.1.113 from 60:83:e7:e0:65:5b (ArcherAX21) via enp2s0
Aug 15 01:37:41 atc-firewall dhcpd[2146]: DHCPACK on 172.16.1.113 to 60:83:e7:e0:65:5b (ArcherAX21) via enp2s0
Aug 15 01:41:10 atc-firewall dhcpd[2146]: DHCPREQUEST for 172.16.1.114 from 30:5a:3a:03:8b:a7 (rbuck-Win10) via enp2s0
Aug 15 01:41:10 atc-firewall dhcpd[2146]: DHCPACK on 172.16.1.114 to 30:5a:3a:03:8b:a7 (rbuck-Win10) via enp2s0
Aug 15 01:42:40 atc-firewall dhcpd[2146]: DHCPREQUEST for 172.16.1.119 from 50:67:ae:f0:3e:c0 (SPA112) via enp2s0
Aug 15 01:42:40 atc-firewall dhcpd[2146]: DHCPACK on 172.16.1.119 to 50:67:ae:f0:3e:c0 (SPA112) via enp2s0
Aug 15 01:42:45 atc-firewall dhcpd[2146]: DHCPREQUEST for 172.16.1.113 from 60:83:e7:e0:65:5b (ArcherAX21) via enp2s0
Aug 15 01:42:45 atc-firewall dhcpd[2146]: DHCPACK on 172.16.1.113 to 60:83:e7:e0:65:5b (ArcherAX21) via enp2s0
root@atc-firewall:/#```

Edit: You are probably correct. This shows the DHCP server is running.
I have the DNS server address in the dhcpd.conf file. But when I run
ps -ef |grep dns, nothing returns. Further investigation required.