Linux Firewall

今天没什么事捣腾下redis,从本地Java连接上服务器redis,代码写完了,运行就一直报Connection refused,查了半天原因,最终确定了两点!一个是/etc/redis.conf中bind 了127.0.0.1,注释掉就可以了,另一个就是防火墙了。

防火墙操作

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
[root@iZ94pjjvvshZ nginx]# firewall-cmd --query-port=80/tcp
FirewallD is not running
[root@iZ94pjjvvshZ nginx]# systemctl enable firewalld
Created symlink from /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service to /usr/lib/systemd/system/firewalld.service.
Created symlink from /etc/systemd/system/basic.target.wants/firewalld.service to /usr/lib/systemd/system/firewalld.service.
[root@iZ94pjjvvshZ nginx]# firewall-cmd --query-port=80/tcp
FirewallD is not running
[root@iZ94pjjvvshZ nginx]# systemctl start firewalld
[root@iZ94pjjvvshZ nginx]# systemctl status firewalld
● firewalld.service - firewalld - dynamic firewall daemon
Loaded: loaded (/usr/lib/systemd/system/firewalld.service; enabled; vendor preset: enabled)
Active: active (running) since 四 2016-12-29 16:44:19 CST; 6s ago
Main PID: 17075 (firewalld)
CGroup: /system.slice/firewalld.service
└─17075 /usr/bin/python -Es /usr/sbin/firewalld --nofork --nopid
1229 16:44:19 iZ94pjjvvshZ systemd[1]: Starting firewalld - dynamic firewall daemon...
1229 16:44:19 iZ94pjjvvshZ systemd[1]: Started firewalld - dynamic firewall daemon.
[root@iZ94pjjvvshZ nginx]# firewall-cmd --query-port=80/tcp
no
[root@iZ94pjjvvshZ nginx]# firewall-cmd --add-port=80/tcp
success
[root@iZ94pjjvvshZ nginx]# firewall-cmd --query-port=80/tcp
yes

简要描述

1
2
3
4
5
6
7
8
9
10
# 查询tcp的80端口是否被开启
firewall-cmd --query-port=80/tcp
# enable防火墙
systemctl enable firewalld
# 启动防火墙
systemctl start firewalld
# 查询防火墙的状态
systemctl status firewalld
# 开启tcp的80端口
firewall-cmd --add-port=80/tcp

刚才试验的时候开了防火墙,个人博客都访问不了了(443端口),算了,没什么事还是不要开防火墙了,否则还要一个个的add port,又没人攻击我!哈哈哈…..

更详细介绍请参看:http://www.cnblogs.com/moxiaoan/p/5683743.html

我知道是不会有人点的,但万一有人想不开呢!