需要关闭防火墙或者开启对应端口
firewall-cmd --zone=public --add-port=80/tcp --permanent (permanent永久生效,没有此参数重启后失效)
firewall-cmd --permanent --add-rich-rule='rule family="ipv4" source address="192.168.1.1" port protocol="tcp" port="80" accept'
firewall-cmd --permanent --add-rich-rule='rule family="ipv4" source address="192.168.1.1" port protocol="tcp" port="80" reject'
firewall-cmd --permanent --remove-rich-rule='rule family="ipv4" source address="192.168.1.1" port protocol="tcp" port="80" accept'
通过修改配置文件修改防火墙访问策略
开放端口
永久开放2个端口
firewall-cmd --permanent --zone=public --add-port=8080/tcp
firewall-cmd --permanent --zone=public --add-port=80/tcp
firewall-cmd --reload
在 /etc/firewalld/zones 下的 public.xml里:
<?xml version="1.0" encoding="utf-8"?>
<zone>
<short>Public</short>
<description>For use in public areas. You do not trust the other computers on networks to not harm your computer. Only selected incoming connections are accepted.</description>
<service name="ssh"/>
<service name="dhcpv6-client"/>
<port protocol="tcp" port="80"/>
<port protocol="tcp" port="8080"/>
</zone>
限制只能接收来自 10.10.x.x段的IP,开放8000到9000之间的端口。
firewall-cmd --permanent --zone=public --add-rich-rule='rule family="ipv4" source address="10.10.0.0/16" port protocol="tcp" port="8000-9000" accept'
firewall-cmd --reload
再看 /etc/firewalld/zones/public.xml
<?xml version="1.0" encoding="utf-8"?>
<zone>
<short>Public</short>
<description>For use in public areas. You do not trust the other computers on networks to not harm your computer. Only selected incoming connections are accepted.</description>
<service name="ssh"/>
<service name="dhcpv6-client"/>
<port protocol="tcp" port="80"/>
<port protocol="tcp" port="8080"/>
<rule family="ipv4">
<source address="10.10.0.0/16"/>
<port protocol="tcp" port="8000-9000"/>
<accept/>
</rule>
<rule family="ipv4">
<source address="192.168.1.0/24"/>
<port protocol="tcp" port="18000-19000"/>
<accept/>
</rule>
# 单个端口限制
<rule family="ipv4">
<source address="192.168.20.228"/>
<port protocol="tcp" port="18848"/>
<accept/>
</rule>
</zone>
所以,可以直接修改配置文件更改防火墙策略.
# firewall-cmd --list-all
public
target: default
icmp-block-inversion: no
interfaces:
sources:
services: ssh dhcpv6-client
ports: 80/tcp 22/tcp
protocols:
masquerade: no
forward-ports:
source-ports:
icmp-blocks:
rich rules:
rule family="ipv4" source address="10.10.0.0/16" port port="8000-9000" protocol="tcp" accept
启动docker : systemctl start docker
docker使用redis6.0.8镜像创建容器(也叫运行镜像):
docker run -p 6379:6379 --name myr3 --privileged=true -v /app/redis/redis.conf:/etc/redis/redis.conf -v /app/redis/data:/data -d redis:6.0.8 redis-server /etc/redis/redis.conf
说明一下:-v /app/redis/redis.conf:/etc/redis/redis.conf
宿主机器上配置文件/app/redis/redis.conf,映射到容器里/etc/redis/redis.conf,容器使用映射后的配置文件/etc/redis/redis.conf
redis-cli连接上来
redis-cli -a 111111