在Linux上防火墙开放对应的端口的命令如下:

方式一:

[root@localhost sbin]# /sbin/iptables -I INPUT -p tcp --dport 80 -j ACCEPT
[root@localhost sbin]#
[root@localhost sbin]# /etc/rc.d/init.d/iptables save
iptables: Saving firewall rules to /etc/sysconfig/iptables:[ OK ]
[root@localhost sbin]#
[root@localhost sbin]# /etc/rc.d/init.d/iptables restart
iptables: Setting chains to policy ACCEPT: filter [ OK ]
iptables: Flushing firewall rules: [ OK ]
iptables: Unloading modules: [ OK ]
iptables: Applying firewall rules: [ OK ]
[root@localhost sbin]#
[root@localhost sbin]# /etc/rc.d/init.d/iptables status
Table: filter
Chain INPUT (policy ACCEPT)
num target prot opt source destination
ACCEPT tcp -- 0.0.0.0/ 0.0.0.0/ tcp dpt:
ACCEPT all -- 0.0.0.0/ 0.0.0.0/ state RELATED,ESTABLISHED
ACCEPT icmp -- 0.0.0.0/ 0.0.0.0/
ACCEPT all -- 0.0.0.0/ 0.0.0.0/
ACCEPT tcp -- 0.0.0.0/ 0.0.0.0/ state NEW tcp dpt:
ACCEPT tcp -- 0.0.0.0/ 0.0.0.0/ state NEW tcp dpt:
ACCEPT tcp -- 0.0.0.0/ 0.0.0.0/ state NEW tcp dpt:
ACCEPT tcp -- 0.0.0.0/ 0.0.0.0/ state NEW tcp dpt:
REJECT all -- 0.0.0.0/ 0.0.0.0/ reject-with icmp-host-prohibited Chain FORWARD (policy ACCEPT)
num target prot opt source destination
REJECT all -- 0.0.0.0/ 0.0.0.0/ reject-with icmp-host-prohibited Chain OUTPUT (policy ACCEPT)
num target prot opt source destination [root@localhost sbin]#

命令介绍如下:

/sbin/iptables -I INPUT -p tcp --dport 8011 -j ACCEPT #开启8011端口 
/etc/rc.d/init.d/iptables save #保存配置 
/etc/rc.d/init.d/iptables restart #重启服务 
查看端口是否已经开放
/etc/init.d/iptables status 
 
#######################################################

其他方式:

查看防火墙的状态:
/etc/init.d/iptables status
 

1) 重启后生效 
开启: chkconfig iptables on 
关闭: chkconfig iptables off

2) 即时生效,重启后失效 
开启: service iptables start 
关闭: service iptables stop

需要说明的是对于Linux下的其它服务都可以用以上命令执行开启和关闭操作。

在开启了防火墙时,做如下设置,开启相关端口, 
修改/etc/sysconfig/iptables 文件,添加以下内容: 
-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT 
-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT

 
 
这里应该也可以不重启计算机:
#/etc/init.d/iptables restart
关闭防火墙服务即可:
查看防火墙信息:
#/etc/init.d/iptables status
关闭防火墙服务:
#/etc/init.d/iptables stop
 
-----简单的修改,在开启防火墙的情况下。放开对应端口,见下面红色。
# Generated by iptables-save v1.4.7 on Mon Dec 26 16:43:03 2016
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [3:420]
-A INPUT -p tcp -m tcp --dport 22 -j ACCEPT
-A INPUT -p tcp -m tcp --dport 8999 -j ACCEPT
-A INPUT -p tcp -m tcp --dport 25 -j ACCEPT
-A INPUT -p tcp -m tcp --dport 8005 -j ACCEPT
COMMIT
# Completed on Mon Dec 26 16:43:03 2016
 
一、Linux下开启/关闭防火墙命令
1、永久性生效,重启后不会复原。
开启: chkconfig iptables on
关闭: chkconfig iptables off
2、 即时生效,重启后复原
开启: service iptables start
关闭: service iptables stop
需要说明的是对于Linux下的其它服务都可以用以上命令执行开启和关闭操作。
在当开启了防火墙时,做如下设置,开启相关端口,
修改/etc/sysconfig/iptables 文件,添加以下内容:
-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT
-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT
二、UBuntu关闭防火墙
iptables -A INPUT -i ! PPP0 -j ACCEPT
三、CentOS Linux 防火墙配置及关闭
执行”setup”命令启动文字模式配置实用程序,在”选择一种工具”中选择”防火墙配置”,然后选择”运行工具”按钮,出现防火墙配置界面,将”安全级别”设为”禁用”,然后选择”确定”即可.
或者用命令:
#/sbin/iptables -I INPUT -p tcp –dport 80 -j ACCEPT
#/sbin/iptables -I INPUT -p tcp –dport 22 -j ACCEPT
#/etc/rc.d/init.d/iptables save
这样重启计算机后,防火墙默认已经开放了80和22端口
这里应该也可以不重启计算机:
#/etc/init.d/iptables restart
关闭防火墙服务即可:
查看防火墙信息:
#/etc/init.d/iptables status
关闭防火墙服务:
#/etc/init.d/iptables stop
 

