Simple configuration of CentOS 7 docker firewall


Disable firewalld service

systemctl disable firewalld
systemctl stop firewalld

Install iptables firewall service

yum install iptables-services

Create iptables configuration script

cat >> /usr/local/bin/ <<'EOF'

iptables -F
iptables -X
iptables -Z
iptables -P INPUT DROP
iptables -A INPUT -i lo -j ACCEPT
iptables -A INPUT -i eth0 -m state --state RELATED,ESTABLISHED -j ACCEPT
iptables -A INPUT -i eth0 -p icmp --icmp-type 8 -j ACCEPT
#iptables -A INPUT -p tcp --dport 80 -i eth0 -m state -state NEW -m recent -update -seconds 60  -hitcount 50 -j DROP
#iptables -A OUTPUT -o eth0 -m owner -uid-owner vivek -p tcp --dport 80 -m state -state NEW,ESTABLISHED  -j ACCEPT
iptables -A INPUT -i eth0 -p tcp --sport 1:1023 --dport 1:1023 --syn -j DROP
iptables -A INPUT -p tcp -i eth0 --dport 22     --sport 1024:65534 -j ACCEPT
iptables -A INPUT -p tcp --dport 80     --sport 1024:65534 -j ACCEPT
iptables -A INPUT -p tcp --dport 2376   --sport 1024:65534 -j ACCEPT
iptables -A INPUT -p tcp --dport 3306   --sport 1024:65534 -j ACCEPT

# OpenVPN Configuration
# iptables -A POSTROUTING -t nat -s -o eth0 -j MASQUERADE
# iptables -A FORWARD -i tun+ -j ACCEPT
# iptables -A INPUT -s -j ACCEPT
# iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
# iptables -A INPUT -p TCP -i eth0 --dport 10173 --sport 1024:65534 -j ACCEPT
# iptables -A INPUT -p UDP -i eth0 --dport 10173 --sport 1024:65534 -j ACCEPT

chmod +x /usr/local/bin/

Add boot entry

cat >> /etc/rc.d/rc.local <<EOF

# Firewall & Docker
/usr/bin/systemctl start iptables.service
/usr/bin/systemctl start docker

chmod +x /etc/rc.d/rc.local

Disable self starting of related services

#Note: when docker is started, it will automatically add some

systemctl disable iptables.service
systemctl disable docker

Recommended Today

Java Engineer Interview Questions

The content covers: Java, mybatis, zookeeper, Dubbo, elasticsearch, memcached, redis, mysql, spring, spring boot, springcloud, rabbitmq, Kafka, Linux, etcMybatis interview questions1. What is mybatis?1. Mybatis is a semi ORM (object relational mapping) framework. It encapsulates JDBC internally. During development, you only need to pay attention to the SQL statement itself, and you don’t need to […]