I would like to allow incoming and outgoing connections when I'm connected to a wired connection, but drop it otherwise. I noticed that ufw can't block outgoing traffic because of will I give iptables a try. I'm unsure if dropping packages that are outgoing will work, the rule after the block rule will allow all outgoing connections.
This what the rules are intended to do, unsure if that is actually the case.
Allow all loopback traffic.
Allow ping replys
Allow incoming on port 12345 if eth0, deny otherwise.
Allow outgoing on port 12346 if eth0, deny otherwise.
Code:
iptables -A FORWARD -j DROP
iptables -A INPUT -i lo -j ACCEPT
iptables -A INPUT -p icmp --icmp-type 0 -s -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -A INPUT -i eth0 -p tcp --dport 12345 -m state --state NEW,ESTABLISHED -j ACCEPT
iptables -A INPUT --dport 12345 -j DROP
iptables -A INPUT -m state --state ESTABLISHED -j ACCEPT
iptables -A INPUT -j DROP
iptables -A OUTPUT -o lo -j ACCEPT
iptables -A OUTPUT -o eth0 -p tcp --sport 12346 -m state --state NEW,ESTABLISHED -j ACCEPT
iptables -A OUTPUT --sport 12346 -j DROP
iptables -A OUTPUT -j ACCEPT
Bookmarks