Linux上防火墙开放对应的端口的更多相关文章

  1. Linux配置防火墙,开启80端口、3306端口

    Linux配置防火墙,开启80端口.3306端口   起因是因为想使用Navicat连接一下数据库,发现连接不上 通过查阅许多资料和多次测试发现是因为防火墙没有配置3306端口 话不多说,开整,同理, ...

  2. Win7上防火墙开放FTP服务以及ping解决方案(zz)

    1.windows 防火墙开放ftp服务 The following 4 steps will allow both non-secure and SSL FTP traffic through fi ...

  3. OpenWRT(RT5350) 路由客户模式(Routed Client) ,设置防火墙开放UDP指定端口

    /* *功     能: 本文主要功能是设置OpenWRT(RT5350) 系统实现路由客户模式,无线连接上级路由, * 无线释放AP客户端,实现伪装的中继(子网段与上级路由网段不同),同时更改防火墙 ...

  4. Linux上部署多个tomcat端口设置

    在Linux上部署多个tomcat主要是防止端口冲突的问题, tomcat服务器需配置三个端口才能启动,安装时默认启用了这三个端口,当要运行多个tomcat服务时需要修改这三个端口,不能相同.端口一: ...

  5. Win7上防火墙开放FTP服务以及ping解决方案

    1.windows 防火墙开放ftp服务 The following 4 steps will allow both non-secure and SSL FTP traffic through fi ...

  6. linux配置防火墙 Centos7下 添加 端口白名单

    最近在阿里云服务器centos7上部署项目 要开启8484端口 , CentOS 7默认使用的是firewall作为防火墙 在firewall下开启端口白名单 1.查看下防火墙的状态:systemct ...

  7. Linux配置防火墙,开启80端口、3306端口(转)

    vi /etc/sysconfig/iptables -A INPUT -m state –state NEW -m tcp -p tcp –dport 80 -j ACCEPT(允许80端口通过防火 ...

  8. 记一个菜鸟在Linux上部署Tomcat的随笔

    以前都只是在园子里找各种资料.文档.各种抱大腿,今天是第一次进园子里来添砖加瓦,实话说,都不知道整些啥东西上来,就把自己在Linux上搭建Tomcat的过程记录下来,人笨,请各位大虾们勿喷. 虽然做开 ...

  9. 如何在阿里云linux上部署java项目

      前2天把git练了下,敲了很多命令,也借助图形界面增强自己的理解,乘着余热把linux在熟悉下.然后想起以前婷主有让我帮忙搭建的阿里云服务器,所以就想自己试着在阿里云的linux上搭建自己的jav ...

随机推荐

  1. 在java代码中执行js脚本,实现计算出字符串“(1+2)*(1+3)”的结果

            今天在公司项目中,发现一个计算运费的妙招.由于运费规则各种各样,因此写一个公式存到数据库.下次需要计算运费时,直接取出这个公式,把公式的未知变量给替换掉,然后计算出结果就是ok了. 一 ...

  2. 全虚拟化和半虚拟化的区别 cpu的ring0 ring1又是什么概念? - 转

    http://www.cnblogs.com/xusongwei/archive/2012/07/30/2615592.html ring0是指CPU的运行级别,ring0是最高级别,ring1次之, ...

  3. 【WPF】给TextBox添上Label

    原文:[WPF]给TextBox添上Label 引言     在客户端开发中,要说出现频率大的控件,必定有TextBox的身影.然而在TextBox的旁边通常得有个基友Label,形影不离.为此,我们 ...

  4. UCOSII笔记---信号量、邮箱、消息队列、信号量集、软件定时器

    一.接收邮箱函数的参数:timeout表示的是滴答定时器的节拍数,比如设定5ms为一个节拍,超时为100ms,则timeout=20. void *OSMboxPend (OS_EVENT *peve ...

  5. 使用ClosedXML,读取到空行

    最近项目中使用了ClosedXML.dll来处理Excel,在读取Excel的时候,用workSheet.Rows()获取Excel行数,默认读取Excel最大行数1048576 所以为了读取到不是空 ...

  6. 科普贴 | 以太坊代币钱包MyEtherWallet使用教程,一步步教你玩转MEW

    MyEtherWallet 是一个以太坊的网页钱包,使用非常简单,打开网页就可以使用,源代码开源,不会在服务器上存储用户的钱包信息如私钥和密码.支持 Ledger Wallet.TREZOR 等硬件钱 ...

  7. openssl证书及配置

    我的环境是:Linux+Apache+MySQL+PHP 1.下载openssl 及相关依赖 #yum install -y openssl 2.进入目录 /etc/pki/tls/certs #cd ...

  8. PAT甲题题解-1043. Is It a Binary Search Tree (25)-二叉搜索树

    博主欢迎转载,但请给出本文链接,我尊重你,你尊重我,谢谢~http://www.cnblogs.com/chenxiwenruo/p/6789220.html特别不喜欢那些随便转载别人的原创文章又不给 ...

  9. 每日Scrum(8)

    今天:在程序中嵌入剖面图,进行美化 明天:测试分析,找学弟学妹来体验我们的软件 任务看板: 燃尽图:

  10. Opendaylight的Carbon(碳)版本安装

    Opendaylight Carbon(碳)版本安装 1.更新源 sudo apt-get update sudo apt-get upgrade 2.安装JDK1.8 sudo apt-get in ...