欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

CentOS 7关闭firewalld【影响docker部署访问】则启用iptables

程序员文章站 2022-05-28 12:34:47
...

CentOS7有很多CentOS 6中的常用服务发生了变化。首当其冲 防火墙iptables被firewalld取代。这里有个最大的问题是,firewalld 放行端口后 服务任然不能外网访问,因为要添加端口对应的服务到firewalld中,那么docker容器中的各个映射访问的端口就没法玩,docker容器映射出的端口 服务如何添加?非docker安装,如ftp,那么放行ftp端口后还须:

firewall-cmd --add-service=ftp // 即时放行了对应端口,无此步任无法访问,除非禁用 firewall

重新载入

firewall-cmd --reload // 方可生效,ftp 客户端才能使用

由此 采用systemctl关闭firewalld,开启iptables。

1.关闭firewalld

[[email protected]~]# systemctl stop firewalld
[[email protected]~]# systemctl disable firewalld
[[email protected]~]# systemctl status firewalld
firewalld.service - firewalld - dynamic firewall daemon

Loaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled)

Active: inactive (dead)
....

2.开启iptables

首先安装iptables:

[[email protected]~]#yum install -y iptables-services
[[email protected]~]# systemctl enable iptablesln -s '/usr/lib/systemd/system/iptables.service' '/etc/systemd/system/basic.target.wants/iptables.service'

[[email protected]~]# systemctl start iptables
[[email protected]~]# systemctl status iptables
iptables.service - IPv4 firewall with iptables

Loaded: loaded (/usr/lib/systemd/system/iptables.service; enabled)

Active: active (exited) since Fri 2016-02-26 13:54:45 UTC; 6s ago

Process: 55539 ExecStart=/usr/libexec/iptables/iptables.init start (code=exited, status=0/SUCCESS)

Main PID: 55539 (code=exited, status=0/SUCCESS)

Feb 26 13:54:45 hwcentos70-01 iptables.init[55539]: iptables: Applying firewall rules: [ OK ]

Feb 26 13:54:45 hwcentos70-01 systemd[1]: Started IPv4 firewall with iptables.

此时iptables的命令都可以使用了:

[[email protected]~]# iptables -L
Chain INPUT (policy ACCEPT)

target prot opt source destination

Chain FORWARD (policy ACCEPT)

target prot opt source destination

Chain OUTPUT (policy ACCEPT)

target prot opt source destination

[[email protected]~]# service iptables save
iptables: Saving firewall rules to /etc/sysconfig/iptables:[ OK ]
相关标签: iptables