1.查看防火墙对外开放了哪些端口

[root@hadoop110 ~]# iptables -L -n
Chain INPUT (policy ACCEPT)
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:
REJECT all -- 0.0.0.0/ 0.0.0.0/ reject-with icmp-host-prohibited Chain FORWARD (policy ACCEPT)
target prot opt source destination
REJECT all -- 0.0.0.0/ 0.0.0.0/ reject-with icmp-host-prohibited Chain OUTPUT (policy ACCEPT)
target prot opt source destination

2.centos6.0防火墙操作:

配置文件:/etc/sysconfig/iptables

开启某个端口号有两种方式:一种是命令方式,一种是修改配置文件方式

查看防火墙状态:chkconfig iptables --list

[root@hadoop110 ~]# chkconfig iptables --list
iptables :关闭 :关闭 :启用 :启用 :启用 :启用 :关闭

开启防火墙(重启后永久生效):chkconfig iptables on
关闭防火墙(重启后永久生效):chkconfig iptables off

[root@hadoop110 ~]# chkconfig iptables --list
iptables :关闭 :关闭 :启用 :启用 :启用 :启用 :关闭
[root@hadoop110 ~]# chkconfig iptables off
[root@hadoop110 ~]# chkconfig iptables --list
iptables :关闭 :关闭 :关闭 :关闭 :关闭 :关闭 :关闭
[root@hadoop110 ~]# chkconfig iptables on
[root@hadoop110 ~]# chkconfig iptables --list
iptables :关闭 :关闭 :启用 :启用 :启用 :启用 :关闭
[root@hadoop110 ~]#

开启防火墙(即时生效,重启后失效):service iptables start
关闭防火墙(即时生效,重启后失效):service iptables stop
重启防火墙:service iptables restart

查看开启的端口号
service iptables status

[root@hadoop110 ~]# service iptables status
\表格: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:
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

3.开启某个端口号(如80端口号,命令方式)
iptables -A INPUT -p tcp -m state --state NEW -m tcp --dport 80 -j ACCEPT

[root@hadoop110 ~]# iptables -A INPUT -p tcp -m state --state  NEW  -m tcp --dport  -j ACCEPT

保存开启的端口号
service iptables save

[root@hadoop110 ~]# service iptables save
iptables:将防火墙规则保存到 /etc/sysconfig/iptables: [确定]
[root@hadoop110 ~]# iptables status
Bad argument `status'
Try `iptables -h' or 'iptables --help' for more information.

重新启动防火墙
service iptables restart

[root@hadoop110 ~]# service iptables restart
iptables:将链设置为政策 ACCEPT:filter [确定]
iptables:清除防火墙规则: [确定]
iptables:正在卸载模块: [确定]
iptables:应用防火墙规则: [确定]

查看开启的端口号
service iptables status

[root@hadoop110 ~]# service iptables status
表格: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:
REJECT all -- 0.0.0.0/ 0.0.0.0/ reject-with icmp-host-prohibited
ACCEPT tcp -- 0.0.0.0/ 0.0.0.0/ state NEW tcp dpt: 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

开启某个范围的端口号(如18881~65534,命令方式)
iptables -A INPUT -p tcp -m state --state NEW -m tcp --dport 18881:65534 -j ACCEPT

[root@hadoop110 ~]# iptables -A INPUT -p tcp -m state --state  NEW  -m tcp --dport : -j ACCEPT

保存开启的端口号
service iptables save

[root@hadoop110 ~]# service iptables save
iptables:将防火墙规则保存到 /etc/sysconfig/iptables: [确定]

重新启动防火墙
service iptables restart

查看开启的端口号
service iptables status

[root@hadoop110 ~]# service iptables status
表格: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:
REJECT all -- 0.0.0.0/ 0.0.0.0/ reject-with icmp-host-prohibited
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 dpts:: 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

4.通过修改配置文件开启端口号(如80端口号)
 vi /etc/sysconfig/iptables
-A INPUT -p tcp -m state --state NEW -m tcp --dport 80 -j ACCEPT
启动防火墙
service iptables restart

参数说明:
–A 参数就看成是添加一条规则
–p 指定是什么协议,我们常用的tcp 协议,当然也有udp,例如53端口的DNS
–dport 就是目标端口,当数据从外部进入服务器为目标端口

