I´m trying to block all traffic using iptables
, but I have some exceptions:
- DNS
- my own server (I'm only using port 80)
- Teamviewer (port 5938)
- port 5555 to allow adb connections
At the moment I have these lines of code, but it is not working as I need:
// Allow my own server - this seems to work
iptables -A INPUT -s 1.1.1.1 -j ACCEPT
iptables -A OUTPUT -d 1.1.1.1 -j ACCEPT
// Allow DNS requests - dont know if it´s correct
iptables -A OUTPUT -p udp --dport 53 -j ACCEPT
iptables -A INPUT -p udp --dport 53 -j ACCEPT
// Allow Teamviewer - same as above - dont know if it´s correct
iptables -A INPUT -p tcp --dport 5938 -j ACCEPT
iptables -A OUTPUT -p tcp --dport 5938 -j ACCEPT
iptables -A OUTPUT -p udp --dport 5938 -j ACCEPT
iptables -A INPUT -p udp --dport 5938 -j ACCEPT
// Allow ADB - same as above - dont know if it´s correct
iptables -A INPUT -p tcp --dport 5555 -j ACCEPT
iptables -A OUTPUT -p tcp --dport 5555 -j ACCEPT
iptables -A OUTPUT -p udp --dport 5555 -j ACCEPT
iptables -A INPUT -p udp --dport 5555 -j ACCEPT
// Block all other requests
iptables -P INPUT DROP
iptables -P OUTPUT DROP
Teamviewer won't connect, nor the name resolution works, adb doesn't connect either. There is something wrong there, don't really know what. Only thing working is the connection to my own server if I hardcode the domain at /etc/hosts
.
Can one of the iptables
gurus here help me out?
iptables -A INPUT -p udp --dport 53 -j ACCEPT
is wrong, it should use--sport
instead of--dport
and that rule should apply to incoming packets from configured DNS nameservers only. But using stateful rules as A.B mentioned would be better (more secure).