
2、初次登陆需要修改密码:

进入首页:

四、CentOS7 防火墙开放指定端口
如果使用浏览器访问 http://ip:apache端口,访问不到,有可能是CentOS 6、CentOS7 防火墙没有开放指定端口当我们在CentOS服务器中装了一些开发环境(如 tomcat、mysql、nginx 等...)时,希望能从外界访问,就需要配置防火墙对指定端口开放。
CentOS 6.5
1.开放指定端口
/sbin/iptables -I INPUT -p tcp --dport 端口号 -j ACCEPT //写入修改
/etc/init.d/iptables save //保存修改
service iptables restart //重启防火墙,修改生效
2.关闭指定端口
/sbin/iptables -I INPUT -p tcp --dport 端口号 -j DROP //写入修改
/etc/init.d/iptables save //保存修改
service iptables restart //重启防火墙,修改生效
3.查看端口状态
/etc/init.d/iptables status
CentOS 7
1.防火墙操作
启动: systemctl start firewalld
查看状态: systemctl status firewalld
停止: systemctl disable firewalld
禁用: systemctl stop firewalld
2.开放指定端口
firewall-cmd --zone=public --add-port=80/tcp --permanent //开放端口
firewall-cmd --reload //重新载入,使其生效
3.关闭指定端口
firewall-cmd --zone=public --remove-port=80/tcp --permanent //关闭端口
firewall-cmd --reload //重新载入,使其生效
4.查看端口状态
firewall-cmd --zone=public --query-port=80/tcp //查看端口状态
CentOS升级到7之后,发现无法使用iptables控制Linuxs的端口,google之后发现Centos 7使用firewalld代替了原来的iptables。下面记录如何使用firewalld开放Linux端口:
查看防火墙状态
systemctl status firewalld
开启防火墙
systemctl start firewalld
关闭防火墙
systemctl stop firewalld
查看当前firewall状态
firewall-cmd --state
重启firewall
firewall-cmd --reload
禁止开机启动
systemctl disable firewalld.service
开启端口
查看已经开放的端口:
firewall-cmd --list-ports
开启端口
firewall-cmd --zone=public --add-port=80/tcp --permanent
命令含义:
--zone #作用域
--add-port=80/tcp #添加端口,格式为:端口/通讯协议
--permanent #永久生效,没有此参数重启后失效
开启断绝口后需要重启防火墙

测试端口
在开启的端口启动一个服务,如tomcat,我使用的是zookeeper。

在dos中输入
telnet 服务器ip 端口

回车后

表明端口开启成功
本文介绍了在CentOS6和7中如何管理防火墙以开放或关闭指定端口。对于CentOS6,使用iptables命令来添加、删除端口规则并重启服务。而在CentOS7,由于采用了firewalld,需使用firewall-cmd进行端口的开放和关闭,并通过reload命令使更改生效。确保服务可以从外部访问的关键步骤包括检查端口状态和重启防火墙。
810

被折叠的 条评论
为什么被折叠?



