CentOS 7 Docker Firewall Simple Configuration


Disabling firewalld services

systemctl disable firewalld
systemctl stop firewalld

Install iptables firewall service

yum install iptables-services

Create iptables configuration scripts

cat >> /usr/local/bin/fired.sh <<'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/fired.sh

Add boot start item

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-startup of related services

# Note: Docker will automatically add some when it starts

systemctl disable iptables.service
systemctl disable docker

Recommended Today

Java atomicinteger class using

A counter For ordinary variables, when multithreading operations are involved, classic thread safety problems will be encountered. Consider the following code: private static final int TEST_THREAD_COUNT = 100; private static int counter = 0; public static void main(String[] args) { final CountDownLatch latch = new CountDownLatch(TEST_THREAD_COUNT); Thread[] threads = new Thread[TEST_THREAD_COUNT]; for (int i = […]