CentOS 7关闭firewalld启用iptables 开放端口
2024-08-28 21:28:36
在CentOS7中,有很多CentOS 6中的常用服务发生了变化。
其中iptables是其中比较大的一个。防火墙iptables被firewalld取代。
本文将介绍,如果采用systemctl关闭firewalld,开启iptables。
1.关闭firewalld
[root@hwcentos70-01 system]# systemctl stop firewalld
[root@hwcentos70-01 system]# systemctl disable firewalld
[root@hwcentos70-01 system]# systemctl status firewalld
firewalld.service - firewalld - dynamic firewall daemon Loaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled) Active: inactive (dead) Feb 26 13:48:00 hwcentos70-01 systemd[1]: Stopped firewalld - dynamic firewall daemon. Feb 26 13:48:14 hwcentos70-01 systemd[1]: Starting firewalld - dynamic firewall daemon... Feb 26 13:48:15 hwcentos70-01 systemd[1]: Started firewalld - dynamic firewall daemon. Feb 26 13:49:23 hwcentos70-01 systemd[1]: Started firewalld - dynamic firewall daemon. Feb 26 13:53:18 hwcentos70-01 systemd[1]: Stopping firewalld - dynamic firewall daemon... Feb 26 13:53:18 hwcentos70-01 systemd[1]: Stopped firewalld - dynamic firewall daemon.
2.开启iptables
首先安装iptables:
[root@hwcentos70-01 system]#yum install -y iptables-services
[root@hwcentos70-01 system]# systemctl enable iptables
ln -s '/usr/lib/systemd/system/iptables.service' '/etc/systemd/system/basic.target.wants/iptables.service' [root@hwcentos70-01 system]# systemctl start iptables
[root@hwcentos70-01 system]# 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的命令都可以使用了:
[root@hwcentos70-01 system]# 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 [root@hwcentos70-01 system]# service iptables save
iptables: Saving firewall rules to /etc/sysconfig/iptables:[ OK ]
3.开放5000端口
输入“vi /etc/sysconfig/iptables”,打开iptables的配置文件,输入之前按一下"i",然后添加一行"-A INPUT -m state --state NEW -m tcp -p tcp --dport 5000 -j ACCEPT",添加以后按一下ESC,输入":x",回车,就保存退出了
重启iptables,输入"service iptables restart",重启成功以后,,输入"service iptables status",回车,就会显示正在生效的规则
启动监听5000的应用程序
4.测试
cmd(命令提示符)窗口,使用telnet命令进行测试,命令"telnet+空格+服务器IP+空格+5000",可以连接就会直接跳转到一个空白的窗口,连不上就会卡住一段时间,然后提示错误
查看网页
最新文章
- Entity Framework 4 数据事务操作
- xcode使用
- DI 之 3.1 DI的配置使用(肆)
- Yii 增删改查 测试记录
- java中的异常处理机制_函数覆盖时的异常特点
- python(4)-迭代器 和 生成器
- Ubuntu 13.04 用Sublime Text 2 编译运行 JAVA
- 深入解读ESB与SOA的关系
- linux的NetworkManager服务(转)
- C# 读取IE缓存文件(1)
- AJAX实现无刷新验证用户名
- java实现——006重建二叉树
- CSS的常用属性
- Xshell学习--菜鸟篇
- 【MySQL】MySQL的执行计划及索引优化
- PLSQL Developer 远程连接Oracle数据库
- redis 开机启动
- Net Core平台灵活简单的日志记录框架NLog+SqlServer初体验
- WPF TextBlock IsTextTrimmed 判断文本是否超出
- phoenix初步
热门文章
- hdu1625 Numbering Paths (floyd判环)
- IntelliJ IDEA 运行java程序时出现“程序发生找不到或无法加载主类 cn.test1.test1”错误
- Acwing 154 滑动窗口(单调队列)经典模板
- hdu2126 Buy the souvenirs
- Dubbo SPI 机制源码分析(基于2.7.7)
- 【转】Dockerfile
- 由CloudStack项目引起的ESXI嵌套虚拟化引起的二级虚拟机无法被访问
- Shell 元字符 &; 变量
- .NET中使用DebuggerDisplay轻松定制调试
- 计蒜客 2019南昌邀请网络赛J Distance on the tree(主席树)题解