I am making a script with iptables on the firewall machine and when executing it and I want to ping a web page I get an error: ping: www.facebook.com: Temprary failed to name resolution and this happens when I run the script, when I restart everything goes perfectly without any problem, I also tried resolv.conf and it doesn't work.
PS: There are two interfaces enp0s3 that goes to the internet and another one enp0s8 that is from an Internal LAN
I pass you the script
sudo iptables -F
sudo iptables -X
sudo iptables -Z
sudo iptables -t nat -F
sudo iptables -P INPUT DROP
sudo iptables -P OUTPUT DROP
sudo iptables -P FORWARD DROP
sudo iptables -t nat -A PREROUTING -i enp0s3 -p tcp --dport 80 -j DNAT --to-destination 172.16.30.10:80
sudo iptables -t nat -A PREROUTING -i enp0s3 -p tcp --dport 443 -j DNAT --to-destination 172.16.30.10:443
sudo iptables -t nat -A PREROUTING -i enp0s3 -p tcp --dport 22 -j DNAT --to-destination 172.16.30.11:22
sudo iptables -t nat -A POSTROUTING -s 172.16.30.0/24 -o enp0s3 -j MASQUERADE
sudo iptables -A FORWARD -i enp0s3 -o enp0s8 -p tcp --dport 22 -d 172.16.30.11 -j ACCEPT
sudo iptables -A FORWARD -i enp0s8 -o enp0s3 -m state --state ESTABLISHED, RELATED -j ACCEPT
sudo iptables -A FORWARD -o enp0s3 -i enp0s8 -s 172.16.30.0/24 -p icmp -j ACCEPT
sudo iptables -A FORWARD -i enp0s3 -o enp0s8 -s 172.16.30.0/24 -p icmp -j ACCEPT
sudo iptables -A FORWARD -i enp0s8 -o enp0s3 -s 172.16.30.0/24 -p udp --dport 53 -j ACCEPT
sudo iptables -A FORWARD -o enp0s8 -i enp0s3 -d 172.16.30.0/24 -p udp --dport 53 -j ACCEPT
sudo iptables -A FORWARD -i enp0s8 -o enp0s3 -s 172.16.30.0/24 -p tcp --dport 80 -j ACCEPT
sudo iptables -A FORWARD -o enp0s8 -i enp0s3 -s 172.16.30.0/24 -p tcp --dport 80 -j ACCEPT
sudo iptables -A FORWARD -i enp0s8 -o enp0s3 -s 172.16.30.0/24 -p tcp --dport 443 -j ACCEPT
sudo iptables -A FORWARD -o enp0s8 -i enp0s3 -s 172.16.30.0/24 -p tcp --dport 443 -j ACCEPT
sudo iptables -A INPUT -d 172.16.30.1 -p icmp -j DROP
sudo iptables -A OUTPUT -o enp0s3 -p icmp -j ACCEPT
sudo iptables -A INPUT -i enp0s3 -p icmp -j ACCEPT
sudo iptables -A OUTPUT -o enp0s8 -p icmp -j ACCEPT
sudo iptables -A INPUT -i enp0s8 -p icmp -j ACCEPT
ACCEPT all -- anywhere anywhere ctstate RELATED,ESTABLISHED
. This allows traffic back in from sessions originating from your machine -- including DNS replies which currently would be dropped even if you did allow it out.iptables -A <chain>
. To insert a rule before position 10,iptables -I <chain> 10
. See the manual page.