–j 就是指定是 ACCEPT -接收 或者 DROP 不接收

原文:https://blog.csdn.net/u014079773/article/details/79745819

centos6+如何对外开放80,3306端口号或者其他端口号的更多相关文章

  1. linux mysql 查看默认端口号和修改端口号

    如何查看mysql 默认端口号和修改端口号 2015-03-19 17:42:18 1. 登录mysql [root@test /]# mysql -u root -p Enter password: ...

  2. 如何查看mysql 默认端口号和修改端口号

    http://blog.itpub.net/26148431/viewspace-1466379/ 1,登录mysql 2,使用命令show global variables like 'port'; ...

  3. 查看mysql 默认端口号和修改端口号

    1. 登录mysql mysql -u root -p //输入密码 2. 使用命令show global variables like 'port';查看端口号 mysql> show glo ...

  4. CentOS7查看开放端口命令及开放端口号

    CentOS 7查看以开放端口命令:firewall-cmd —list-ports 查看端口是否开放命令:第一个方法就是使用lsof -i:端口号命令行,例如lsof -i:80.如果没有任何信息输 ...

  5. 登录MySQL非默认3306端口号的语句

    这里登陆的是mysql3308端口号的数据库 mysql -P3308 -p用户名 -u密码

  6. Centos7 开放80,3306端口解决办法

    所有扯iptables的文章都是扯淡!!! centos 7 默认防火墙由firewalld来管理!关iptables屁事! 以开放80端口为例,执行以下命令: 开放80端口:firewall-cmd ...

  7. SQL Server 端口号的使用

    SQL Server 端口号的使用 服务器地址  逗号 端口号 服务器地址,端口号 xxx.xxx.xxx.xxx,0000 www.xxx.com,1533  (1533是SQL Server 的端 ...

  8. linux-sftp-指定端口号登录远程主机

    sftp -oPort=60001 root@192.168.0.254 -o选项来指定端口号 -oPort=远程端口号

  9. 调试技巧--Windows端口号是否被占用

    调试技巧--Windows端口号是否被占用 一.端口概念 10.0.0.0~10.255.255.255,172.16.0.0~172.16.255.255, 192.168.0.0~192.168. ...

随机推荐

  1. Dom对象与jQuery对象的转换

  2. js格式化时间和时间操作

    js格式化时间 function formatDateTime(inputTime) { var date = new Date(inputTime); var y = date.getFullYea ...

  3. [luogu3391] 【模板】文艺平衡树(fhq-treap反转区间)

    解题关键:无旋treap模板. #include<iostream> #include<cstdio> #include<cstring> #include< ...

  4. PHPMailer fe v4.11 For Thinkphp 3.2

    PHPMailer fe v4.11 For Thinkphp 3.2,你值得拥有! 今晚用TP3.2开发一个东西的时候需要邮件发送功能,理所当然的想到了PHPMailer.于是有了此文!------ ...

  5. CMakefile for Cross-Platform Compling - 1

    cmake可以自动侦测目标系统,通常编译时候包含的文件和链接的库都不是本地的文件. Demo #toolchain cmake file SET(CMAKE_SYSTEM_NAME Linux) SE ...

  6. 468C Hack it!

    传送门 题目大意 分析 here 对于最后求p的过程我想再说一下 那个45就是最前一位分别是0~9,所以总贡献就是45乘上每一种数开头对应多少种情况 而后面的10则是他前面可以填多少不同的数对他做的贡 ...

  7. PostgreSQL9.3+PostGIS2.1安装配置

    Postgresql——Postgresql是一种对象关系型数据库.下载地址:http://www.postgresql.org/download/ postgis (可选)——是一个空间数据库,它扩 ...

  8. fDDA

    fDDA:fast DDA,快速的动态数据认证 中国余数定理模式: 就是中国的古人发明的多项式除以多项式的结果的一个定理 AC:应用密文,application cryptogram(密文) gene ...

  9. 转 Delphi中XLSReadWrite控件的使用(2)---基本应用

    unit Main; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, ...

  10. 服务器控件数据回发实现IPostBackDataHandler需注意的

    我写的服务器控件(未完,模型如此) using System; using System.Collections.Generic; using System.Collections.Specializ ...