Serious error in my iptables rules?

Kernels & Hardware, configuring network, installing services

Serious error in my iptables rules?

Postby CaptTaifun » 2018-06-30 01:17

Good morning/day/evening to you!

First, our setup:
Rented vServer with Debian Stretch (v9.4)
LXC and LXD (LXD with snap) installed
LXC container (IP: with TeamSpeak 3 server running
LXC container (IP: with running sinusbot (TeamSpeak 3 musicbot)
Network interface (lxdbr0) set up via lxd init

Our TeamSpeak 3 server, which is running in an LXC/LXD container, sometimes drops the connection to all clients on the server.

Further information:
I have set up some rules under iptables, which only lets packets through, defined by me via the incoming and outgoing ports.

What I've discovered so far:
We have a musicbot running in another container which does not connect to the TeamSpeak 3 server over the public IP, but over the local IP (i.e. container (Sinusbot) connects to container (TeamSpeak 3 server)).
So the packets don't get to the firewall, if I understood correctly. Yesterday, 29 June, there was this timeout for a maximum of 2 seconds. The timeout never lasts longer. The server really only drops the connections and allows them again immediately. In the log files of the Sinusbot, however, there is no information that the bot has also been kicked. In fact, I assume that my iptables rules are flawed.

Could someone please take a look and tell me if there's something wrong with it? And first of all: I am a student at an IT school and am more of a software programmer than a network technician. I think I have a basic understanding of what I am doing, but I had to teach myself most of it. So please be merciful if I made one or more big mistakes :P.

Log file for the accepted network packets:

Log file for the dropped network packets:

My iptables rules:
Code: Select all
# -------------- Load Modules --------------
modprobe ip_conntrack_ftp
# -------------- Clear all other rules --------------
iptables -F
iptables -X
iptables -t nat -F
# -------------- Creation of my own chains --------------
iptables -N MYDROP
iptables -N MYACCEPT
# -------------- Loopback communication --------------
iptables -A INPUT -i lo -j ACCEPT
iptables -A OUTPUT -i lo -j ACCEPT
# -------------- Statefull inspection --------------
iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -A OUTPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -A INPUT -m state --state INVALID -j MYDROP
# -------------- Configuring my own chains --------------
iptables -A MYDROP -j LOG --log-prefix "FW-DROP: "
iptables -A MYDROP -j DROP
iptables -A MYACCEPT -j LOG --log-prefix "FW-ACCEPT: "
iptables -A MYACCEPT -j ACCEPT
# -------------- Debian Updates --------------
iptables -A OUTPUT -p tcp --dport 80 -j MYACCEPT
# -------------- SSH --------------
iptables -A INPUT -p tcp --dport xxxxx -j MYACCEPT
# -------------- ICMP Ping --------------
iptables -A INPUT -p icmp -j MYACCEPT
# -------------- DNS --------------
iptables -A INPUT -p udp --dport 53 -j MYACCEPT
iptables -A OUTPUT -p udp --dport 53 -j MYACCEPT
# -------------- LXC --------------
iptables -A FORWARD -d -m conntrack --ctstate RELATED,ESTABLISHED -j MYACCEPT
iptables -A FORWARD -s -j MYACCEPT
iptables -A INPUT -d -s -j MYACCEPT
iptables -A INPUT -d -s -j MYACCEPT
iptables -A INPUT -d -s -j MYACCEPT
iptables -A INPUT -d -s -j MYACCEPT
iptables -t nat -A POSTROUTING -s -j MASQUERADE
# -------------- LXC - Pre-Routing --------------
iptables -t nat -A PREROUTING -i ens3 -p tcp --dport 8087 -j DNAT --to
iptables -t nat -A PREROUTING -i ens3 -p udp --dport 9987 -j DNAT --to
iptables -t nat -A PREROUTING -i ens3 -p tcp --dport 30033 -j DNAT --to
iptables -t nat -A PREROUTING -i ens3 -p tcp --dport 10011 -j DNAT --to
iptables -t nat -A PREROUTING -i ens3 -p tcp --dport 41144 -j DNAT --to
# -------------- LXC - Forwarding --------------
iptables -A FORWARD -p tcp -d --dport 8087 -j MYACCEPT
iptables -A FORWARD -p udp -d --dport 9987 -j MYACCEPT
iptables -A FORWARD -p tcp -d --dport 30033 -j MYACCEPT
iptables -A FORWARD -p tcp -d --dport 10011 -j MYACCEPT
iptables -A FORWARD -p tcp -d --dport 41144 -j MYACCEPT
# -------------- END --------------
iptables -A INPUT -j MYDROP
iptables -A OUTPUT -j MYDROP
iptables -A FORWARD -j MYDROP
exit 0

I am grateful for any help!
Posts: 1
Joined: 2018-06-30 00:42

Return to System configuration

Who is online

Users browsing this forum: No registered users and 20 guests